]> git.ozlabs.org Git - patchwork/blobdiff - apps/patchwork/utils.py
notifications: add project name to patch update notification
[patchwork] / apps / patchwork / utils.py
index 5cb45e8eeaa41191955ead4a9fea3ca434dbb81d..f8fee3fcaaa1c8d0db9e5d50b4989ac75ae9ef3c 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
@@ -58,12 +59,12 @@ class Order(object):
     def __init__(self, str = None, editable = False):
         self.reversed = False
         self.editable = editable
+        (self.order, self.reversed) = self.default_order
 
         if self.editable:
             return
 
         if str is None or str == '':
-            (self.order, self.reversed) = self.default_order
             return
 
         reversed = False
@@ -72,7 +73,6 @@ class Order(object):
             reversed = True
 
         if str not in self.order_map.keys():
-            (self.order, self.reversed) = self.default_order
             return
 
         self.order = str
@@ -105,9 +105,15 @@ def set_bundle(user, project, action, data, patches, context):
     bundle = None
     if action == 'create':
         bundle_name = data['bundle_name'].strip()
+        if '/' in bundle_name:
+            return ['Bundle names can\'t contain slashes']
+
         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()
@@ -169,6 +175,7 @@ def send_notifications():
 
     for (recipient, notifications) in groups:
         notifications = list(notifications)
+        projects = set([ n.patch.project.linkname for n in notifications ])
 
         def delete_notifications():
             PatchChangeNotification.objects.filter(
@@ -182,7 +189,9 @@ def send_notifications():
             'site': Site.objects.get_current(),
             'person': recipient,
             'notifications': notifications,
+            'projects': projects,
         }
+
         subject = render_to_string(
                         'patchwork/patch-change-notification-subject.text',
                         context).strip()