]> git.ozlabs.org Git - patchwork/blobdiff - apps/patchwork/utils.py
Remove unused imports
[patchwork] / apps / patchwork / utils.py
index 5bd6925b6bf0065ee2beaf30b60f354c2d4de5c0..53cf40ba7487b11e7e2d117606533db281d51d4f 100644 (file)
@@ -19,9 +19,8 @@
 
 
 from patchwork.forms import MultiplePatchForm
-from patchwork.models import Bundle, Project, BundlePatch, State, UserProfile
-from django.conf import settings
-from django.shortcuts import render_to_response, get_object_or_404
+from patchwork.models import Bundle, Project, BundlePatch, UserProfile
+from django.shortcuts import get_object_or_404
 
 def get_patch_ids(d, prefix = 'patch_id'):
     ids = []
@@ -97,8 +96,12 @@ def set_bundle(user, project, action, data, patches, context):
     # set up the bundle
     bundle = None
     if action == 'create':
+        bundle_name = data['bundle_name'].strip()
+        if not bundle_name:
+            return ['No bundle name was specified']
+
         bundle = Bundle(owner = user, project = project,
-                name = data['bundle_name'])
+                name = bundle_name)
         bundle.save()
         context.add_message("Bundle %s created" % bundle.name)
 
@@ -113,13 +116,15 @@ def set_bundle(user, project, action, data, patches, context):
 
     for patch in patches:
         if action == 'create' or action == 'add':
-            try:
+            bundlepatch_count = BundlePatch.objects.filter(bundle = bundle,
+                        patch = patch).count()
+            if bundlepatch_count == 0:
                 bundle.append_patch(patch)
                 context.add_message("Patch '%s' added to bundle %s" % \
                         (patch.name, bundle.name))
-            except Exception, ex:
-                context.add_message("Couldn't add patch '%s' to bundle: %s" % \
-                        (patch.name, ex.message))
+            else:
+                context.add_message("Patch '%s' already in bundle %s" % \
+                        (patch.name, bundle.name))
 
         elif action == 'remove':
             try:
@@ -168,23 +173,6 @@ def set_patches(user, project, action, data, patches, context):
             form.save(patch)
             str = 'updated'
 
-        elif action == 'ack':
-            pass
-
-        elif action == 'archive':
-            patch.archived = True
-            patch.save()
-            str = 'archived'
-
-        elif action == 'unarchive':
-            patch.archived = True
-            patch.save()
-            str = 'un-archived'
-
-        elif action == 'delete':
-            patch.delete()
-            str = 'un-archived'
-
 
     if len(patches) > 0:
         if len(patches) == 1: