Skip to content

Commit 5d291f2

Browse files
committed
Remove .state and .*_state on Document in favour of generic states
mapping, port the codebase to use these states - Legacy-Id: 3660
1 parent 64c3ef0 commit 5d291f2

34 files changed

Lines changed: 702 additions & 637 deletions

ietf/idrfc/expire.py

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
from django.template.loader import render_to_string
55
from django.db.models import Q
66

7-
import datetime, os, shutil, glob, re
7+
import datetime, os, shutil, glob, re, itertools
88

99
from ietf.idtracker.models import InternetDraft, IDDates, IDStatus, IDState, DocumentComment, IDAuthor,WGChair
1010
from ietf.utils.mail import send_mail, send_mail_subj
1111
from ietf.idrfc.utils import log_state_changed, add_document_comment
12-
from doc.models import Document, DocEvent, save_document_in_history
13-
from name.models import IesgDocStateName, DocStateName, DocTagName
14-
from person.models import Person, Email
12+
from redesign.doc.models import Document, DocEvent, save_document_in_history, State
13+
from redesign.name.models import DocTagName
14+
from redesign.person.models import Person, Email
1515

1616
INTERNET_DRAFT_DAYS_TO_EXPIRE = 185
1717

@@ -36,7 +36,11 @@ def document_expires(doc):
3636
return None
3737

3838
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))
39+
d = Document.objects.filter(states__type="draft", states__slug="active").exclude(tags="rfc-rev")
40+
# we need to get those that either don't have a state or have a
41+
# state >= 42 (AD watching), unfortunately that doesn't appear to
42+
# be possible to get to work directly in Django 1.1
43+
return itertools.chain(d.exclude(states__type="draft-iesg").distinct(), d.filter(states__type="draft-iesg", states__order__gte=42).distinct())
4044

4145
def get_soon_to_expire_ids(days):
4246
start_date = datetime.date.today() - datetime.timedelta(InternetDraft.DAYS_TO_EXPIRE - 1)
@@ -104,7 +108,8 @@ def send_expire_warning_for_idREDESIGN(doc):
104108
if doc.group.type_id != "individ":
105109
cc = [e.formatted_email() for e in Email.objects.filter(role__group=doc.group, role__name="chair") if not e.address.startswith("unknown-email")]
106110

107-
state = doc.iesg_state.name if doc.iesg_state else "I-D Exists"
111+
s = doc.get_state("draft-iesg")
112+
state = s.name if s else "I-D Exists"
108113

109114
frm = None
110115
request = None
@@ -138,8 +143,9 @@ def send_expire_notice_for_idREDESIGN(doc):
138143
if not doc.ad:
139144
return
140145

141-
state = doc.iesg_state.name if doc.iesg_state else "I-D Exists"
142-
146+
s = doc.get_state("draft-iesg")
147+
state = s.name if s else "I-D Exists"
148+
143149
request = None
144150
to = doc.ad.formatted_email()
145151
send_mail(request, to,
@@ -216,10 +222,10 @@ def move_file(f):
216222

217223
save_document_in_history(doc)
218224
if doc.latest_event(type='started_iesg_process'):
219-
dead_state = IesgDocStateName.objects.get(slug="dead")
220-
if doc.iesg_state != dead_state:
221-
prev = doc.iesg_state
222-
doc.iesg_state = dead_state
225+
dead_state = State.objects.get(type="draft-iesg", slug="dead")
226+
prev = doc.get_state("draft-iesg")
227+
if prev != dead_state:
228+
doc.set_state(dead_state)
223229
log_state_changed(None, doc, system, prev)
224230

225231
e = DocEvent(doc=doc, by=system)
@@ -228,7 +234,7 @@ def move_file(f):
228234
e.save()
229235

230236
doc.rev = new_revision # FIXME: incrementing the revision like this is messed up
231-
doc.state = DocStateName.objects.get(slug="expired")
237+
doc.set_state(State.objects.get(type="draft", slug="expired"))
232238
doc.time = datetime.datetime.now()
233239
doc.save()
234240

@@ -334,10 +340,10 @@ def move_file_to(subdir):
334340
try:
335341
doc = Document.objects.get(name=filename, rev=revision)
336342

337-
if doc.state_id == "rfc":
343+
if doc.get_state_slug() == "rfc":
338344
if ext != ".txt":
339345
move_file_to("unknown_ids")
340-
elif doc.state_id in ("expired", "auth-rm", "repl", "ietf-rm"):
346+
elif doc.get_state_slug() in ("expired", "repl", "auth-rm", "ietf-rm"):
341347
e = doc.latest_event(type__in=('expired_document', 'new_revision', "completed_resurrect"))
342348
expiration_date = e.time.date() if e and e.type == "expired_document" else None
343349

ietf/idrfc/idrfc_wrapper.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,11 +121,11 @@ def __init__(self, draft):
121121

122122
def rfc_editor_state(self):
123123
if settings.USE_DB_REDESIGN_PROXY_CLASSES:
124-
if self._draft.rfc_state:
124+
s = self._draft.get_state("draft-rfceditor")
125+
if s:
125126
# extract possible extra states
126127
tags = self._draft.tags.filter(slug__in=("iana-crd", "ref", "missref"))
127-
s = [self._draft.rfc_state.name] + [t.slug.replace("-crd", "").upper() for t in tags]
128-
return " ".join(s)
128+
return " ".join([s.name] + [t.slug.replace("-crd", "").upper() for t in tags])
129129
else:
130130
return None
131131

ietf/idrfc/lastcall.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@
88
from ietf.idrfc.mails import *
99
from ietf.idrfc.utils import *
1010

11-
from doc.models import Document, DocEvent, LastCallDocEvent, WriteupDocEvent, save_document_in_history
12-
from name.models import IesgDocStateName
11+
from doc.models import Document, DocEvent, LastCallDocEvent, WriteupDocEvent, save_document_in_history, State
1312
from person.models import Person
1413

1514
def request_last_call(request, doc):
@@ -47,7 +46,7 @@ def get_expired_last_calls():
4746

4847
def get_expired_last_callsREDESIGN():
4948
today = datetime.date.today()
50-
for d in Document.objects.filter(iesg_state="lc"):
49+
for d in Document.objects.filter(states__type="draft-iesg", states__slug="lc"):
5150
e = d.latest_event(LastCallDocEvent, type="sent_last_call")
5251
if e and e.expires.date() <= today:
5352
yield d
@@ -71,18 +70,18 @@ def expire_last_call(doc):
7170
email_last_call_expired(doc)
7271

7372
def expire_last_callREDESIGN(doc):
74-
state = IesgDocStateName.objects.get(slug="writeupw")
73+
state = State.objects.get(type="draft-iesg", slug="writeupw")
7574

7675
e = doc.latest_event(WriteupDocEvent, type="changed_ballot_writeup_text")
7776
if e and "What does this protocol do and why" not in e.text:
78-
# if it boiler-plate text has been removed, we assume the
77+
# if boiler-plate text has been removed, we assume the
7978
# write-up has been written
80-
state = IesgDocStateName.objects.get(slug="goaheadw")
79+
state = State.objects.get(type="draft-iesg", slug="goaheadw")
8180

8281
save_document_in_history(doc)
8382

84-
prev = doc.iesg_state
85-
doc.iesg_state = state
83+
prev = doc.get_state("draft-iesg")
84+
doc.set_state(state)
8685
e = log_state_changed(None, doc, Person.objects.get(name="(System)"), prev)
8786

8887
doc.time = e.time

ietf/idrfc/mails.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def generate_approval_mail_rfc_editor(request, doc):
269269
DO_NOT_PUBLISH_IESG_STATES = ("nopubadw", "nopubanw")
270270

271271
def generate_approval_mailREDESIGN(request, doc):
272-
if doc.iesg_state_id in DO_NOT_PUBLISH_IESG_STATES or doc.tags.filter(slug='via-rfc'):
272+
if doc.get_state_slug("draft-iesg") in DO_NOT_PUBLISH_IESG_STATES or doc.tags.filter(slug='via-rfc'):
273273
mail = generate_approval_mail_rfc_editor(request, doc)
274274
else:
275275
mail = generate_approval_mail_approved(request, doc)
@@ -320,7 +320,7 @@ def generate_approval_mail_approved(request, doc):
320320
else:
321321
contacts = "The IESG contact person is %s." % director.name
322322

323-
doc_type = "RFC" if doc.state_id == "rfc" else "Internet Draft"
323+
doc_type = "RFC" if doc.get_state_slug() == "rfc" else "Internet Draft"
324324

325325
return render_to_string("idrfc/approval_mail.txt",
326326
dict(doc=doc,
@@ -338,8 +338,8 @@ def generate_approval_mail_approved(request, doc):
338338
def generate_approval_mail_rfc_editorREDESIGN(request, doc):
339339
full_status = full_intended_status(doc.intended_std_level.name)
340340
status = full_status.replace("a ", "").replace("an ", "")
341-
disapproved = doc.iesg_state_id in DO_NOT_PUBLISH_IESG_STATES
342-
doc_type = "RFC" if doc.state_id == "rfc" else "Internet Draft"
341+
disapproved = doc.get_state_slug("draft-iesg") in DO_NOT_PUBLISH_IESG_STATES
342+
doc_type = "RFC" if doc.get_state_slug() == "rfc" else "Internet Draft"
343343

344344
return render_to_string("idrfc/approval_mail_rfc_editor.txt",
345345
dict(doc=doc,
@@ -619,7 +619,7 @@ def email_last_call_expired(doc):
619619
cc="iesg-secretary@ietf.org")
620620

621621
def email_last_call_expiredREDESIGN(doc):
622-
text = "IETF Last Call has ended, and the state has been changed to\n%s." % doc.iesg_state.name
622+
text = "IETF Last Call has ended, and the state has been changed to\n%s." % doc.get_state("draft-iesg").name
623623

624624
send_mail(None,
625625
"iesg@ietf.org",

ietf/idrfc/mirror_rfc_editor_queue.py

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ def insert_into_database(drafts, refs):
197197

198198
def get_rfc_tag_mapping():
199199
"""Return dict with RFC Editor state name -> DocTagName"""
200-
from name.models import DocTagName
201-
from name.utils import name
200+
from redesign.name.models import DocTagName
201+
from redesign.name.utils import name
202202

203203
return {
204204
'IANA': name(DocTagName, 'iana-crd', 'IANA coordination', "RFC-Editor/IANA Registration Coordination"),
@@ -207,22 +207,21 @@ def get_rfc_tag_mapping():
207207
}
208208

209209
def get_rfc_state_mapping():
210-
"""Return dict with RFC Editor state name -> RfcDocStateName"""
211-
from name.models import RfcDocStateName
212-
from name.utils import name
213-
210+
"""Return dict with RFC Editor state name -> State"""
211+
from redesign.doc.models import State, StateType
212+
t = StateType.objects.get(slug="draft-rfceditor")
214213
return {
215-
'AUTH': name(RfcDocStateName, 'auth', 'AUTH', "Awaiting author action"),
216-
'AUTH48': name(RfcDocStateName, 'auth48', "AUTH48", "Awaiting final author approval"),
217-
'EDIT': name(RfcDocStateName, 'edit', 'EDIT', "Approved by the stream manager (e.g., IESG, IAB, IRSG, ISE), awaiting processing and publishing"),
218-
'IANA': name(RfcDocStateName, 'iana-crd', 'IANA', "RFC-Editor/IANA Registration Coordination"),
219-
'IESG': name(RfcDocStateName, 'iesg', 'IESG', "Holding for IESG action"),
220-
'ISR': name(RfcDocStateName, 'isr', 'ISR', "Independent Submission Review by the ISE "),
221-
'ISR-AUTH': name(RfcDocStateName, 'isr-auth', 'ISR-AUTH', "Independent Submission awaiting author update, or in discussion between author and ISE"),
222-
'REF': name(RfcDocStateName, 'ref', 'REF', "Holding for normative reference"),
223-
'RFC-EDITOR': name(RfcDocStateName, 'rfc-edit', 'RFC-EDITOR', "Awaiting final RFC Editor review before AUTH48"),
224-
'TO': name(RfcDocStateName, 'timeout', 'TO', "Time-out period during which the IESG reviews document for conflict/concurrence with other IETF working group work"),
225-
'MISSREF': name(RfcDocStateName, 'missref', 'MISSREF', "Awaiting missing normative reference"),
214+
'AUTH': State.objects.get_or_create(type=t, slug='auth', name='AUTH', desc="Awaiting author action")[0],
215+
'AUTH48': State.objects.get_or_create(type=t, slug='auth48', name="AUTH48", desc="Awaiting final author approval")[0],
216+
'EDIT': State.objects.get_or_create(type=t, slug='edit', name='EDIT', desc="Approved by the stream manager (e.g., IESG, IAB, IRSG, ISE), awaiting processing and publishing")[0],
217+
'IANA': State.objects.get_or_create(type=t, slug='iana-crd', name='IANA', desc="RFC-Editor/IANA Registration Coordination")[0],
218+
'IESG': State.objects.get_or_create(type=t, slug='iesg', name='IESG', desc="Holding for IESG action")[0],
219+
'ISR': State.objects.get_or_create(type=t, slug='isr', name='ISR', desc="Independent Submission Review by the ISE ")[0],
220+
'ISR-AUTH': State.objects.get_or_create(type=t, slug='isr-auth', name='ISR-AUTH', desc="Independent Submission awaiting author update, or in discussion between author and ISE")[0],
221+
'REF': State.objects.get_or_create(type=t, slug='ref', name='REF', desc="Holding for normative reference")[0],
222+
'RFC-EDITOR': State.objects.get_or_create(type=t, slug='rfc-edit', name='RFC-EDITOR', desc="Awaiting final RFC Editor review before AUTH48")[0],
223+
'TO': State.objects.get_or_create(type=t, slug='timeout', name='TO', desc="Time-out period during which the IESG reviews document for conflict/concurrence with other IETF working group work")[0],
224+
'MISSREF': State.objects.get_or_create(type=t, slug='missref', name='MISSREF', desc="Awaiting missing normative reference")[0],
226225
}
227226

228227

@@ -237,10 +236,9 @@ def insert_into_databaseREDESIGN(drafts, refs):
237236
rfc_editor_tags = tags.values()
238237

239238
log("removing old data...")
240-
for d in Document.objects.exclude(rfc_state=None).filter(tags__in=rfc_editor_tags):
239+
for d in Document.objects.filter(states__type="draft-rfceditor").distinct():
241240
d.tags.remove(*rfc_editor_tags)
242-
243-
Document.objects.exclude(rfc_state=None).update(rfc_state=None)
241+
d.unset_state("draft-rfceditor")
244242

245243
log("inserting new data...")
246244

@@ -254,8 +252,7 @@ def insert_into_databaseREDESIGN(drafts, refs):
254252
s = state.split(" ")
255253
if s:
256254
# first is state
257-
d.rfc_state = states[s[0]]
258-
d.save()
255+
d.set_state(states[s[0]])
259256

260257
# remainding are tags
261258
for x in s[1:]:

ietf/idrfc/mirror_rfc_index.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,11 @@ def get_stream_mapping():
178178

179179
@django.db.transaction.commit_on_success
180180
def insert_to_databaseREDESIGN(data):
181-
from person.models import Person
182-
from doc.models import Document, DocAlias, DocEvent, RelatedDocument
183-
from group.models import Group
184-
from name.models import DocTagName, DocRelationshipName
185-
from name.utils import name
181+
from redesign.person.models import Person
182+
from redesign.doc.models import Document, DocAlias, DocEvent, RelatedDocument, State
183+
from redesign.group.models import Group
184+
from redesign.name.models import DocTagName, DocRelationshipName
185+
from redesign.name.utils import name
186186

187187
system = Person.objects.get(name="(System)")
188188
std_level_mapping = get_std_level_mapping()
@@ -242,8 +242,8 @@ def insert_to_databaseREDESIGN(data):
242242
doc.std_level = std_level_mapping[current_status]
243243
changed = True
244244

245-
if doc.state_id != "rfc":
246-
doc.state_id = "rfc"
245+
if doc.get_state_slug() != "rfc":
246+
doc.set_state(State.objects.filter(type="draft", slug="rfc"))
247247
changed = True
248248

249249
if doc.stream != stream_mapping[stream]:

0 commit comments

Comments
 (0)