]> git.ozlabs.org Git - patchwork/blobdiff - apps/patchwork/utils.py
Use the 'in' operator instead of dict.has_key(), which has been deprecated
[patchwork] / apps / patchwork / utils.py
index 3737e8923abe2f98af783ff36adaabf738d471a1..5df6404dafeb594c37bc2a815b39c8d5b53d2d1f 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 = []
@@ -117,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:
@@ -172,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:
@@ -198,8 +182,3 @@ def set_patches(user, project, action, data, patches, context):
         context.add_message(str)
 
     return (errors, form)
-
-def userprofile_register_callback(user):
-    profile = UserProfile(user = user)
-    profile.save()
-