diff options
Diffstat (limited to 'pgcommitfest/commitfest/management/commands/send_notifications.py')
-rw-r--r-- | pgcommitfest/commitfest/management/commands/send_notifications.py | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/pgcommitfest/commitfest/management/commands/send_notifications.py b/pgcommitfest/commitfest/management/commands/send_notifications.py index 6a8fe42..be8cd90 100644 --- a/pgcommitfest/commitfest/management/commands/send_notifications.py +++ b/pgcommitfest/commitfest/management/commands/send_notifications.py @@ -9,38 +9,38 @@ from pgcommitfest.userprofile.models import UserProfile from pgcommitfest.mailqueue.util import send_template_mail class Command(BaseCommand): - help = "Send queued notifications" + help = "Send queued notifications" - def handle(self, *args, **options): - with transaction.atomic(): - # Django doesn't do proper group by in the ORM, so we have to - # build our own. - matches = {} - for n in PendingNotification.objects.all().order_by('user', 'history__patch__id', 'history__id'): - if not matches.has_key(n.user.id): - matches[n.user.id] = {'user': n.user, 'patches': {}} - if not matches[n.user.id]['patches'].has_key(n.history.patch.id): - matches[n.user.id]['patches'][n.history.patch.id] = {'patch': n.history.patch, 'entries': []} - matches[n.user.id]['patches'][n.history.patch.id]['entries'].append(n.history) - n.delete() + def handle(self, *args, **options): + with transaction.atomic(): + # Django doesn't do proper group by in the ORM, so we have to + # build our own. + matches = {} + for n in PendingNotification.objects.all().order_by('user', 'history__patch__id', 'history__id'): + if not matches.has_key(n.user.id): + matches[n.user.id] = {'user': n.user, 'patches': {}} + if not matches[n.user.id]['patches'].has_key(n.history.patch.id): + matches[n.user.id]['patches'][n.history.patch.id] = {'patch': n.history.patch, 'entries': []} + matches[n.user.id]['patches'][n.history.patch.id]['entries'].append(n.history) + n.delete() - # Ok, now let's build emails from this - for v in matches.values(): - user = v['user'] - email = user.email - try: - if user.userprofile and user.userprofile.notifyemail: - email = user.userprofile.notifyemail.email - except UserProfile.DoesNotExist: - pass + # Ok, now let's build emails from this + for v in matches.values(): + user = v['user'] + email = user.email + try: + if user.userprofile and user.userprofile.notifyemail: + email = user.userprofile.notifyemail.email + except UserProfile.DoesNotExist: + pass - send_template_mail(settings.NOTIFICATION_FROM, - None, - email, - "PostgreSQL commitfest updates", - 'mail/patch_notify.txt', - { - 'user': user, - 'patches': v['patches'], - }, - ) + send_template_mail(settings.NOTIFICATION_FROM, + None, + email, + "PostgreSQL commitfest updates", + 'mail/patch_notify.txt', + { + 'user': user, + 'patches': v['patches'], + }, + ) |