[PATCH 10/51] series: Add a Series model

Damien Lespiau damien.lespiau at intel.com
Sat Sep 12 01:54:43 AEST 2015


v2: Add 'order' metadata to revisions as they do have a natural
    ordering.

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

diff --git a/patchwork/models.py b/patchwork/models.py
index 62fd628..742a08d 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -415,6 +415,54 @@ class BundlePatch(models.Model):
         unique_together = [('bundle', 'patch')]
         ordering = ['order']
 
+# This Model represents the "top level" Series, an object that doesn't change
+# with the various versions of patches sent to the mailing list.
+class Series(models.Model):
+    project = models.ForeignKey(Project)
+    name = models.CharField(max_length=200, null=True, blank=False)
+    submitter = models.ForeignKey(Person, related_name='submitters')
+    reviewer = models.ForeignKey(User, related_name='reviewers', null=True,
+                                 blank=True)
+    submitted = models.DateTimeField(default=datetime.datetime.now)
+    last_updated = models.DateTimeField(auto_now=True)
+    # Caches the latest version so we can display it without looking at the max
+    # of all SeriesRevision.version
+    version = models.IntegerField(default=1)
+    # This is the number of patches of the latest version.
+    n_patches = models.IntegerField(default=0)
+
+# 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):
+    series = models.ForeignKey(Series)
+    version = models.IntegerField(default=1)
+    root_msgid = models.CharField(max_length=255)
+    cover_letter = models.TextField(null = True, blank = True)
+    patches = models.ManyToManyField(Patch, through = 'SeriesRevisionPatch')
+
+    class Meta:
+        unique_together = [('series', 'version')]
+        ordering = ['version']
+
+    def add_patch(self, patch, order):
+        # see if the patch is already in this revision
+        if SeriesRevisionPatch.objects.filter(revision=self,
+                                              patch=patch).count():
+            raise Exception("patch is already in revision")
+
+        sp = SeriesRevisionPatch.objects.create(revision=self, patch=patch,
+                                                order=order)
+        sp.save()
+
+class SeriesRevisionPatch(models.Model):
+    patch = models.ForeignKey(Patch)
+    revision = models.ForeignKey(SeriesRevision)
+    order = models.IntegerField()
+
+    class Meta:
+        unique_together = [('revision', 'patch')]
+        ordering = ['order']
+
 class EmailConfirmation(models.Model):
     validity = datetime.timedelta(days = settings.CONFIRMATION_VALIDITY_DAYS)
     type = models.CharField(max_length = 20, choices = [
-- 
2.1.0



More information about the Patchwork mailing list