diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2011-04-14 19:37:55 +0800 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2011-04-14 19:37:55 +0800 |
commit | f1e5f6a2c9d737f12290f5bd5a934b74c362616f (patch) | |
tree | 5917844b4f15870e9a0015f2ebd1d928190bf9cb /apps/patchwork/utils.py | |
parent | 017f73b059aadfce30ee29d2aceeab92739105a6 (diff) | |
download | patchwork-f1e5f6a2c9d737f12290f5bd5a934b74c362616f.tar.bz2 patchwork-f1e5f6a2c9d737f12290f5bd5a934b74c362616f.tar.xz |
notifications: implement opt-outnotifications
Check for opt-out status before sending notification mail.
Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
Diffstat (limited to 'apps/patchwork/utils.py')
-rw-r--r-- | apps/patchwork/utils.py | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/apps/patchwork/utils.py b/apps/patchwork/utils.py index 58edb19..5cb45e8 100644 --- a/apps/patchwork/utils.py +++ b/apps/patchwork/utils.py @@ -28,7 +28,7 @@ from django.core.mail import EmailMessage from django.db.models import Max from patchwork.forms import MultiplePatchForm from patchwork.models import Bundle, Project, BundlePatch, UserProfile, \ - PatchChangeNotification + PatchChangeNotification, EmailOptout def get_patch_ids(d, prefix = 'patch_id'): ids = [] @@ -169,6 +169,15 @@ def send_notifications(): for (recipient, notifications) in groups: notifications = list(notifications) + + def delete_notifications(): + PatchChangeNotification.objects.filter( + pk__in = notifications).delete() + + if EmailOptout.is_optout(recipient.email): + delete_notifications() + continue + context = { 'site': Site.objects.get_current(), 'person': recipient, @@ -191,6 +200,6 @@ def send_notifications(): errors.append((recipient, ex)) continue - PatchChangeNotification.objects.filter(pk__in = notifications).delete() + delete_notifications() return errors |