66
77import datetime , os , shutil , glob , re
88
9- from ietf .idtracker .models import InternetDraft , IDDates , IDStatus , IDState , DocumentComment
10- from ietf .utils .mail import send_mail
9+ from ietf .idtracker .models import InternetDraft , IDDates , IDStatus , IDState , DocumentComment , IDAuthor , WGChair
10+ from ietf .utils .mail import send_mail , send_mail_subj
1111from ietf .idrfc .utils import log_state_changed , add_document_comment
1212from doc .models import Document , Event , save_document_in_history
1313from name .models import IesgDocStateName , DocStateName , DocInfoTagName
@@ -28,6 +28,33 @@ def in_id_expire_freeze(when=None):
2828
2929 return second_cut_off <= when < ietf_monday
3030
31+ def document_expires (doc ):
32+ e = doc .latest_event (type__in = ("completed_resurrect" , "new_revision" ))
33+ if e :
34+ return e .time + datetime .timedelta (days = INTERNET_DRAFT_DAYS_TO_EXPIRE )
35+ else :
36+ return None
37+
38+ def expirable_documents ():
39+ return Document .objects .filter (state = "active" ).exclude (tags = "rfc-rev" ).filter (Q (iesg_state = None ) | Q (iesg_state__order__gte = 42 ))
40+
41+ def get_soon_to_expire_ids (days ):
42+ start_date = datetime .date .today () - datetime .timedelta (InternetDraft .DAYS_TO_EXPIRE - 1 )
43+ end_date = start_date + datetime .timedelta (days - 1 )
44+
45+ for d in InternetDraft .objects .filter (revision_date__gte = start_date ,revision_date__lte = end_date ,status__status = 'Active' ):
46+ if d .can_expire ():
47+ yield d
48+
49+ def get_soon_to_expire_idsREDESIGN (days ):
50+ start_date = datetime .date .today () - datetime .timedelta (1 )
51+ end_date = start_date + datetime .timedelta (days - 1 )
52+
53+ for d in expirable_documents ():
54+ e = document_expires (d )
55+ if e and start_date <= e .date () <= end_date :
56+ yield d
57+
3158def get_expired_ids ():
3259 cut_off = datetime .date .today () - datetime .timedelta (days = InternetDraft .DAYS_TO_EXPIRE )
3360
@@ -38,14 +65,59 @@ def get_expired_ids():
3865 Q (idinternal = None ) | Q (idinternal__cur_state__document_state_id__gte = 42 ))
3966
4067def get_expired_idsREDESIGN ():
41- cut_off = datetime .date .today () - datetime . timedelta ( days = INTERNET_DRAFT_DAYS_TO_EXPIRE )
68+ today = datetime .date .today ()
4269
43- docs = Document .objects .filter (state = "active" ).exclude (tags = "rfc-rev" ).filter (Q (iesg_state = None ) | Q (iesg_state__order__gte = 42 ))
44- for d in docs :
45- e = d .latest_event (type = "new_revision" )
46- if e and e .time .date () <= cut_off :
70+ for d in expirable_documents ():
71+ e = document_expires (d )
72+ if e and e .time .date () <= today :
4773 yield d
4874
75+ def send_expire_warning_for_id (doc ):
76+ expiration = doc .expiration ()
77+ # Todo:
78+ #second_cutoff = IDDates.objects.get(date_id=2)
79+ #ietf_monday = IDDates.objects.get(date_id=3)
80+ #freeze_delta = ietf_monday - second_cutoff
81+ # # The I-D expiration job doesn't run while submissions are frozen.
82+ # if ietf_monday > expiration > second_cutoff:
83+ # expiration += freeze_delta
84+
85+ authors = doc .authors .all ()
86+ to_addrs = [author .email () for author in authors if author .email ()]
87+ cc_addrs = None
88+ if doc .group .acronym != 'none' :
89+ cc_addrs = [chair .person .email () for chair in WGChair .objects .filter (group_acronym = doc .group )]
90+
91+ if to_addrs or cc_addrs :
92+ send_mail_subj (None , to_addrs , None , 'notify_expirations/subject.txt' , 'notify_expirations/body.txt' ,
93+ {
94+ 'draft' :doc ,
95+ 'expiration' :expiration ,
96+ },
97+ cc_addrs )
98+
99+ def send_expire_warning_for_idREDESIGN (doc ):
100+ expiration = document_expires (doc ).date ()
101+
102+ to = [e .formatted_email () for e in doc .authors .all () if not e .address .startswith ("unknown-email" )]
103+ cc = None
104+ if doc .group .type_id != "individ" :
105+ cc = [e .formatted_email () for e in Email .objects .filter (role__group = doc .group , role__name = "chair" ) if not e .address .startswith ("unknown-email" )]
106+
107+ state = doc .iesg_state .name if doc .iesg_state else "I-D Exists"
108+
109+ frm = None
110+ request = None
111+ if to or cc :
112+ send_mail (request , to , frm ,
113+ u"Expiration impending: %s" % doc .file_tag (),
114+ "idrfc/expire_warning_email.txt" ,
115+ dict (doc = doc ,
116+ state = state ,
117+ expiration = expiration
118+ ),
119+ cc = cc )
120+
49121def send_expire_notice_for_id (doc ):
50122 doc .dunn_sent_date = datetime .date .today ()
51123 doc .save ()
@@ -242,7 +314,9 @@ def move_file_to(subdir):
242314 move_file_to ("unknown_ids" )
243315
244316if settings .USE_DB_REDESIGN_PROXY_CLASSES :
317+ get_soon_to_expire_ids = get_soon_to_expire_idsREDESIGN
245318 get_expired_ids = get_expired_idsREDESIGN
319+ send_expire_warning_for_id = send_expire_warning_for_idREDESIGN
246320 send_expire_notice_for_id = send_expire_notice_for_idREDESIGN
247321 expire_id = expire_idREDESIGN
248322 clean_up_id_files = clean_up_id_filesREDESIGN
0 commit comments