diff mbox

[13/15] series: Add a signal to notify when a revision is complete

Message ID 1444387202-25735-14-git-send-email-damien.lespiau@intel.com
State Superseded
Headers show

Commit Message

Damien Lespiau Oct. 9, 2015, 10:40 a.m. UTC
To decouple some high level and rather complex parsing code from the
models, let's add a signal when a SeriesRevision is complete.

One can use that signal to hook some logic there, for instance from the
mail parsing code.

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

Comments

Stephen Finucane Oct. 9, 2015, 11:21 p.m. UTC | #1
> To decouple some high level and rather complex parsing code from the

> models, let's add a signal when a SeriesRevision is complete.

> 

> One can use that signal to hook some logic there, for instance from the

> mail parsing code.

> 

> Signed-off-by: Damien Lespiau <damien.lespiau@intel.com>


I'm missing patch 12? As for this patch,

Acked-by: Stephen Finucane <stephen.finucane@intel.com>
diff mbox

Patch

diff --git a/patchwork/models.py b/patchwork/models.py
index eb9758b..c9b2f9a 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -19,6 +19,7 @@ 
 
 from django.db import models
 from django.db.models import Q
+import django.dispatch
 from django.contrib.auth.models import User
 from django.core.urlresolvers import reverse
 from django.contrib.sites.models import Site
@@ -452,6 +453,10 @@  class Series(models.Model):
                 print('            msgid  : %s' % patch.msgid)
                 i += 1
 
+# Signal one can listen to to know when a revision is complete (ie. has all of
+# its patches)
+series_revision_complete = django.dispatch.Signal(providing_args=["revision"])
+
 # A 'revision' of a series. Resending a new version of a patch or a full new
 # iteration of a series will create a new revision.
 class SeriesRevision(models.Model):
@@ -478,6 +483,10 @@  class SeriesRevision(models.Model):
                                                 order=order)
         sp.save()
 
+        revision_complete = self.patches.count() == self.series.n_patches
+        if revision_complete:
+            series_revision_complete.send(sender=self.__class__, revision=self)
+
     def duplicate_meta(self):
         new = SeriesRevision.objects.get(pk=self.pk)
         new.pk = None