factorize notifications
This commit is contained in:
parent
9495924722
commit
2d724f0c82
1 changed files with 28 additions and 46 deletions
|
@ -23,41 +23,16 @@ def notify_new_issue(issue):
|
||||||
project = issue.project
|
project = issue.project
|
||||||
dests = project.subscribers.all().distinct()
|
dests = project.subscribers.all().distinct()
|
||||||
|
|
||||||
if hasattr(settings, 'FROM_ADDR'):
|
|
||||||
from_addr = settings.FROM_ADDR
|
|
||||||
else:
|
|
||||||
return
|
|
||||||
|
|
||||||
subject = "[%s] %s" % (project, issue.title)
|
subject = "[%s] %s" % (project, issue.title)
|
||||||
|
sender = issue.author
|
||||||
|
|
||||||
data = []
|
data = {
|
||||||
for dest in dests:
|
'description': issue.description,
|
||||||
|
'uri': settings.BASE_URL + reverse('show-issue',
|
||||||
if dest.notifications == User.NOTIFICATIONS_NEVER:
|
args=[project.name, issue.id]),
|
||||||
continue
|
}
|
||||||
if dest == issue.author \
|
|
||||||
and dest.notifications == User.NOTIFICATIONS_OTHERS:
|
|
||||||
continue
|
|
||||||
dest_addr = dest.email
|
|
||||||
if not dest_addr:
|
|
||||||
continue
|
|
||||||
|
|
||||||
c = {
|
|
||||||
'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,
|
|
||||||
"%s <%s>" % (issue.author.username, from_addr), [dest_addr])]
|
|
||||||
|
|
||||||
if 'djcelery' in settings.INSTALLED_APPS:
|
|
||||||
send_mass_mail.delay(tuple(data))
|
|
||||||
else:
|
|
||||||
send_mass_mail(tuple(data))
|
|
||||||
|
|
||||||
|
notify_by_email(data, 'new_issue', subject, sender, dests)
|
||||||
|
|
||||||
def notify_new_comment(event):
|
def notify_new_comment(event):
|
||||||
notify_event(event, 'new_comment')
|
notify_event(event, 'new_comment')
|
||||||
|
@ -80,14 +55,30 @@ def notify_event(event, template):
|
||||||
dests |= project.subscribers.all()
|
dests |= project.subscribers.all()
|
||||||
dests = dests.distinct()
|
dests = dests.distinct()
|
||||||
|
|
||||||
|
subject = "Re: [%s] %s" % (project, issue.title)
|
||||||
|
sender = event.author
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'comment': event.additionnal_section,
|
||||||
|
'uri': settings.BASE_URL + reverse('show-issue',
|
||||||
|
args=[project.name, issue.id]),
|
||||||
|
}
|
||||||
|
|
||||||
|
notify_by_email(data, template, subject, sender, dests)
|
||||||
|
|
||||||
|
|
||||||
|
def notify_by_email(data, template, subject, sender, dests):
|
||||||
|
|
||||||
|
message = render_to_string('emails/%s.html' % template, data)
|
||||||
|
|
||||||
if hasattr(settings, 'FROM_ADDR'):
|
if hasattr(settings, 'FROM_ADDR'):
|
||||||
from_addr = settings.FROM_ADDR
|
from_addr = settings.FROM_ADDR
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
|
||||||
subject = "Re: [%s] %s" % (project, issue.title)
|
from_addr = '%s <%s>' % (sender.fullname or sender.username, from_addr)
|
||||||
|
|
||||||
data = []
|
mails = []
|
||||||
|
|
||||||
for dest in dests:
|
for dest in dests:
|
||||||
|
|
||||||
|
@ -100,18 +91,9 @@ def notify_event(event, template):
|
||||||
if not dest_addr:
|
if not dest_addr:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
c = {
|
mails += [(subject, message, from_addr, [dest_addr])]
|
||||||
'comment': event.additionnal_section,
|
|
||||||
'uri': settings.BASE_URL + reverse('show-issue',
|
|
||||||
args=[project.name, issue.id]),
|
|
||||||
}
|
|
||||||
|
|
||||||
message = render_to_string('emails/%s.html' % template, c)
|
|
||||||
|
|
||||||
data += [(subject, message,
|
|
||||||
'%s <%s>' % (event.author.username, from_addr), [dest_addr])]
|
|
||||||
|
|
||||||
if 'djcelery' in settings.INSTALLED_APPS:
|
if 'djcelery' in settings.INSTALLED_APPS:
|
||||||
send_mass_mail.delay(tuple(data))
|
send_mass_mail.delay(tuple(mails))
|
||||||
else:
|
else:
|
||||||
send_mass_mail(tuple(data))
|
send_mass_mail(tuple(mails))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue