From 3a45c8e56049f50d9f43e13d6c466b177b24f5e7 Mon Sep 17 00:00:00 2001 From: Bill Fenner Date: Sat, 20 Mar 2010 20:15:20 +0000 Subject: [PATCH] Merge the I-D notification work from my sprint branch. - Legacy-Id: 2112 --- changelog | 8 +++ ietf/bin/notify-expirations | 60 +++++++++++++++++++ ietf/templates/notify_expirations/body.txt | 6 ++ ietf/templates/notify_expirations/subject.txt | 1 + ietf/utils/mail.py | 12 +++- 5 files changed, 84 insertions(+), 3 deletions(-) create mode 100755 ietf/bin/notify-expirations create mode 100644 ietf/templates/notify_expirations/body.txt create mode 100644 ietf/templates/notify_expirations/subject.txt diff --git a/changelog b/changelog index 53cb760e8..82727bfa7 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,11 @@ +ietfdb (2.46) + + From Robert: + + * Add the I-D expiration notification script. + + -- Bill Fenner 20 Mar 2010 12:59:50 -0800 + ietfdb (2.45) From Pasi: diff --git a/ietf/bin/notify-expirations b/ietf/bin/notify-expirations new file mode 100755 index 000000000..0e96f7ad0 --- /dev/null +++ b/ietf/bin/notify-expirations @@ -0,0 +1,60 @@ +#!/usr/bin/env python + +import datetime + +from ietf import settings +from django.core import management +management.setup_environ(settings) + +from ietf.idtracker.models import InternetDraft,IDAuthor,WGChair +from ietf.utils.mail import send_mail_subj + +notify_days = 14 # notify about documents that expire within the + # next 2 weeks + +start_date = datetime.date.today() - datetime.timedelta(InternetDraft.DAYS_TO_EXPIRE - 1) +end_date = start_date + datetime.timedelta(notify_days - 1) + + +matches = InternetDraft.objects.filter(revision_date__gte=start_date,revision_date__lte=end_date,status__status='Active') + +#For development - focus on one draft +#matches = InternetDraft.objects.filter(filename__icontains='geopriv-http-location-delivery') + +# Todo: +#second_cutoff = IDDates.objects.get(date_id=2) +#ietf_monday = IDDates.objects.get(date_id=3) +#freeze_delta = ietf_monday - second_cutoff + +for draft in matches: + if not draft.can_expire(): + # debugging + #print "%s can't expire, skipping" % draft + continue + expiration = draft.expiration() +# # The I-D expiration job doesn't run while submissions are frozen. +# if ietf_monday > expiration > second_cutoff: +# expiration += freeze_delta + authors = draft.authors.all() + to_addrs = [author.email() for author in authors if author.email()] + cc_addrs = None + if draft.group.acronym != 'none': + cc_addrs = [chair.person.email() for chair in WGChair.objects.filter(group_acronym=draft.group)] + + #For development debugging + """ + print "filename: "+draft.filename + print "to: ", to_addrs + print "cc: ", cc_addrs + print "expires: ", expiration + print "status: ", draft.status.status, "/", draft.idstate() + print + continue + """ + + send_mail_subj(None, to_addrs, None, 'notify_expirations/subject.txt', 'notify_expirations/body.txt', + { + 'draft':draft, + 'expiration':expiration, + }, + cc_addrs) diff --git a/ietf/templates/notify_expirations/body.txt b/ietf/templates/notify_expirations/body.txt new file mode 100644 index 000000000..bc07899a7 --- /dev/null +++ b/ietf/templates/notify_expirations/body.txt @@ -0,0 +1,6 @@ +The following draft will expire soon: + +Filename: {{draft.filename}} +Title: {{draft.title}} +State: {{draft.idstate}} +Expires: {{expiration}} (in {{expiration|timeuntil}}) diff --git a/ietf/templates/notify_expirations/subject.txt b/ietf/templates/notify_expirations/subject.txt new file mode 100644 index 000000000..7cb09c178 --- /dev/null +++ b/ietf/templates/notify_expirations/subject.txt @@ -0,0 +1 @@ +Expiration impending: {{draft.filename}} diff --git a/ietf/utils/mail.py b/ietf/utils/mail.py index ca1b78d35..d570a3078 100644 --- a/ietf/utils/mail.py +++ b/ietf/utils/mail.py @@ -8,7 +8,7 @@ import smtplib from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django.template.loader import render_to_string -from django.template import RequestContext +from django.template import Context,RequestContext from ietf.utils import log import sys import time @@ -95,12 +95,18 @@ def copy_email(msg, to, toUser=False): new['To'] = to send_smtp(new) +def mail_context(request): + if request: + return RequestContext(request) + else: + return Context() + def send_mail_subj(request, to, frm, stemplate, template, context, *args, **kwargs): ''' Send an email message, exactly as send_mail(), but the subject field is a template. ''' - subject = render_to_string(stemplate, context, context_instance=RequestContext(request)).replace("\n"," ").strip() + subject = render_to_string(stemplate, context, context_instance=mail_context(request)).replace("\n"," ").strip() return send_mail(request, to, frm, subject, template, context, *args, **kwargs) def send_mail(request, to, frm, subject, template, context, *args, **kwargs): @@ -110,7 +116,7 @@ def send_mail(request, to, frm, subject, template, context, *args, **kwargs): The body is a text/plain rendering of the template with the context. extra is a dict of extra headers to add. ''' - txt = render_to_string(template, context, context_instance=RequestContext(request)) + txt = render_to_string(template, context, context_instance=mail_context(request)) return send_mail_text(request, to, frm, subject, txt, *args, **kwargs) def send_mail_text(request, to, frm, subject, txt, cc=None, extra=None, toUser=None, bcc=None):