datatracker/ietf/doc/lastcall.py
Ole Laursen e1f0917659 Summary: Add new document saving API, Document.save_with_history(events).
The new API requires at least one event and will automatically save a
snapshot of the document and related state. Document.save() will now
throw an exception if called directly, as the new API is intended to
ensure that documents are saved with both an appropriate snapsnot and
relevant history log, both of which are easily defeated by just
calling .save() directly.

To simplify things, the snapshot is generated after the changes to a
document have been made (in anticipation of coming changes), instead
of before as was usual.

While revising the existing code to work with this API, a couple of
missing events was discovered:

- In draft expiry, a "Document has expired" event was only generated
  in case an IESG process had started on the document - now it's
  always generated, as the document changes its state in any case

- Synchronization updates like title and abstract amendmends from the
  RFC Editor were silently (except for RFC publication) applied and
  not accompanied by a descriptive event - they now are

- do_replace in the Secretariat tools now adds an event

- Proceedings post_process in the Secretariat tools now adds an event

- do_withdraw in the Secretariat tools now adds an event

A migration is needed for snapshotting all documents, takes a while to
run. It turns out that a single document had a bad foreign key so the
migration fixes that too.
 - Legacy-Id: 10101
2015-09-28 14:01:03 +00:00

64 lines
2.5 KiB
Python

# helpers for handling last calls on Internet Drafts
import datetime
from django.db.models import Q
from ietf.doc.models import Document, State, DocEvent, LastCallDocEvent, WriteupDocEvent
from ietf.doc.models import IESG_SUBSTATE_TAGS
from ietf.person.models import Person
from ietf.doc.utils import add_state_change_event
from ietf.doc.mails import generate_ballot_writeup, generate_approval_mail, generate_last_call_announcement
from ietf.doc.mails import send_last_call_request, email_last_call_expired
def request_last_call(request, doc):
if not doc.latest_event(type="changed_ballot_writeup_text"):
generate_ballot_writeup(request, doc)
if not doc.latest_event(type="changed_ballot_approval_text"):
generate_approval_mail(request, doc)
if not doc.latest_event(type="changed_last_call_text"):
generate_last_call_announcement(request, doc)
send_last_call_request(request, doc)
e = DocEvent()
e.type = "requested_last_call"
e.by = request.user.person
e.doc = doc
e.desc = "Last call was requested"
e.save()
def get_expired_last_calls():
today = datetime.date.today()
for d in Document.objects.filter(Q(states__type="draft-iesg", states__slug="lc")
| Q(states__type="statchg", states__slug="in-lc")):
e = d.latest_event(LastCallDocEvent, type="sent_last_call")
if e and e.expires.date() <= today:
yield d
def expire_last_call(doc):
if doc.type_id == 'draft':
new_state = State.objects.get(used=True, type="draft-iesg", slug="writeupw")
e = doc.latest_event(WriteupDocEvent, type="changed_ballot_writeup_text")
if e and "Relevant content can frequently be found in the abstract" not in e.text:
# if boiler-plate text has been removed, we assume the
# write-up has been written
new_state = State.objects.get(used=True, type="draft-iesg", slug="goaheadw")
elif doc.type_id == 'statchg':
new_state = State.objects.get(used=True, type="statchg", slug="goahead")
else:
raise ValueError("Unexpected document type to expire_last_call(): %s" % doc.type)
prev_state = doc.get_state(new_state.type_id)
doc.set_state(new_state)
prev_tags = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
doc.tags.remove(*prev_tags)
system = Person.objects.get(name="(System)")
e = add_state_change_event(doc, system, prev_state, new_state, prev_tags=prev_tags, new_tags=[])
if e:
doc.save_with_history([e])
email_last_call_expired(doc)