88import datetime , os , shutil , glob , re
99from pathlib import Path
1010
11- from typing import List , Tuple # pyflakes:ignore
11+ from typing import List , Optional # pyflakes:ignore
1212
1313from ietf .utils import log
1414from ietf .utils .mail import send_mail
1919from ietf .mailtrigger .utils import gather_address_lists
2020
2121
22- def expirable_draft (draft ):
23- """Return whether draft is in an expirable state or not. This is
24- the single draft version of the logic in expirable_drafts. These
25- two functions need to be kept in sync."""
26- if draft .type_id != 'draft' :
27- return False
28- return bool (expirable_drafts (Document .objects .filter (pk = draft .pk )))
29-
30- nonexpirable_states = [] # type: List[State]
22+ nonexpirable_states : Optional [List [State ]] = None
3123
3224def expirable_drafts (queryset = None ):
3325 """Return a queryset with expirable drafts."""
@@ -39,31 +31,25 @@ def expirable_drafts(queryset=None):
3931 queryset = Document .objects .all ()
4032
4133 # Populate this first time through (but after django has been set up)
42- if nonexpirable_states == [] :
34+ if nonexpirable_states is None :
4335 # all IESG states except I-D Exists, AD Watching, and Dead block expiry
44- nonexpirable_states + = list (State .objects .filter (used = True , type = "draft-iesg" ).exclude (slug__in = ("idexists" ,"watching" , "dead" )))
36+ nonexpirable_states = list (State .objects .filter (used = True , type = "draft-iesg" ).exclude (slug__in = ("idexists" ,"watching" , "dead" )))
4537 # sent to RFC Editor and RFC Published block expiry (the latter
4638 # shouldn't be possible for an active draft, though)
4739 nonexpirable_states += list (State .objects .filter (used = True , type__in = ("draft-stream-iab" , "draft-stream-irtf" , "draft-stream-ise" ), slug__in = ("rfc-edit" , "pub" )))
4840 # other IRTF states that block expiration
4941 nonexpirable_states += list (State .objects .filter (used = True , type_id = "draft-stream-irtf" , slug__in = ("irsgpoll" , "iesg-rev" ,)))
5042
51- d = queryset .filter (states__type = "draft" , states__slug = "active" )
52- if not d .exists ():
53- return d
54-
55- d = d .exclude (expires = None )
56- if not d .exists ():
57- return d
58-
59- d = d .exclude (states__in = nonexpirable_states )
60- if not d .exists ():
61- return d
62-
63- # under review by the RFC Editor blocks expiry
64- d = d .exclude (tags = "rfc-rev" )
43+ return queryset .filter (
44+ states__type = "draft" , states__slug = "active"
45+ ).exclude (
46+ expires = None
47+ ).exclude (
48+ states__in = nonexpirable_states
49+ ).exclude (
50+ tags = "rfc-rev" # under review by the RFC Editor blocks expiry
51+ ).distinct ()
6552
66- return d .distinct ()
6753
6854def get_soon_to_expire_drafts (days_of_warning ):
6955 start_date = datetime .date .today () - datetime .timedelta (1 )
0 commit comments