Now only sent emails when:
- any notifiable_fields is update - an object is create - an object is deleteremotes/origin/enhancement/email-actions
parent
3c496eb547
commit
886e4554bc
|
@ -1,4 +1,4 @@
|
||||||
# -*- coding: utf-8 -*-i
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
from djmail import template_mail
|
from djmail import template_mail
|
||||||
|
|
||||||
|
@ -15,14 +15,17 @@ class NotificationSenderMixin(object):
|
||||||
email.send()
|
email.send()
|
||||||
|
|
||||||
def post_save(self, obj, created=False):
|
def post_save(self, obj, created=False):
|
||||||
|
super().post_save(obj, created)
|
||||||
|
|
||||||
users = obj.get_watchers_to_notify(self.request.user)
|
users = obj.get_watchers_to_notify(self.request.user)
|
||||||
context = {'changer': self.request.user, 'object': obj}
|
context = {'changer': self.request.user, 'object': obj}
|
||||||
|
changed_fields_dict = obj.get_changed_fields_dict(self.request.DATA)
|
||||||
|
|
||||||
if created:
|
if created:
|
||||||
self._send_notification_email(self.create_notification_template,
|
self._send_notification_email(self.create_notification_template,
|
||||||
users=users, context=context)
|
users=users, context=context)
|
||||||
else:
|
elif changed_fields_dict:
|
||||||
context["changed_fields_dict"] = obj.get_changed_fields_dict(self.request.DATA)
|
context["changed_fields_dict"] = changed_fields_dict
|
||||||
self._send_notification_email(self.update_notification_template,
|
self._send_notification_email(self.update_notification_template,
|
||||||
users=users, context=context)
|
users=users, context=context)
|
||||||
|
|
||||||
|
@ -34,4 +37,4 @@ class NotificationSenderMixin(object):
|
||||||
self._send_notification_email(self.destroy_notification_template,
|
self._send_notification_email(self.destroy_notification_template,
|
||||||
users=users, context=context)
|
users=users, context=context)
|
||||||
|
|
||||||
return super(NotificationSenderMixin, self).destroy(request, *args, **kwargs)
|
return super().destroy(request, *args, **kwargs)
|
||||||
|
|
|
@ -73,7 +73,7 @@ class WatchedMixin(models.Model):
|
||||||
changed_data = data_dict
|
changed_data = data_dict
|
||||||
|
|
||||||
field_dict = {}
|
field_dict = {}
|
||||||
for field_name, data_value in data_dict.items():
|
for field_name, data_value in changed_data.items():
|
||||||
field_dict.update(self._get_changed_field(field_name, data_value))
|
field_dict.update(self._get_changed_field(field_name, data_value))
|
||||||
return field_dict
|
return field_dict
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue