]> git.ozlabs.org Git - patchwork/blobdiff - apps/patchwork/views/patch.py
Bundle reordering support
[patchwork] / apps / patchwork / views / patch.py
index f20f25d792e5b33321c43cf3e0a539419338ed51..49843eb2cfad3c99c5dfc62707d829ddd66f793c 100644 (file)
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
 
-from patchwork.models import Patch, Project, Person, RegistrationRequest, Bundle
+from patchwork.models import Patch, Project, Person, Bundle
 from patchwork.filters import Filters
-from patchwork.forms import RegisterForm, LoginForm, PatchForm, MultiplePatchForm, CreateBundleForm
+from patchwork.forms import PatchForm, MultiplePatchForm, CreateBundleForm
 from patchwork.utils import get_patch_ids, set_patches, Order
 from patchwork.requestcontext import PatchworkRequestContext
 from django.shortcuts import render_to_response, get_object_or_404
 from django.http import HttpResponse, HttpResponseRedirect, \
-            HttpResponseForbidden
+        HttpResponseForbidden
 from django.contrib.auth.models import User
 from django.contrib.auth.decorators import login_required
 from django.contrib.auth import authenticate, login
@@ -59,7 +59,7 @@ def patch(request, patch_id):
                     data = request.POST)
             if createbundleform.is_valid():
                 createbundleform.save()
-                bundle.patches.add(patch)
+                bundle.append_patch(patch)
                 bundle.save()
                 createbundleform = CreateBundleForm()
                 context.add_message('Bundle %s created' % bundle.name)
@@ -67,11 +67,15 @@ def patch(request, patch_id):
         elif action == 'addtobundle':
             bundle = get_object_or_404(Bundle, id = \
                         request.POST.get('bundle_id'))
-            bundle.patches.add(patch)
-            bundle.save()
-            context.add_message('Patch added to bundle "%s"' % bundle.name)
+            try:
+                bundle.append_patch(patch)
+                bundle.save()
+                context.add_message('Patch added to bundle "%s"' % bundle.name)
+            except Exception, ex:
+                context.add_message("Couldn't add patch '%s' to bundle %s: %s" \
+                        % (patch.name, bundle.name, ex.message))
 
-       # all other actions require edit privs
+        # all other actions require edit privs
         elif not editable:
             return HttpResponseForbidden()
 
@@ -81,14 +85,14 @@ def patch(request, patch_id):
                 form.save()
                 context.add_message('Patch updated')
 
-       elif action == 'archive':
-           patch.archived = True
-           patch.save()
+        elif action == 'archive':
+            patch.archived = True
+            patch.save()
             context.add_message('Patch archived')
 
-       elif action == 'unarchive':
-           patch.archived = False
-           patch.save()
+        elif action == 'unarchive':
+            patch.archived = False
+            patch.save()
             context.add_message('Patch un-archived')
 
         elif action == 'ack':
@@ -157,13 +161,13 @@ def list(request, project_id):
             ps.append(patch)
 
         (errors, form) = set_patches(request.user, project, action, \
-                               request.POST, ps)
+                                        request.POST, ps)
         if errors:
             context['errors'] = errors
 
 
     elif request.user.is_authenticated() and \
-           project in request.user.get_profile().maintainer_projects.all():
+            project in request.user.get_profile().maintainer_projects.all():
         form = MultiplePatchForm(project)
 
     patches = Patch.objects.filter(project=project).order_by(order)