fix changeset notifying

This commit is contained in:
Laura Klünder 2017-12-20 13:50:32 +01:00
parent 2964ddf0f4
commit 64f5d34b66
2 changed files with 11 additions and 5 deletions

View file

@ -518,7 +518,13 @@ class ChangeSet(models.Model):
self.last_update = update
self.last_state_update = update
self.save()
send_changeset_proposed_notification.delay(changeset=self)
self.notify_reviewers()
def notify_reviewers(self):
send_changeset_proposed_notification.delay(pk=self.pk,
title=self.title,
author=self.author.username,
description=self.description)
def unpropose(self, user):
new_state = {'proposed': 'unproposed', 'reproposed': 'rejected'}[self.state]

View file

@ -10,15 +10,15 @@ logger = logging.getLogger('c3nav')
@app.task(bind=True, max_retries=3)
def send_changeset_proposed_notification(self, changeset):
subject = '[c3nav] New Changeset by %s: %s' % (changeset.author.username, changeset.title)
def send_changeset_proposed_notification(self, pk, author, title, description):
subject = '[c3nav] New Changeset by %s: %s' % (author, title)
for user in User.objects.filter(permissions__review_changesets=True):
if not user.email:
continue
text = (
('Hi %s!\n\n' % user.username) +
('A new Changeset has been proposed by %s:\n\n' % changeset.author.username) +
('A new Changeset has been proposed by %s:\n\n' % author) +
('---\n\n') +
(changeset.title+'\n\n'+changeset.description)
(title+'\n\n'+description)
)
send_mail(subject, text, settings.MAIL_FROM, [user.email])