Port liaison deadline reminder emails to new schema, with test;
refactor email to use the normal liaison email for the bulk of the message instead of duplicating it - Legacy-Id: 3358
This commit is contained in:
parent
2aa97434fb
commit
89dd9b83ca
|
@ -1,3 +1,5 @@
|
|||
import datetime
|
||||
|
||||
from django.conf import settings
|
||||
from django.template.loader import render_to_string
|
||||
from django.core.urlresolvers import reverse as urlreverse
|
||||
|
@ -64,7 +66,7 @@ def notify_pending_by_email(request, liaison, fake):
|
|||
|
||||
def send_sdo_reminder(sdo):
|
||||
roles = Role.objects.filter(name="liaiman", group=sdo)
|
||||
if not roles:
|
||||
if not roles: # no manager to contact
|
||||
return None
|
||||
|
||||
manager_role = roles[0]
|
||||
|
@ -83,3 +85,44 @@ def send_sdo_reminder(sdo):
|
|||
send_mail_text(None, to_email, settings.LIAISON_UNIVERSAL_FROM, subject, body)
|
||||
|
||||
return body
|
||||
|
||||
def possibly_send_deadline_reminder(liaison):
|
||||
PREVIOUS_DAYS = {
|
||||
14: 'in two weeks',
|
||||
7: 'in one week',
|
||||
4: 'in four days',
|
||||
3: 'in three days',
|
||||
2: 'in two days',
|
||||
1: 'tomorrow',
|
||||
0: 'today'
|
||||
}
|
||||
|
||||
days_to_go = (liaison.deadline - datetime.date.today()).days
|
||||
if not (days_to_go < 0 or days_to_go in PREVIOUS_DAYS.keys()):
|
||||
return None # no reminder
|
||||
|
||||
if days_to_go < 0:
|
||||
subject = '[Liaison OUT OF DATE] %s' % liaison.title
|
||||
days_msg = 'is out of date for %s days' % (-days_to_go)
|
||||
else:
|
||||
subject = '[Liaison deadline %s] %s' % (PREVIOUS_DAYS[days_to_go], liaison.title)
|
||||
days_msg = 'expires %s' % PREVIOUS_DAYS[days_to_go]
|
||||
|
||||
from_email = settings.LIAISON_UNIVERSAL_FROM
|
||||
to_email = liaison.to_contact.split(',')
|
||||
cc = liaison.cc.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_deadline_mail.txt',
|
||||
dict(liaison=liaison,
|
||||
days_msg=days_msg,
|
||||
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,
|
||||
))
|
||||
|
||||
send_mail_text(None, to_email, from_email, subject, body, cc=cc, bcc=bcc)
|
||||
|
||||
return body
|
||||
|
|
|
@ -3,6 +3,7 @@ import datetime
|
|||
from django.conf import settings
|
||||
from django.core.management.base import BaseCommand
|
||||
from django.template.loader import render_to_string
|
||||
from django.core.urlresolvers import reverse as urlreverse
|
||||
|
||||
from ietf.liaisons.models import LiaisonDetail
|
||||
from ietf.liaisons.mail import IETFEmailMessage
|
||||
|
@ -19,7 +20,7 @@ PREVIOUS_DAYS = {
|
|||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = (u"Check liaison deadlines and send a reminder if we are close to its deadline")
|
||||
help = (u"Check liaison deadlines and send a reminder if we are close to a deadline")
|
||||
|
||||
def send_reminder(self, liaison, days_to_go):
|
||||
if days_to_go < 0:
|
||||
|
@ -40,6 +41,8 @@ class Command(BaseCommand):
|
|||
body = render_to_string('liaisons/liaison_deadline_mail.txt',
|
||||
{'liaison': liaison,
|
||||
'days_msg': days_msg,
|
||||
'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,
|
||||
})
|
||||
mail = IETFEmailMessage(subject=subject,
|
||||
to=to_email,
|
||||
|
@ -55,6 +58,19 @@ class Command(BaseCommand):
|
|||
|
||||
def handle(self, *args, **options):
|
||||
today = datetime.date.today()
|
||||
|
||||
if settings.USE_DB_REDESIGN_PROXY_CLASSES:
|
||||
from ietf.liaisons.mails import possibly_send_deadline_reminder
|
||||
from ietf.liaisons.proxy import LiaisonDetailProxy as LiaisonDetail
|
||||
|
||||
cutoff = today - datetime.timedelta(14)
|
||||
|
||||
for l in LiaisonDetail.objects.filter(action_taken=False, deadline__gte=cutoff).exclude(deadline=None):
|
||||
r = possibly_send_deadline_reminder(l)
|
||||
if r:
|
||||
print 'Liaison %05s#: Deadline reminder sent!' % liaison.pk
|
||||
return
|
||||
|
||||
query = LiaisonDetail.objects.filter(deadline_date__isnull=False, action_taken=False, deadline_date__gte=today - datetime.timedelta(14))
|
||||
for liaison in query:
|
||||
delta = liaison.deadline_date - today
|
||||
|
|
|
@ -394,7 +394,28 @@ class LiaisonManagementTestCase(django.test.TestCase):
|
|||
send_sdo_reminder(Group.objects.filter(type="sdo")[0])
|
||||
self.assertEquals(len(mail_outbox), mailbox_before + 1)
|
||||
self.assertTrue("authorized individuals" in mail_outbox[-1]["Subject"])
|
||||
print mail_outbox[-1]
|
||||
|
||||
def test_send_liaison_deadline_reminder(self):
|
||||
make_test_data()
|
||||
liaison = make_liaison_models()
|
||||
|
||||
from ietf.liaisons.mails import possibly_send_deadline_reminder
|
||||
from ietf.liaisons.proxy import LiaisonDetailProxy as LiaisonDetail
|
||||
|
||||
l = LiaisonDetail.objects.all()[0]
|
||||
|
||||
mailbox_before = len(mail_outbox)
|
||||
possibly_send_deadline_reminder(l)
|
||||
self.assertEquals(len(mail_outbox), mailbox_before + 1)
|
||||
self.assertTrue("deadline" in mail_outbox[-1]["Subject"])
|
||||
|
||||
# try pushing the deadline
|
||||
l.deadline = l.deadline + datetime.timedelta(days=30)
|
||||
l.save()
|
||||
|
||||
mailbox_before = len(mail_outbox)
|
||||
possibly_send_deadline_reminder(l)
|
||||
self.assertEquals(len(mail_outbox), mailbox_before)
|
||||
|
||||
|
||||
if not settings.USE_DB_REDESIGN_PROXY_CLASSES:
|
||||
|
|
|
@ -1,21 +1,4 @@
|
|||
{% autoescape off %}The following liaison {{ days_msg }}. Plase take actions.
|
||||
|
||||
Title: {{ liaison.title }}
|
||||
Submission Date: {{ liaison.submitted_date }}
|
||||
URL of the IETF Web page: {% url liaison_detail object_id=liaison.pk %}
|
||||
{% if liaison.deadline_date %}Please reply by {{ liaison.deadline_date }}{% endif %}
|
||||
From: {{ liaison.from_body }} ({{ liaison.person }} <{{ liaison.replyto|default:liaison.from_email }}>)
|
||||
To: {{ liaison.to_body }} ({{ liaison.to_poc }})
|
||||
Cc: {{ liaison.cc1 }}
|
||||
Reponse Contact: {{ liaison.response_contact }}
|
||||
Technical Contact: {{ liaison.technical_contact }}
|
||||
Purpose: {% if liaison.purpose_text %}{{ liaison.purpose_text }}{% else %}{{ liaison.purpose.purpose_text }}{% endif %}
|
||||
{% if liaison.related_to %}Referenced liaison: {% if liaison.related_to.title %}{{ liaison.related_to.title }}{% else %}Liaison #{{ liaison.related_to.pk }}{% endif %} ({% url liaison_detail object_id=liaison.related_to.pk %}){% endif %}
|
||||
Body: {{ liaison.body }}
|
||||
Attachment(s):
|
||||
{% for file in liaison.uploads_set.all %}
|
||||
{{ file.file_title }} https://datatracker.ietf.org/documents/LIAISON/file{{ file.filename }}
|
||||
{% empty %}
|
||||
No document has been attached
|
||||
{% endfor %}
|
||||
{% include "liaisons/liaison_mail.txt" %}
|
||||
{% endautoescape %}
|
||||
|
|
Loading…
Reference in a new issue