diff mbox

[47/51] models: Split the notication logic into its own function

Message ID 1441986924-26689-48-git-send-email-damien.lespiau@intel.com
State Superseded
Headers show

Commit Message

Damien Lespiau Sept. 11, 2015, 3:55 p.m. UTC
I want to add Series state update on patch change, so start by factoring
out the notification code that was already there so we can add the
series update at the same level.

Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>
---
 patchwork/models.py | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)
diff mbox

Patch

diff --git a/patchwork/models.py b/patchwork/models.py
index 02763c5..e14d843 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -524,12 +524,8 @@  class PatchChangeNotification(models.Model):
     last_modified = models.DateTimeField(default = datetime.datetime.now)
     orig_state = models.ForeignKey(State)
 
-def _patch_change_callback(sender, instance, **kwargs):
-    # we only want notification of modified patches
-    if instance.pk is None:
-        return
-
-    if instance.project is None or not instance.project.send_notifications:
+def _patch_queue_notifications(instance):
+    if not instance.project.send_notifications:
         return
 
     try:
@@ -560,4 +556,14 @@  def _patch_change_callback(sender, instance, **kwargs):
     notification.last_modified = datetime.datetime.now()
     notification.save()
 
+def _patch_change_callback(sender, instance, **kwargs):
+    # we only want notification of modified patches
+    if instance.pk is None:
+        return
+
+    if instance.project is None:
+        return;
+
+    _patch_queue_notifications(instance)
+
 models.signals.pre_save.connect(_patch_change_callback, sender = Patch)