built-in Django, fix a couple of bugs, make pending liaison emails use the normal liaison email template too instead of duplicating the content - Legacy-Id: 3352
63 lines
2.8 KiB
Python
63 lines
2.8 KiB
Python
from django.conf import settings
|
|
from django.template.loader import render_to_string
|
|
from django.core.urlresolvers import reverse as urlreverse
|
|
|
|
from ietf.utils.mail import send_mail_text
|
|
|
|
def send_liaison_by_email(request, liaison, fake=False):
|
|
if liaison.is_pending(): # this conditional should definitely be at the caller, not here
|
|
return notify_pending_by_email(request, liaison, fake)
|
|
|
|
subject = u'New Liaison Statement, "%s"' % (liaison.title)
|
|
from_email = settings.LIAISON_UNIVERSAL_FROM
|
|
to_email = liaison.to_poc.split(',')
|
|
cc = liaison.cc1.split(',')
|
|
if liaison.technical_contact:
|
|
cc += liaison.technical_contact.split(',')
|
|
if liaison.response_contact:
|
|
cc += liaison.response_contact.split(',')
|
|
bcc = ['statements@ietf.org']
|
|
body = render_to_string('liaisons/liaison_mail.txt', dict(
|
|
liaison=liaison,
|
|
url=settings.IDTRACKER_BASE_URL + urlreverse("liaison_detail", kwargs=dict(object_id=liaison.pk)),
|
|
referenced_url=settings.IDTRACKER_BASE_URL + urlreverse("liaison_detail", kwargs=dict(object_id=liaison.related_to.pk)) if liaison.related_to else None,
|
|
))
|
|
if fake:
|
|
# rather than this fake stuff, it's probably better to start a
|
|
# debug SMTP server as explained in the Django docs
|
|
from ietf.liaisons.mail import IETFEmailMessage
|
|
mail = IETFEmailMessage(subject=subject,
|
|
to=to_email,
|
|
from_email=from_email,
|
|
cc = cc,
|
|
bcc = bcc,
|
|
body = body)
|
|
return mail
|
|
|
|
send_mail_text(request, to_email, from_email, subject, body, cc=", ".join(cc), bcc=", ".join(bcc))
|
|
|
|
def notify_pending_by_email(request, liaison, fake):
|
|
from ietf.liaisons.utils import IETFHM
|
|
|
|
from_entity = IETFHM.get_entity_by_key(liaison.from_raw_code)
|
|
if not from_entity:
|
|
return None
|
|
to_email = []
|
|
for person in from_entity.can_approve():
|
|
to_email.append('%s <%s>' % person.email())
|
|
subject = u'New Liaison Statement, "%s" needs your approval' % (liaison.title)
|
|
from_email = settings.LIAISON_UNIVERSAL_FROM
|
|
body = render_to_string('liaisons/pending_liaison_mail.txt', dict(
|
|
liaison=liaison,
|
|
url=settings.IDTRACKER_BASE_URL + urlreverse("liaison_approval_detail", kwargs=dict(object_id=liaison.pk)),
|
|
referenced_url=settings.IDTRACKER_BASE_URL + urlreverse("liaison_detail", kwargs=dict(object_id=liaison.related_to.pk)) if liaison.related_to else None,
|
|
))
|
|
if fake:
|
|
mail = IETFEmailMessage(subject=subject,
|
|
to=to_email,
|
|
from_email=from_email,
|
|
body = body)
|
|
return mail
|
|
send_mail_text(request, to_email, from_email, subject, body)
|
|
|