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

Damien Lespiau damien.lespiau at intel.com
Sat Sep 12 01:55:20 AEST 2015


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 at intel.com>
---
 patchwork/models.py | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

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)
-- 
2.1.0



More information about the Patchwork mailing list