X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=apps%2Fpatchwork%2Fviews%2Fbundle.py;h=d9db49096f5b52909e4e69da6fcfa32e5ae03788;hb=a16f6f8afd0e9487cb3d9b8041f24c7496330086;hp=5f990c44dfe0d1f705370cbd8d8e3a922a623fe4;hpb=750c03f854ace16cd013c189369aa0cf9d3bdd9d;p=patchwork diff --git a/apps/patchwork/views/bundle.py b/apps/patchwork/views/bundle.py index 5f990c4..d9db490 100644 --- a/apps/patchwork/views/bundle.py +++ b/apps/patchwork/views/bundle.py @@ -23,12 +23,11 @@ from django.shortcuts import render_to_response, get_object_or_404 from patchwork.requestcontext import PatchworkRequestContext from django.http import HttpResponse, HttpResponseRedirect import django.core.urlresolvers -from patchwork.models import Patch, Bundle, Project +from patchwork.models import Patch, Bundle, BundlePatch, Project from patchwork.utils import get_patch_ids from patchwork.forms import BundleForm, DeleteBundleForm from patchwork.views import generic_list from patchwork.filters import DelegateFilter -from patchwork.paginator import Paginator @login_required def setbundle(request): @@ -49,7 +48,10 @@ def setbundle(request): patch_id = request.POST.get('patch_id', None) if patch_id: patch = get_object_or_404(Patch, id = patch_id) - bundle.patches.add(patch) + try: + bundle.append_patch(patch) + except Exception: + pass bundle.save() elif action == 'add': bundle = get_object_or_404(Bundle, @@ -65,7 +67,7 @@ def setbundle(request): for id in patch_ids: try: patch = Patch.objects.get(id = id) - bundle.patches.add(patch) + bundle.append_patch(patch) except ex: pass @@ -107,17 +109,17 @@ def bundles(request): if request.method == 'POST': form_name = request.POST.get('form_name', '') - if form_name == DeleteBundleForm.name: - form = DeleteBundleForm(request.POST) - if form.is_valid(): - bundle = get_object_or_404(Bundle, - id = form.cleaned_data['bundle_id']) - bundle.delete() + if form_name == DeleteBundleForm.name: + form = DeleteBundleForm(request.POST) + if form.is_valid(): + bundle = get_object_or_404(Bundle, + id = form.cleaned_data['bundle_id']) + bundle.delete() bundles = Bundle.objects.filter(owner = request.user) for bundle in bundles: bundle.delete_form = DeleteBundleForm(auto_id = False, - initial = {'bundle_id': bundle.id}) + initial = {'bundle_id': bundle.id}) context['bundles'] = bundles @@ -143,11 +145,23 @@ def bundle(request, bundle_id): else: form = BundleForm(instance = bundle) + if request.method == 'POST' and request.POST.get('form') == 'reorderform': + order = get_object_or_404(BundlePatch, bundle = bundle, + patch__id = request.POST.get('order_start')).order + + for patch_id in request.POST.getlist('neworder'): + bundlepatch = get_object_or_404(BundlePatch, + bundle = bundle, patch__id = patch_id) + bundlepatch.order = order + bundlepatch.save() + order += 1 + context = generic_list(request, bundle.project, 'patchwork.views.bundle.bundle', view_args = {'bundle_id': bundle_id}, filter_settings = filter_settings, - patches = bundle.patches.all()) + patches = bundle.ordered_patches(), + editable_order = True) context['bundle'] = bundle context['bundleform'] = form @@ -159,13 +173,14 @@ def mbox(request, bundle_id): bundle = get_object_or_404(Bundle, id = bundle_id) response = HttpResponse(mimetype='text/plain') response['Content-Disposition'] = 'attachment; filename=bundle-%d.mbox' % \ - bundle.id + bundle.id response.write(bundle.mbox()) return response def public(request, username, bundlename): user = get_object_or_404(User, username = username) - bundle = get_object_or_404(Bundle, name = bundlename, public = True) + bundle = get_object_or_404(Bundle, name = bundlename, owner = user, + public = True) filter_settings = [(DelegateFilter, DelegateFilter.AnyDelegate)] context = generic_list(request, bundle.project, 'patchwork.views.bundle.public', @@ -173,6 +188,6 @@ def public(request, username, bundlename): filter_settings = filter_settings, patches = bundle.patches.all()) - context.update({'bundle': bundle, - 'user': user}); + context['bundle'] = bundle + return render_to_response('patchwork/bundle-public.html', context)