diff options
author | Magnus Hagander | 2016-02-12 17:03:26 +0000 |
---|---|---|
committer | Magnus Hagander | 2016-02-12 17:03:26 +0000 |
commit | 986048a270afd56ef4f504d8e417d81f28970362 (patch) | |
tree | ddd42a69157676e6caf311f1ed133ac30ae3011e /pgcommitfest/commitfest/models.py | |
parent | 6dec4d85a2eb96a5cbf502f282e9087c9f9081a5 (diff) |
Implement notifications
This makes it possible to receive notifications (via email) when a patch
has been updated.
It's possible to subscribe to notifications on a specific patch. It is also
possible to set the user profile up so that one receives notifications for
all patches where one is author, reviewer or committer on.
Notifications are, of course, only sent when other people make modifications
to the entry.
Diffstat (limited to 'pgcommitfest/commitfest/models.py')
-rw-r--r-- | pgcommitfest/commitfest/models.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/pgcommitfest/commitfest/models.py b/pgcommitfest/commitfest/models.py index ead5eea..04d2fb4 100644 --- a/pgcommitfest/commitfest/models.py +++ b/pgcommitfest/commitfest/models.py @@ -91,6 +91,9 @@ class Patch(models.Model, DiffableModel): committer = models.ForeignKey(Committer, blank=True, null=True) + # Users to be notified when something happens + subscribers = models.ManyToManyField(User, related_name='patch_subscriber', blank=True) + # Datestamps for tracking activity created = models.DateTimeField(blank=False, null=False, auto_now_add=True) modified = models.DateTimeField(blank=False, null=False) @@ -210,6 +213,34 @@ class PatchHistory(models.Model): class Meta: ordering = ('-date', ) + def save_and_notify(self, prevcommitter=None, + prevreviewers=None, prevauthors=None): + # Save this model, and then trigger notifications if there are any. There are + # many different things that can trigger notifications, so try them all. + self.save() + + recipients = [] + recipients.extend(self.patch.subscribers.all()) + + # Current or previous committer wants all notifications + if self.patch.committer and self.patch.committer.user.userprofile.notify_all_committer: + recipients.append(self.patch.committer.user) + if prevcommitter and prevcommitter.user.userprofile.notify_all_committer: + recipients.append(prevcommitter.user) + + # Current or previous reviewers wants all notifications + recipients.extend(self.patch.reviewers.filter(userprofile__notify_all_reviewer=True)) + if prevreviewers: + # prevreviewers is a list + recipients.extend(User.objects.filter(id__in=[p.id for p in prevreviewers], userprofile__notify_all_reviewer=True)) + + # Current or previous authors wants all notifications + recipients.extend(self.patch.authors.filter(userprofile__notify_all_author=True)) + + for u in set(recipients): + if u != self.by: # Don't notify for changes we make ourselves + PendingNotification(history=self, user=u).save() + class MailThread(models.Model): # This class tracks mail threads from the main postgresql.org # mailinglist archives. For each thread, we store *one* messageid. @@ -270,3 +301,8 @@ class PatchStatus(models.Model): status = models.IntegerField(null=False, blank=False, primary_key=True) statusstring = models.TextField(max_length=50, null=False, blank=False) sortkey = models.IntegerField(null=False, blank=False, default=10) + + +class PendingNotification(models.Model): + history = models.ForeignKey(PatchHistory, blank=False, null=False) + user = models.ForeignKey(User, blank=False, null=False) |