[RFC 2/3] models: Add 'Event' model

Stephen Finucane stephen at that.guru
Wed Oct 19 07:12:04 AEDT 2016


Events record Patch-related things like initial creation, state
transitions, delegation assigning etc.

Signed-off-by: Stephen Finucane <stephen at that.guru>
---
 patchwork/models.py | 50 +++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)

diff --git a/patchwork/models.py b/patchwork/models.py
index c74308f..ef2b539 100644
--- a/patchwork/models.py
+++ b/patchwork/models.py
@@ -27,8 +27,8 @@ import random
 import re
 
 import django
-from django.contrib.auth.models import User
 from django.conf import settings
+from django.contrib.auth.models import User
 from django.contrib.sites.models import Site
 from django.core.urlresolvers import reverse
 from django.db import models
@@ -736,6 +736,54 @@ class SeriesReference(models.Model):
         return self.msgid
 
 
+class Event(models.Model):
+    """An event raised against a patch.
+
+    Events are created whenever certain attributes of a patch are
+    changed.
+    """
+    CATEGORY_PATCH_CREATED = 0
+    CATEGORY_DEPENDENCIES_MET = 1
+    CATEGORY_STATE_CHANGED = 2
+    CATEGORY_DELEGATE_CHANGED = 3
+    CATEGORY_CHECK_ADDED = 4
+    CATEGORY_CHOICES = (
+        (CATEGORY_PATCH_CREATED, 'patch-created'),
+        (CATEGORY_DEPENDENCIES_MET, 'patch-dependencies-met'),
+        (CATEGORY_STATE_CHANGED, 'state-changed'),
+        (CATEGORY_DELEGATE_CHANGED, 'delegate-changed'),
+        (CATEGORY_CHECK_ADDED, 'check-added'),
+    )
+
+    patch = models.ForeignKey(
+        Patch, related_name='events', related_query_name='event',
+        help_text='The patch that the event was raised against.')
+    user = models.ForeignKey(
+        User, blank=True, null=True, related_name='events',
+        related_query_name='event',
+        help_text='The user that caused the event, if any.')
+    category = models.SmallIntegerField(
+        choices=CATEGORY_CHOICES,
+        help_text='The category of the event.')
+    created_on = models.DateTimeField(
+        default=datetime.datetime.now,
+        help_text='The time this event was created.')
+
+    before = models.PositiveIntegerField(
+        blank=True, null=True,
+        help_text='An identifier for the previous value of the changed patch '
+        'attribute, if any. The meaning of this value is entirely dependant '
+        'on the category')
+    after = models.PositiveIntegerField(
+        blank=True, null=True,
+        help_text='An identifier for the previous value of the changed patch '
+        'attribute, if any. The meaning of this value is entirely dependant '
+        'on the category')
+
+    class Meta:
+        ordering = ['-created_on']
+
+
 class Bundle(models.Model):
     owner = models.ForeignKey(User)
     project = models.ForeignKey(Project)
-- 
2.7.4



More information about the Patchwork mailing list