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
+ PatchChangeNotification, EmailOptout
def get_patch_ids(d, prefix = 'patch_id'):
ids = []
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
reversed = True
if str not in self.order_map.keys():
- (self.order, self.reversed) = self.default_order
return
self.order = str
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()
for (recipient, notifications) in groups:
notifications = list(notifications)
+ projects = set([ n.patch.project.linkname for n in notifications ])
+
+ def delete_notifications():
+ PatchChangeNotification.objects.filter(
+ pk__in = notifications).delete()
+
+ if EmailOptout.is_optout(recipient.email):
+ delete_notifications()
+ continue
+
context = {
'site': Site.objects.get_current(),
'person': recipient,
'notifications': notifications,
+ 'projects': projects,
}
+
subject = render_to_string(
'patchwork/patch-change-notification-subject.text',
context).strip()
context)
message = EmailMessage(subject = subject, body = content,
- from_email = settings.DEFAULT_FROM_EMAIL,
+ from_email = settings.NOTIFICATION_FROM_EMAIL,
to = [recipient.email],
headers = {'Precedence': 'bulk'})
errors.append((recipient, ex))
continue
- PatchChangeNotification.objects.filter(pk__in = notifications).delete()
+ delete_notifications()
return errors