From 3074b990177d6e2fde5c21bea16948f12027ef2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89lie=20Bouttier?= Date: Sun, 17 Aug 2014 14:31:41 -0700 Subject: [PATCH] notifications when close/reopen issue --- issue/notifications.py | 34 ++++++++++++++---------- issue/templates/emails/close_issue.html | 4 +++ issue/templates/emails/new_comment.html | 14 +++------- issue/templates/emails/new_issue.html | 14 ++++------ issue/templates/emails/reopen_issue.html | 4 +++ issue/views.py | 4 +++ 6 files changed, 40 insertions(+), 34 deletions(-) create mode 100644 issue/templates/emails/close_issue.html create mode 100644 issue/templates/emails/reopen_issue.html diff --git a/issue/notifications.py b/issue/notifications.py index 095e8a1..baa1500 100644 --- a/issue/notifications.py +++ b/issue/notifications.py @@ -9,7 +9,6 @@ from issue.models import * def notify_new_issue(issue): project = issue.project - dests = project.subscribers.all().distinct() if hasattr(settings, 'FROM_ADDR'): @@ -17,10 +16,9 @@ def notify_new_issue(issue): else: return - subject = "[PonyTracker] New issue: %s (%s)" %(issue.title, project) + subject = "[%s] %s" %(project, issue.title) data = [] - for dest in dests: if dest == issue.author: @@ -31,22 +29,32 @@ def notify_new_issue(issue): continue c = { - 'dest': dest.username, - 'author': issue.author.username, - 'title': issue.title, - 'description:': issue.description, + 'description': issue.description, 'uri': settings.BASE_URL \ + reverse('show-issue', args=[project.name, issue.id]), } message = render_to_string('emails/new_issue.html', c) - data += [(subject, message, from_addr, [dest_addr])] + data += [(subject, message, + "%s <%s>" %(issue.author.username, from_addr), [dest_addr])] send_mass_mail(tuple(data)) def notify_new_comment(event): + notify_event(event, 'new_comment') + + +def notify_close_issue(event): + notify_event(event, 'close_issue') + + +def notify_reopen_issue(event): + notify_event(event, 'reopen_issue') + + +def notify_event(event, template): issue = event.issue project = issue.project @@ -60,7 +68,7 @@ def notify_new_comment(event): else: return - subject = "[PonyTracker] New comment - %s (%s)" %(issue.title, project) + subject = "Re: [%s] %s" %(project, issue.title) data = [] @@ -74,16 +82,14 @@ def notify_new_comment(event): continue c = { - 'dest': dest.username, - 'author': event.author.username, - 'title': issue.title, 'comment': event.additionnal_section, 'uri': settings.BASE_URL \ + reverse('show-issue', args=[project.name, issue.id]), } - message = render_to_string('emails/new_comment.html', c) + message = render_to_string('emails/%s.html' % template, c) - data += [(subject, message, from_addr, [dest_addr])] + data += [(subject, message, + '%s <%s>' %(event.author.username, from_addr), [dest_addr])] send_mass_mail(tuple(data)) diff --git a/issue/templates/emails/close_issue.html b/issue/templates/emails/close_issue.html new file mode 100644 index 0000000..59a5557 --- /dev/null +++ b/issue/templates/emails/close_issue.html @@ -0,0 +1,4 @@ +Issue closed. + +-- +You can see the issue on PonyTracker: {{ uri }} diff --git a/issue/templates/emails/new_comment.html b/issue/templates/emails/new_comment.html index cf1a870..79512e7 100644 --- a/issue/templates/emails/new_comment.html +++ b/issue/templates/emails/new_comment.html @@ -1,12 +1,4 @@ -Dear {{ dest }}, +{{ comment }} -{{ author }} commented the issue '{{ title }}': - - {{ comment }} - -You can respond by following this link: - - {{ uri }} - -Sincerly, -PonyTracker +-- +Respond on PonyTracker: {{ uri }} diff --git a/issue/templates/emails/new_issue.html b/issue/templates/emails/new_issue.html index 53c6551..c145060 100644 --- a/issue/templates/emails/new_issue.html +++ b/issue/templates/emails/new_issue.html @@ -1,12 +1,8 @@ -Dear {{ dest }}, - -{{ author }} added a new issue: '{{ title }}' {% if description %} - {{ description }} +{{ description }} +{% else %} + No description. {% endif %} -You can coment it by following this link: - {{ uri }} - -Sincerly, -PonyTracker +-- +Comment it on PonyTracker: {{ uri }} diff --git a/issue/templates/emails/reopen_issue.html b/issue/templates/emails/reopen_issue.html new file mode 100644 index 0000000..96d8a94 --- /dev/null +++ b/issue/templates/emails/reopen_issue.html @@ -0,0 +1,4 @@ +Issue reopened. + +-- +You can see the issue on PonyTracker: {{ uri }} diff --git a/issue/views.py b/issue/views.py index d850cf1..6b44af7 100644 --- a/issue/views.py +++ b/issue/views.py @@ -521,6 +521,8 @@ def issue_close(request, project, issue): event = Event(issue=issue, author=author, code=Event.CLOSE) event.save() + notify_close_issue(event) + return redirect('list-issue', project.name) @@ -536,6 +538,8 @@ def issue_reopen(request, project, issue): event = Event(issue=issue, author=author, code=Event.REOPEN) event.save() + notify_reopen_issue(event) + return redirect('show-issue', project.name, issue.id)