]> git.ozlabs.org Git - patchwork/blobdiff - apps/patchwork/utils.py
bundles: Add check for duplicate bundles
[patchwork] / apps / patchwork / utils.py
index e7619c319091ce2dd9e78396f24ffbe8dac1f6db..1771167ae12f35fb55479c35aa865be496ce2664 100644 (file)
@@ -26,6 +26,7 @@ from django.contrib.sites.models import Site
 from django.conf import settings
 from django.core.mail import EmailMessage
 from django.db.models import Max
+from django.db.utils import IntegrityError
 from patchwork.forms import MultiplePatchForm
 from patchwork.models import Bundle, Project, BundlePatch, UserProfile, \
         PatchChangeNotification, EmailOptout
@@ -107,6 +108,9 @@ def set_bundle(user, project, action, data, patches, context):
         if not bundle_name:
             return ['No bundle name was specified']
 
+        if Bundle.objects.filter(owner = user, name = bundle_name).count() > 0:
+            return ['You already have a bundle called "%s"' % bundle_name]
+
         bundle = Bundle(owner = user, project = project,
                 name = bundle_name)
         bundle.save()