Code cleaning on notification app.

remotes/origin/enhancement/email-actions
Andrey Antukh 2013-10-08 17:46:23 +02:00
parent 3cd8d913fa
commit 1636a9c838
2 changed files with 14 additions and 14 deletions

View File

@ -16,24 +16,22 @@ class NotificationSenderMixin(object):
def post_save(self, obj, created=False): def post_save(self, obj, created=False):
users = obj.get_watchers_to_notify(self.request.user) users = obj.get_watchers_to_notify(self.request.user)
context = { context = {'changer': self.request.user, 'object': obj}
"changer": self.request.user,
"object": obj
}
if created: if created:
self._send_notification_email(self.create_notification_template, users=users, context=context) self._send_notification_email(self.create_notification_template,
users=users, context=context)
else: else:
context["changed_fields_dict"] = obj.get_changed_fields_dict(self.request.DATA) context["changed_fields_dict"] = obj.get_changed_fields_dict(self.request.DATA)
self._send_notification_email(self.update_notification_template, users=users, context=context) self._send_notification_email(self.update_notification_template,
users=users, context=context)
def destroy(self, request, *args, **kwargs): def destroy(self, request, *args, **kwargs):
obj = self.get_object() obj = self.get_object()
users = obj.get_watchers_to_notify(self.request.user) users = obj.get_watchers_to_notify(self.request.user)
context = {
'changer': self.request.user, context = {'changer': self.request.user, 'object': obj}
'object': obj self._send_notification_email(self.destroy_notification_template,
} users=users, context=context)
self._send_notification_email(self.destroy_notification_template, users=users, context=context)
return super(NotificationSenderMixin, self).destroy(request, *args, **kwargs) return super(NotificationSenderMixin, self).destroy(request, *args, **kwargs)

View File

@ -16,8 +16,9 @@ class WatcherMixin(object):
("no_events", _(u"No events")), ("no_events", _(u"No events")),
) )
notify_level = models.CharField(max_length=32, null=False, blank=False, default="all_owned_projects", notify_level = models.CharField(max_length=32, null=False, blank=False,
choices=NOTIFY_LEVEL_CHOICES, verbose_name=_(u"notify level")) default="all_owned_projects", choices=NOTIFY_LEVEL_CHOICES,
verbose_name=_(u"notify level"))
notify_changes_by_me = models.BooleanField(null=False, blank=True, default=True, notify_changes_by_me = models.BooleanField(null=False, blank=True, default=True,
verbose_name=_(u"notify changes made by me")) verbose_name=_(u"notify changes made by me"))
@ -65,7 +66,8 @@ class WatchedMixin(object):
def get_changed_fields_dict(self, data_dict): def get_changed_fields_dict(self, data_dict):
if self.notifiable_fields: if self.notifiable_fields:
changed_data = dict((k, v) for k, v in data_dict.items() if k in self.notifiable_fields) changed_data = {k: v for k, v in data_dict.items()
if k in self.notifiable_fields}
else: else:
changed_data = data_dict changed_data = data_dict