Merge the I-D notification work from my sprint branch.
- Legacy-Id: 2112
This commit is contained in:
parent
ec4b877e24
commit
3a45c8e560
|
@ -1,3 +1,11 @@
|
|||
ietfdb (2.46)
|
||||
|
||||
From Robert:
|
||||
|
||||
* Add the I-D expiration notification script.
|
||||
|
||||
-- Bill Fenner <fenner@fenron.net> 20 Mar 2010 12:59:50 -0800
|
||||
|
||||
ietfdb (2.45)
|
||||
|
||||
From Pasi:
|
||||
|
|
60
ietf/bin/notify-expirations
Executable file
60
ietf/bin/notify-expirations
Executable file
|
@ -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)
|
6
ietf/templates/notify_expirations/body.txt
Normal file
6
ietf/templates/notify_expirations/body.txt
Normal file
|
@ -0,0 +1,6 @@
|
|||
The following draft will expire soon:
|
||||
|
||||
Filename: {{draft.filename}}
|
||||
Title: {{draft.title}}
|
||||
State: {{draft.idstate}}
|
||||
Expires: {{expiration}} (in {{expiration|timeuntil}})
|
1
ietf/templates/notify_expirations/subject.txt
Normal file
1
ietf/templates/notify_expirations/subject.txt
Normal file
|
@ -0,0 +1 @@
|
|||
Expiration impending: {{draft.filename}}
|
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue