email notifications
This commit is contained in:
parent
4658732dde
commit
0ff1f115dd
5 changed files with 122 additions and 0 deletions
89
issue/notifications.py
Normal file
89
issue/notifications.py
Normal file
|
@ -0,0 +1,89 @@
|
|||
from django.core.mail import send_mass_mail
|
||||
from django.template.loader import render_to_string
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.conf import settings
|
||||
|
||||
from issue.models import *
|
||||
|
||||
|
||||
def notify_new_issue(issue):
|
||||
|
||||
project = issue.project
|
||||
|
||||
dests = project.subscribers.all().distinct()
|
||||
|
||||
if hasattr(settings, 'FROM_ADDR'):
|
||||
from_addr = settings.FROM_ADDR
|
||||
else:
|
||||
return
|
||||
|
||||
subject = "[PonyTracker] New issue: %s (%s)" %(issue.title, project.name)
|
||||
|
||||
data = []
|
||||
|
||||
for dest in dests:
|
||||
|
||||
if dest == issue.author:
|
||||
continue
|
||||
|
||||
dest_addr = dest.email
|
||||
if not dest_addr:
|
||||
continue
|
||||
|
||||
c = {
|
||||
'dest': dest.username,
|
||||
'author': issue.author.username,
|
||||
'title': issue.title,
|
||||
'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])]
|
||||
|
||||
send_mass_mail(tuple(data))
|
||||
|
||||
|
||||
def notify_new_comment(event):
|
||||
|
||||
issue = event.issue
|
||||
project = issue.project
|
||||
|
||||
dests = issue.subscribers.all()
|
||||
dests |= project.subscribers.all()
|
||||
dests = dests.distinct()
|
||||
|
||||
if hasattr(settings, 'FROM_ADDR'):
|
||||
from_addr = settings.FROM_ADDR
|
||||
else:
|
||||
return
|
||||
|
||||
subject = "[PonyTracker] New comment - %s (%s)" %(issue.title, project.name)
|
||||
|
||||
data = []
|
||||
|
||||
for dest in dests:
|
||||
|
||||
if dest == event.author:
|
||||
continue
|
||||
|
||||
dest_addr = dest.email
|
||||
if not dest_addr:
|
||||
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)
|
||||
|
||||
data += [(subject, message, from_addr, [dest_addr])]
|
||||
|
||||
send_mass_mail(tuple(data))
|
12
issue/templates/emails/new_comment.html
Normal file
12
issue/templates/emails/new_comment.html
Normal file
|
@ -0,0 +1,12 @@
|
|||
Dear {{ dest }},
|
||||
|
||||
{{ author }} commented the issue '{{ title }}':
|
||||
|
||||
{{ comment }}
|
||||
|
||||
You can respond by following this link:
|
||||
|
||||
{{ uri }}
|
||||
|
||||
Sincerly,
|
||||
PonyTracker
|
12
issue/templates/emails/new_issue.html
Normal file
12
issue/templates/emails/new_issue.html
Normal file
|
@ -0,0 +1,12 @@
|
|||
Dear {{ dest }},
|
||||
|
||||
{{ author }} added a new issue: '{{ title }}'
|
||||
{% if description %}
|
||||
{{ description }}
|
||||
{% endif %}
|
||||
You can coment it by following this link:
|
||||
|
||||
{{ uri }}
|
||||
|
||||
Sincerly,
|
||||
PonyTracker
|
|
@ -7,6 +7,7 @@ from django.views.decorators.http import require_http_methods
|
|||
|
||||
from issue.models import *
|
||||
from issue.forms import *
|
||||
from issue.notifications import *
|
||||
from issue.decorators import project_perm_required
|
||||
|
||||
import shlex
|
||||
|
@ -405,6 +406,7 @@ def issue_edit(request, project, issue=None):
|
|||
issue.save()
|
||||
issue.subscribers.add(author)
|
||||
issue.description = description
|
||||
notify_new_issue(issue)
|
||||
messages.success(request, 'Issue created successfully.')
|
||||
|
||||
return redirect('show-issue', project.name, issue.id)
|
||||
|
@ -480,6 +482,7 @@ def issue_edit_comment(request, project, issue, comment=None):
|
|||
code=Event.COMMENT, additionnal_section=comment)
|
||||
event.save()
|
||||
issue.subscribers.add(author)
|
||||
notify_new_comment(event)
|
||||
messages.success(request, 'Comment added successfully.')
|
||||
|
||||
return redirect('show-issue', project.name, issue.id)
|
||||
|
|
|
@ -123,3 +123,9 @@ AUTHENTICATION_BACKENDS = (
|
|||
)
|
||||
|
||||
SITE_ID = 1
|
||||
|
||||
EMAIL_HOST = 'smtp'
|
||||
|
||||
#FROM_ADDR = 'ponytracker@example.com'
|
||||
|
||||
BASE_URL = 'http://localhost:8000'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue