Skip to content

Commit 87ca10d

Browse files
committed
Remove usage of log_state_changed (and duplicate in
doc/utils_charter.py) in favour of add_state_change_event which has slightly better API but otherwise does basically the same except it sets an event type we can later search for. Also expand tests slightly to exercise three more templates. - Legacy-Id: 7129
1 parent 6b2d50d commit 87ca10d

14 files changed

Lines changed: 173 additions & 174 deletions

ietf/doc/expire.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from ietf.doc.models import Document, DocEvent, State, save_document_in_history, IESG_SUBSTATE_TAGS
1111
from ietf.person.models import Person, Email
1212
from ietf.meeting.models import Meeting
13-
from ietf.doc.utils import log_state_changed
13+
from ietf.doc.utils import add_state_change_event
1414

1515
def expirable_draft(draft):
1616
"""Return whether draft is in an expirable state or not. This is
@@ -122,20 +122,18 @@ def expire_draft(doc):
122122
# clean up files
123123
move_draft_files_to_archive(doc, doc.rev)
124124

125-
# change the state
126125
system = Person.objects.get(name="(System)")
127126

127+
# change the state
128128
save_document_in_history(doc)
129129
if doc.latest_event(type='started_iesg_process'):
130-
dead_state = State.objects.get(used=True, type="draft-iesg", slug="dead")
131-
prev_state = doc.friendly_state()
132-
prev_tag = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
133-
prev_tag = prev_tag[0] if prev_tag else None
134-
if doc.get_state("draft-iesg") != dead_state:
135-
doc.set_state(dead_state)
136-
if prev_tag:
137-
doc.tags.remove(prev_tag)
138-
log_state_changed(None, doc, system, doc.friendly_state(), prev_state)
130+
new_state = State.objects.get(used=True, type="draft-iesg", slug="dead")
131+
prev_state = doc.get_state(new_state.type_id)
132+
prev_tags = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
133+
if new_state != prev_state:
134+
doc.set_state(new_state)
135+
doc.tags.remove(*prev_tags)
136+
e = add_state_change_event(doc, system, prev_state, new_state, prev_tags=prev_tags, new_tags=[])
139137

140138
e = DocEvent(doc=doc, by=system)
141139
e.type = "expired_document"

ietf/doc/lastcall.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from ietf.doc.models import *
88
from ietf.person.models import Person
9-
from ietf.doc.utils import log_state_changed
9+
from ietf.doc.utils import add_state_change_event
1010
from ietf.doc.mails import *
1111

1212
def request_last_call(request, doc):
@@ -36,30 +36,27 @@ def get_expired_last_calls():
3636

3737
def expire_last_call(doc):
3838
if doc.type_id == 'draft':
39-
state = State.objects.get(used=True, type="draft-iesg", slug="writeupw")
39+
new_state = State.objects.get(used=True, type="draft-iesg", slug="writeupw")
4040
e = doc.latest_event(WriteupDocEvent, type="changed_ballot_writeup_text")
4141
if e and "Relevant content can frequently be found in the abstract" not in e.text:
4242
# if boiler-plate text has been removed, we assume the
4343
# write-up has been written
44-
state = State.objects.get(used=True, type="draft-iesg", slug="goaheadw")
45-
prev = doc.get_state("draft-iesg")
44+
new_state = State.objects.get(used=True, type="draft-iesg", slug="goaheadw")
4645
elif doc.type_id == 'statchg':
47-
state = State.objects.get(used=True, type="statchg", slug="goahead")
48-
prev = doc.get_state("statchg")
46+
new_state = State.objects.get(used=True, type="statchg", slug="goahead")
4947
else:
5048
raise ValueError("Unexpected document type to expire_last_call(): %s" % doc.type)
5149

52-
prev_state = doc.friendly_state()
53-
5450
save_document_in_history(doc)
55-
doc.set_state(state)
5651

57-
prev_tag = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
58-
prev_tag = prev_tag[0] if prev_tag else None
59-
if prev_tag:
60-
doc.tags.remove(prev_tag)
52+
prev_state = doc.get_state(new_state.type_id)
53+
doc.set_state(new_state)
54+
55+
prev_tags = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
56+
doc.tags.remove(*prev_tags)
6157

62-
e = log_state_changed(None, doc, Person.objects.get(name="(System)"), doc.friendly_state(), prev_state)
58+
system = Person.objects.get(name="(System)")
59+
e = add_state_change_event(doc, system, prev_state, new_state, prev_tags=prev_tags, new_tags=[])
6360

6461
doc.time = e.time
6562
doc.save()

ietf/doc/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def friendly_state(self):
392392
# Expired/Withdrawn by Submitter/IETF
393393
return state.name
394394
else:
395-
return state.name
395+
return state.name
396396

397397
def ipr(self):
398398
"""Returns the IPR disclosures against this document (as a queryset over IprDocAlias)."""

ietf/doc/tests_charter.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def test_startstop_process(self):
5151
if option == "abandon":
5252
self.assertTrue("abandoned" in charter.latest_event(type="changed_document").desc.lower())
5353
else:
54-
self.assertTrue("state changed" in charter.latest_event(type="changed_document").desc.lower())
54+
self.assertTrue("state changed" in charter.latest_event(type="changed_state").desc.lower())
5555

5656
def test_change_state(self):
5757
make_test_data()
@@ -94,7 +94,7 @@ def test_change_state(self):
9494
def find_event(t):
9595
return [e for e in charter.docevent_set.all()[:events_now - events_before] if e.type == t]
9696

97-
self.assertTrue("state changed" in find_event("changed_document")[0].desc.lower())
97+
self.assertTrue("state changed" in find_event("changed_state")[0].desc.lower())
9898

9999
if slug in ("intrev", "iesgrev"):
100100
self.assertTrue(find_event("created_ballot"))
@@ -111,6 +111,10 @@ def test_edit_telechat_date(self):
111111
url = urlreverse('charter_telechat_date', kwargs=dict(name=charter.name))
112112
login_testing_unauthorized(self, "secretary", url)
113113

114+
# get
115+
r = self.client.get(url)
116+
self.assertEqual(r.status_code, 200)
117+
114118
# add to telechat
115119
self.assertTrue(not charter.latest_event(TelechatDocEvent, "scheduled_for_telechat"))
116120
telechat_date = TelechatDate.objects.active()[0].date
@@ -145,6 +149,10 @@ def test_edit_notify(self):
145149
url = urlreverse('charter_edit_notify', kwargs=dict(name=charter.name))
146150
login_testing_unauthorized(self, "secretary", url)
147151

152+
# get
153+
r = self.client.get(url)
154+
self.assertEqual(r.status_code, 200)
155+
148156
# post
149157
self.assertTrue(not charter.notify)
150158
r = self.client.post(url, dict(notify="someone@example.com, someoneelse@example.com"))

ietf/doc/tests_draft.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def test_change_state(self):
6767
self.assertTrue(draft.tags.filter(slug="point"))
6868
self.assertEqual(draft.docevent_set.count(), events_before + 2)
6969
self.assertTrue("Test comment" in draft.docevent_set.all()[0].desc)
70-
self.assertTrue("State changed" in draft.docevent_set.all()[1].desc)
70+
self.assertTrue("IESG state changed" in draft.docevent_set.all()[1].desc)
7171
self.assertEqual(len(outbox), mailbox_before + 2)
7272
self.assertTrue("State Update Notice" in outbox[-2]['Subject'])
7373
self.assertTrue(draft.name in outbox[-1]['Subject'])
@@ -232,6 +232,10 @@ def test_edit_telechat_date(self):
232232
note="",
233233
)
234234

235+
# get
236+
r = self.client.get(url)
237+
self.assertEqual(r.status_code, 200)
238+
235239
# add to telechat
236240
self.assertTrue(not draft.latest_event(TelechatDocEvent, type="scheduled_for_telechat"))
237241
data["telechat_date"] = TelechatDate.objects.active()[0].date.isoformat()
@@ -347,6 +351,11 @@ def test_edit_consensus(self):
347351
url = urlreverse('doc_edit_consensus', kwargs=dict(name=draft.name))
348352
login_testing_unauthorized(self, "secretary", url)
349353

354+
# get
355+
r = self.client.get(url)
356+
self.assertEqual(r.status_code, 200)
357+
358+
# post
350359
self.assertTrue(not draft.latest_event(ConsensusDocEvent, type="changed_consensus"))
351360
r = self.client.post(url, dict(consensus="Yes"))
352361
self.assertEqual(r.status_code, 302)

ietf/doc/utils.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -220,25 +220,24 @@ def get_document_content(key, filename, split=True, markup=True):
220220
else:
221221
return raw_content
222222

223-
def log_state_changed(request, doc, by, new_description, old_description):
224-
e = DocEvent(doc=doc, by=by)
225-
e.type = "changed_document"
226-
e.desc = u"State changed to <b>%s</b> from %s" % (new_description, old_description)
227-
e.save()
228-
return e
229-
230-
def add_state_change_event(doc, by, prev_state, new_state, timestamp=None):
223+
def add_state_change_event(doc, by, prev_state, new_state, prev_tags=[], new_tags=[], timestamp=None):
231224
"""Add doc event to explain that state change just happened."""
232-
if prev_state == new_state:
225+
if prev_state and new_state:
226+
assert prev_state.type_id == new_state.type_id
227+
228+
if prev_state == new_state and set(prev_tags) == set(new_tags):
233229
return None
234230

231+
def tags_suffix(tags):
232+
return (u"::" + u"::".join(t.name for t in tags)) if tags else u""
233+
235234
e = StateDocEvent(doc=doc, by=by)
236235
e.type = "changed_state"
237236
e.state_type = (prev_state or new_state).type
238237
e.state = new_state
239-
e.desc = "%s changed to <b>%s</b>" % (e.state_type.label, new_state.name)
238+
e.desc = "%s changed to <b>%s</b>" % (e.state_type.label, new_state.name + tags_suffix(new_tags))
240239
if prev_state:
241-
e.desc += " from %s" % prev_state.name
240+
e.desc += " from %s" % (prev_state.name + tags_suffix(prev_tags))
242241
if timestamp:
243242
e.time = timestamp
244243
e.save()

ietf/doc/utils_charter.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,6 @@
1313
from ietf.utils.history import find_history_active_at
1414

1515

16-
def log_state_changed(request, doc, by, prev_state):
17-
e = DocEvent(doc=doc, by=by)
18-
e.type = "changed_document"
19-
e.desc = u"State changed to <b>%s</b> from %s" % (
20-
doc.get_state().name,
21-
prev_state.name if prev_state else "None")
22-
e.save()
23-
return e
24-
2516
def next_revision(rev):
2617
if rev == "":
2718
return "00-00"

ietf/doc/views_ballot.py

Lines changed: 54 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,21 @@ def do_undefer_ballot(request, doc):
4949
telechat_date = TelechatDate.objects.active().order_by("date")[0].date
5050
save_document_in_history(doc)
5151

52-
prev_state = doc.friendly_state()
52+
new_state = doc.get_state()
53+
prev_tags = new_tags = []
54+
5355
if doc.type_id == 'draft':
54-
doc.set_state(State.objects.get(used=True, type="draft-iesg", slug='iesg-eva'))
55-
prev_tag = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
56-
prev_tag = prev_tag[0] if prev_tag else None
57-
if prev_tag:
58-
doc.tags.remove(prev_tag)
56+
new_state = State.objects.get(used=True, type="draft-iesg", slug='iesg-eva')
57+
prev_tags = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
5958
elif doc.type_id == 'conflrev':
60-
doc.set_state(State.objects.get(used=True, type='conflrev',slug='iesgeval'))
59+
new_state = State.objects.get(used=True, type='conflrev',slug='iesgeval')
60+
61+
prev_state = doc.get_state(new_state.type_id if new_state else None)
6162

62-
e = log_state_changed(request, doc, login, doc.friendly_state(), prev_state)
63+
doc.set_state(new_state)
64+
doc.tags.remove(*prev_tags)
65+
66+
e = add_state_change_event(doc, login, prev_state, new_state, prev_tags=prev_tags, new_tags=new_tags)
6367

6468
doc.time = e.time
6569
doc.save()
@@ -353,17 +357,21 @@ def defer_ballot(request, name):
353357
if request.method == 'POST':
354358
save_document_in_history(doc)
355359

356-
prev_state = doc.friendly_state()
360+
new_state = doc.get_state()
361+
prev_tags = new_tags = []
362+
357363
if doc.type_id == 'draft':
358-
doc.set_state(State.objects.get(used=True, type="draft-iesg", slug='defer'))
359-
prev_tag = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
360-
prev_tag = prev_tag[0] if prev_tag else None
361-
if prev_tag:
362-
doc.tags.remove(prev_tag)
364+
new_state = State.objects.get(used=True, type="draft-iesg", slug='defer')
365+
prev_tags = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
363366
elif doc.type_id == 'conflrev':
364-
doc.set_state(State.objects.get(used=True, type='conflrev', slug='defer'))
367+
new_state = State.objects.get(used=True, type='conflrev', slug='defer')
368+
369+
prev_state = doc.get_state(new_state.type_id if new_state else None)
370+
371+
doc.set_state(new_state)
372+
doc.tags.remove(*prev_tags)
365373

366-
e = log_state_changed(request, doc, login, doc.friendly_state(), prev_state)
374+
e = add_state_change_event(doc, login, prev_state, new_state, prev_tags=prev_tags, new_tags=new_tags)
367375

368376
doc.time = e.time
369377
doc.save()
@@ -445,16 +453,16 @@ def lastcalltext(request, name):
445453
if "send_last_call_request" in request.POST:
446454
save_document_in_history(doc)
447455

448-
prev_state = doc.friendly_state()
449-
doc.set_state(State.objects.get(used=True, type="draft-iesg", slug='lc-req'))
456+
prev_state = doc.get_state("draft-iesg")
457+
new_state = State.objects.get(used=True, type="draft-iesg", slug='lc-req')
450458

451-
prev_tag = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
452-
prev_tag = prev_tag[0] if prev_tag else None
453-
if prev_tag:
454-
doc.tags.remove(prev_tag)
459+
prev_tags = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
460+
461+
doc.set_state(new_state)
462+
doc.tags.remove(*prev_tags)
463+
464+
e = add_state_change_event(doc, login, prev_state, new_state, prev_tags=prev_tags, new_tags=[])
455465

456-
e = log_state_changed(request, doc, login, doc.friendly_state(), prev_state)
457-
458466
doc.time = e.time
459467
doc.save()
460468

@@ -664,8 +672,9 @@ def approve_ballot(request, name):
664672
else:
665673
new_state = State.objects.get(used=True, type="draft-iesg", slug="ann")
666674

667-
prev_friendly_state = doc.friendly_state()
668675
prev_state = doc.get_state("draft-iesg")
676+
prev_tags = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
677+
669678
if new_state.slug == "ann" and new_state.slug != prev_state.slug and not request.REQUEST.get("skiprfceditorpost"):
670679
# start by notifying the RFC Editor
671680
import ietf.sync.rfceditor
@@ -677,18 +686,14 @@ def approve_ballot(request, name):
677686
error=error),
678687
context_instance=RequestContext(request))
679688

680-
# fixup document
681-
close_open_ballots(doc, login)
682-
683689
save_document_in_history(doc)
684690

685691
doc.set_state(new_state)
686-
687-
prev_tag = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
688-
prev_tag = prev_tag[0] if prev_tag else None
689-
if prev_tag:
690-
doc.tags.remove(prev_tag)
692+
doc.tags.remove(*prev_tags)
691693

694+
# fixup document
695+
close_open_ballots(doc, login)
696+
692697
e = DocEvent(doc=doc, by=login)
693698
if action == "do_not_publish":
694699
e.type = "iesg_disapproved"
@@ -701,8 +706,8 @@ def approve_ballot(request, name):
701706

702707
change_description = e.desc + " and state has been changed to %s" % doc.get_state("draft-iesg").name
703708

704-
e = log_state_changed(request, doc, login, doc.friendly_state(), prev_friendly_state)
705-
709+
e = add_state_change_event(doc, login, prev_state, new_state, prev_tags=prev_tags, new_tags=[])
710+
706711
doc.time = e.time
707712
doc.save()
708713

@@ -766,26 +771,27 @@ def make_last_call(request, name):
766771

767772
save_document_in_history(doc)
768773

769-
prev_state = doc.get_state("draft-iesg")
774+
new_state = doc.get_state()
775+
prev_tags = new_tags = []
776+
770777
if doc.type.slug == 'draft':
771-
doc.set_state(State.objects.get(used=True, type="draft-iesg", slug='lc'))
778+
new_state = State.objects.get(used=True, type="draft-iesg", slug='lc')
779+
prev_tags = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
780+
elif doc.type.slug == 'statchg':
781+
new_state = State.objects.get(used=True, type="statchg", slug='in-lc')
772782

773-
prev_tag = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
774-
prev_tag = prev_tag[0] if prev_tag else None
775-
if prev_tag:
776-
doc.tags.remove(prev_tag)
783+
prev_state = doc.get_state(new_state.type_id)
777784

778-
e = log_state_changed(request, doc, login, doc.friendly_state(), prev_state)
779-
change_description = "Last call has been made for %s and state has been changed to %s" % (doc.name, doc.get_state("draft-iesg").name)
785+
doc.set_state(new_state)
786+
doc.tags.remove(*prev_tags)
787+
788+
e = add_state_change_event(doc, login, prev_state, new_state, prev_tags=prev_tags, new_tags=new_tags)
780789

781-
elif doc.type.slug == 'statchg':
782-
doc.set_state(State.objects.get(used=True, type="statchg", slug='in-lc'))
783-
e = log_state_changed(request, doc, login, doc.friendly_state(), prev_state)
784-
change_description = "Last call has been made for %s and state has been changed to %s" % (doc.name, doc.friendly_state())
785-
786790
doc.time = e.time
787791
doc.save()
788792

793+
change_description = "Last call has been made for %s and state has been changed to %s" % (doc.name, new_state.name)
794+
789795
email_state_changed(request, doc, change_description)
790796
email_ad(request, doc, doc.ad, login, change_description)
791797

0 commit comments

Comments
 (0)