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
This commit is contained in:
Ole Laursen 2014-01-15 17:52:00 +00:00
parent 6b2d50db93
commit 87ca10d122
14 changed files with 179 additions and 180 deletions

View file

@ -10,7 +10,7 @@ from ietf.utils.mail import send_mail, send_mail_subj
from ietf.doc.models import Document, DocEvent, State, save_document_in_history, IESG_SUBSTATE_TAGS
from ietf.person.models import Person, Email
from ietf.meeting.models import Meeting
from ietf.doc.utils import log_state_changed
from ietf.doc.utils import add_state_change_event
def expirable_draft(draft):
"""Return whether draft is in an expirable state or not. This is
@ -122,20 +122,18 @@ def expire_draft(doc):
# clean up files
move_draft_files_to_archive(doc, doc.rev)
# change the state
system = Person.objects.get(name="(System)")
# change the state
save_document_in_history(doc)
if doc.latest_event(type='started_iesg_process'):
dead_state = State.objects.get(used=True, type="draft-iesg", slug="dead")
prev_state = doc.friendly_state()
prev_tag = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
prev_tag = prev_tag[0] if prev_tag else None
if doc.get_state("draft-iesg") != dead_state:
doc.set_state(dead_state)
if prev_tag:
doc.tags.remove(prev_tag)
log_state_changed(None, doc, system, doc.friendly_state(), prev_state)
new_state = State.objects.get(used=True, type="draft-iesg", slug="dead")
prev_state = doc.get_state(new_state.type_id)
prev_tags = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
if new_state != prev_state:
doc.set_state(new_state)
doc.tags.remove(*prev_tags)
e = add_state_change_event(doc, system, prev_state, new_state, prev_tags=prev_tags, new_tags=[])
e = DocEvent(doc=doc, by=system)
e.type = "expired_document"

View file

@ -6,7 +6,7 @@ from django.conf import settings
from ietf.doc.models import *
from ietf.person.models import Person
from ietf.doc.utils import log_state_changed
from ietf.doc.utils import add_state_change_event
from ietf.doc.mails import *
def request_last_call(request, doc):
@ -36,30 +36,27 @@ def get_expired_last_calls():
def expire_last_call(doc):
if doc.type_id == 'draft':
state = State.objects.get(used=True, type="draft-iesg", slug="writeupw")
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
state = State.objects.get(used=True, type="draft-iesg", slug="goaheadw")
prev = doc.get_state("draft-iesg")
new_state = State.objects.get(used=True, type="draft-iesg", slug="goaheadw")
elif doc.type_id == 'statchg':
state = State.objects.get(used=True, type="statchg", slug="goahead")
prev = doc.get_state("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.friendly_state()
save_document_in_history(doc)
doc.set_state(state)
prev_tag = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
prev_tag = prev_tag[0] if prev_tag else None
if prev_tag:
doc.tags.remove(prev_tag)
prev_state = doc.get_state(new_state.type_id)
doc.set_state(new_state)
e = log_state_changed(None, doc, Person.objects.get(name="(System)"), doc.friendly_state(), prev_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=[])
doc.time = e.time
doc.save()

View file

@ -392,7 +392,7 @@ class Document(DocumentInfo):
# Expired/Withdrawn by Submitter/IETF
return state.name
else:
return state.name
return state.name
def ipr(self):
"""Returns the IPR disclosures against this document (as a queryset over IprDocAlias)."""

View file

@ -51,7 +51,7 @@ class EditCharterTests(TestCase):
if option == "abandon":
self.assertTrue("abandoned" in charter.latest_event(type="changed_document").desc.lower())
else:
self.assertTrue("state changed" in charter.latest_event(type="changed_document").desc.lower())
self.assertTrue("state changed" in charter.latest_event(type="changed_state").desc.lower())
def test_change_state(self):
make_test_data()
@ -94,7 +94,7 @@ class EditCharterTests(TestCase):
def find_event(t):
return [e for e in charter.docevent_set.all()[:events_now - events_before] if e.type == t]
self.assertTrue("state changed" in find_event("changed_document")[0].desc.lower())
self.assertTrue("state changed" in find_event("changed_state")[0].desc.lower())
if slug in ("intrev", "iesgrev"):
self.assertTrue(find_event("created_ballot"))
@ -111,6 +111,10 @@ class EditCharterTests(TestCase):
url = urlreverse('charter_telechat_date', kwargs=dict(name=charter.name))
login_testing_unauthorized(self, "secretary", url)
# get
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
# add to telechat
self.assertTrue(not charter.latest_event(TelechatDocEvent, "scheduled_for_telechat"))
telechat_date = TelechatDate.objects.active()[0].date
@ -145,6 +149,10 @@ class EditCharterTests(TestCase):
url = urlreverse('charter_edit_notify', kwargs=dict(name=charter.name))
login_testing_unauthorized(self, "secretary", url)
# get
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
# post
self.assertTrue(not charter.notify)
r = self.client.post(url, dict(notify="someone@example.com, someoneelse@example.com"))

View file

@ -67,7 +67,7 @@ class ChangeStateTests(TestCase):
self.assertTrue(draft.tags.filter(slug="point"))
self.assertEqual(draft.docevent_set.count(), events_before + 2)
self.assertTrue("Test comment" in draft.docevent_set.all()[0].desc)
self.assertTrue("State changed" in draft.docevent_set.all()[1].desc)
self.assertTrue("IESG state changed" in draft.docevent_set.all()[1].desc)
self.assertEqual(len(outbox), mailbox_before + 2)
self.assertTrue("State Update Notice" in outbox[-2]['Subject'])
self.assertTrue(draft.name in outbox[-1]['Subject'])
@ -232,6 +232,10 @@ class EditInfoTests(TestCase):
note="",
)
# get
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
# add to telechat
self.assertTrue(not draft.latest_event(TelechatDocEvent, type="scheduled_for_telechat"))
data["telechat_date"] = TelechatDate.objects.active()[0].date.isoformat()
@ -347,6 +351,11 @@ class EditInfoTests(TestCase):
url = urlreverse('doc_edit_consensus', kwargs=dict(name=draft.name))
login_testing_unauthorized(self, "secretary", url)
# get
r = self.client.get(url)
self.assertEqual(r.status_code, 200)
# post
self.assertTrue(not draft.latest_event(ConsensusDocEvent, type="changed_consensus"))
r = self.client.post(url, dict(consensus="Yes"))
self.assertEqual(r.status_code, 302)

View file

@ -220,25 +220,24 @@ def get_document_content(key, filename, split=True, markup=True):
else:
return raw_content
def log_state_changed(request, doc, by, new_description, old_description):
e = DocEvent(doc=doc, by=by)
e.type = "changed_document"
e.desc = u"State changed to <b>%s</b> from %s" % (new_description, old_description)
e.save()
return e
def add_state_change_event(doc, by, prev_state, new_state, timestamp=None):
def add_state_change_event(doc, by, prev_state, new_state, prev_tags=[], new_tags=[], timestamp=None):
"""Add doc event to explain that state change just happened."""
if prev_state == new_state:
if prev_state and new_state:
assert prev_state.type_id == new_state.type_id
if prev_state == new_state and set(prev_tags) == set(new_tags):
return None
def tags_suffix(tags):
return (u"::" + u"::".join(t.name for t in tags)) if tags else u""
e = StateDocEvent(doc=doc, by=by)
e.type = "changed_state"
e.state_type = (prev_state or new_state).type
e.state = new_state
e.desc = "%s changed to <b>%s</b>" % (e.state_type.label, new_state.name)
e.desc = "%s changed to <b>%s</b>" % (e.state_type.label, new_state.name + tags_suffix(new_tags))
if prev_state:
e.desc += " from %s" % prev_state.name
e.desc += " from %s" % (prev_state.name + tags_suffix(prev_tags))
if timestamp:
e.time = timestamp
e.save()

View file

@ -13,15 +13,6 @@ from ietf.doc.models import DocEvent, NewRevisionDocEvent, WriteupDocEvent, Ball
from ietf.utils.history import find_history_active_at
def log_state_changed(request, doc, by, prev_state):
e = DocEvent(doc=doc, by=by)
e.type = "changed_document"
e.desc = u"State changed to <b>%s</b> from %s" % (
doc.get_state().name,
prev_state.name if prev_state else "None")
e.save()
return e
def next_revision(rev):
if rev == "":
return "00-00"

View file

@ -49,17 +49,21 @@ def do_undefer_ballot(request, doc):
telechat_date = TelechatDate.objects.active().order_by("date")[0].date
save_document_in_history(doc)
prev_state = doc.friendly_state()
if doc.type_id == 'draft':
doc.set_state(State.objects.get(used=True, type="draft-iesg", slug='iesg-eva'))
prev_tag = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
prev_tag = prev_tag[0] if prev_tag else None
if prev_tag:
doc.tags.remove(prev_tag)
elif doc.type_id == 'conflrev':
doc.set_state(State.objects.get(used=True, type='conflrev',slug='iesgeval'))
new_state = doc.get_state()
prev_tags = new_tags = []
e = log_state_changed(request, doc, login, doc.friendly_state(), prev_state)
if doc.type_id == 'draft':
new_state = State.objects.get(used=True, type="draft-iesg", slug='iesg-eva')
prev_tags = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
elif doc.type_id == 'conflrev':
new_state = State.objects.get(used=True, type='conflrev',slug='iesgeval')
prev_state = doc.get_state(new_state.type_id if new_state else None)
doc.set_state(new_state)
doc.tags.remove(*prev_tags)
e = add_state_change_event(doc, login, prev_state, new_state, prev_tags=prev_tags, new_tags=new_tags)
doc.time = e.time
doc.save()
@ -353,17 +357,21 @@ def defer_ballot(request, name):
if request.method == 'POST':
save_document_in_history(doc)
prev_state = doc.friendly_state()
if doc.type_id == 'draft':
doc.set_state(State.objects.get(used=True, type="draft-iesg", slug='defer'))
prev_tag = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
prev_tag = prev_tag[0] if prev_tag else None
if prev_tag:
doc.tags.remove(prev_tag)
elif doc.type_id == 'conflrev':
doc.set_state(State.objects.get(used=True, type='conflrev', slug='defer'))
new_state = doc.get_state()
prev_tags = new_tags = []
e = log_state_changed(request, doc, login, doc.friendly_state(), prev_state)
if doc.type_id == 'draft':
new_state = State.objects.get(used=True, type="draft-iesg", slug='defer')
prev_tags = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
elif doc.type_id == 'conflrev':
new_state = State.objects.get(used=True, type='conflrev', slug='defer')
prev_state = doc.get_state(new_state.type_id if new_state else None)
doc.set_state(new_state)
doc.tags.remove(*prev_tags)
e = add_state_change_event(doc, login, prev_state, new_state, prev_tags=prev_tags, new_tags=new_tags)
doc.time = e.time
doc.save()
@ -445,16 +453,16 @@ def lastcalltext(request, name):
if "send_last_call_request" in request.POST:
save_document_in_history(doc)
prev_state = doc.friendly_state()
doc.set_state(State.objects.get(used=True, type="draft-iesg", slug='lc-req'))
prev_state = doc.get_state("draft-iesg")
new_state = State.objects.get(used=True, type="draft-iesg", slug='lc-req')
prev_tag = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
prev_tag = prev_tag[0] if prev_tag else None
if prev_tag:
doc.tags.remove(prev_tag)
prev_tags = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
doc.set_state(new_state)
doc.tags.remove(*prev_tags)
e = add_state_change_event(doc, login, prev_state, new_state, prev_tags=prev_tags, new_tags=[])
e = log_state_changed(request, doc, login, doc.friendly_state(), prev_state)
doc.time = e.time
doc.save()
@ -664,8 +672,9 @@ def approve_ballot(request, name):
else:
new_state = State.objects.get(used=True, type="draft-iesg", slug="ann")
prev_friendly_state = doc.friendly_state()
prev_state = doc.get_state("draft-iesg")
prev_tags = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
if new_state.slug == "ann" and new_state.slug != prev_state.slug and not request.REQUEST.get("skiprfceditorpost"):
# start by notifying the RFC Editor
import ietf.sync.rfceditor
@ -677,18 +686,14 @@ def approve_ballot(request, name):
error=error),
context_instance=RequestContext(request))
# fixup document
close_open_ballots(doc, login)
save_document_in_history(doc)
doc.set_state(new_state)
prev_tag = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
prev_tag = prev_tag[0] if prev_tag else None
if prev_tag:
doc.tags.remove(prev_tag)
doc.tags.remove(*prev_tags)
# fixup document
close_open_ballots(doc, login)
e = DocEvent(doc=doc, by=login)
if action == "do_not_publish":
e.type = "iesg_disapproved"
@ -701,8 +706,8 @@ def approve_ballot(request, name):
change_description = e.desc + " and state has been changed to %s" % doc.get_state("draft-iesg").name
e = log_state_changed(request, doc, login, doc.friendly_state(), prev_friendly_state)
e = add_state_change_event(doc, login, prev_state, new_state, prev_tags=prev_tags, new_tags=[])
doc.time = e.time
doc.save()
@ -766,26 +771,27 @@ def make_last_call(request, name):
save_document_in_history(doc)
prev_state = doc.get_state("draft-iesg")
new_state = doc.get_state()
prev_tags = new_tags = []
if doc.type.slug == 'draft':
doc.set_state(State.objects.get(used=True, type="draft-iesg", slug='lc'))
prev_tag = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
prev_tag = prev_tag[0] if prev_tag else None
if prev_tag:
doc.tags.remove(prev_tag)
e = log_state_changed(request, doc, login, doc.friendly_state(), prev_state)
change_description = "Last call has been made for %s and state has been changed to %s" % (doc.name, doc.get_state("draft-iesg").name)
new_state = State.objects.get(used=True, type="draft-iesg", slug='lc')
prev_tags = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
elif doc.type.slug == 'statchg':
doc.set_state(State.objects.get(used=True, type="statchg", slug='in-lc'))
e = log_state_changed(request, doc, login, doc.friendly_state(), prev_state)
change_description = "Last call has been made for %s and state has been changed to %s" % (doc.name, doc.friendly_state())
new_state = State.objects.get(used=True, type="statchg", slug='in-lc')
prev_state = doc.get_state(new_state.type_id)
doc.set_state(new_state)
doc.tags.remove(*prev_tags)
e = add_state_change_event(doc, login, prev_state, new_state, prev_tags=prev_tags, new_tags=new_tags)
doc.time = e.time
doc.save()
change_description = "Last call has been made for %s and state has been changed to %s" % (doc.name, new_state.name)
email_state_changed(request, doc, change_description)
email_ad(request, doc, doc.ad, login, change_description)

View file

@ -100,12 +100,13 @@ def change_state(request, name, option=None):
# Charter state changed
save_document_in_history(charter)
prev = charter.get_state()
charter.set_state(charter_state)
prev_state = charter.get_state()
new_state = charter_state
charter.set_state(new_state)
charter.rev = charter_rev
if option != "abandon":
log_state_changed(request, charter, login, prev)
add_state_change_event(charter, login, prev_state, new_state)
else:
# kill hanging ballots
close_open_ballots(charter, login)
@ -612,7 +613,7 @@ def approve(request, name):
change_description += " and %s state has been changed to %s" % (group.type.name, new_state.name)
e = log_state_changed(request, charter, login, prev_charter_state)
e = add_state_change_event(charter, login, prev_charter_state, new_charter_state)
# according to spec, 00-02 becomes 01, so copy file and record new revision
try:

View file

@ -8,8 +8,7 @@ from django.template import RequestContext
from django.template.loader import render_to_string
from django.conf import settings
from ietf.doc.utils import log_state_changed, update_telechat
from ietf.doc.utils import add_state_change_event, update_telechat
from ietf.doc.models import save_document_in_history
from ietf.doc.utils import create_ballot_if_not_open, close_open_ballots, get_document_content
from ietf.ietfauth.utils import has_role, role_required
@ -41,7 +40,7 @@ def change_state(request, name, option=None):
form = ChangeStateForm(request.POST)
if form.is_valid():
clean = form.cleaned_data
review_state = clean['review_state']
new_state = clean['review_state']
comment = clean['comment'].rstrip()
if comment:
@ -49,19 +48,17 @@ def change_state(request, name, option=None):
c.desc = comment
c.save()
if review_state != review.get_state():
prev_state = review.get_state()
if new_state != prev_state:
save_document_in_history(review)
old_description = review.friendly_state()
review.set_state(review_state)
new_description = review.friendly_state()
log_state_changed(request, review, login, new_description, old_description)
review.set_state(new_state)
add_state_change_event(review, login, prev_state, new_state)
review.time = datetime.datetime.now()
review.save()
if review_state.slug == "iesgeval":
if new_state.slug == "iesgeval":
create_ballot_if_not_open(review, login, "conflrev")
ballot = review.latest_event(BallotDocEvent, type="created_ballot")
if has_role(request.user, "Area Director") and not review.latest_event(BallotPositionDocEvent, ad=login, ballot=ballot, type="changed_ballot_position"):
@ -307,15 +304,14 @@ def approve(request, name):
form = AnnouncementForm(request.POST)
if form.is_valid():
prev_state = review.get_state()
new_state_slug = 'appr-reqnopub-sent' if review.get_state('conflrev').slug=='appr-reqnopub-pend' else 'appr-noprob-sent'
new_review_state = State.objects.get(used=True, type="conflrev", slug=new_state_slug)
new_state_slug = 'appr-reqnopub-sent' if prev_state.slug == 'appr-reqnopub-pend' else 'appr-noprob-sent'
new_state = State.objects.get(used=True, type="conflrev", slug=new_state_slug)
save_document_in_history(review)
old_description = review.friendly_state()
review.set_state(new_review_state)
new_description = review.friendly_state()
log_state_changed(request, review, login, new_description, old_description)
review.set_state(new_state)
add_state_change_event(review, login, prev_state, new_state)
close_open_ballots(review, login)

View file

@ -57,7 +57,7 @@ class ChangeStateForm(forms.Form):
@role_required('Area Director','Secretariat')
def change_state(request, name):
"""Change state of Internet Draft, notifying parties as necessary
"""Change IESG state of Internet Draft, notifying parties as necessary
and logging the change as a comment."""
doc = get_object_or_404(Document, docalias__name=name)
if (not doc.latest_event(type="started_iesg_process")) or doc.get_state_slug() == "expired":
@ -69,30 +69,28 @@ def change_state(request, name):
form = ChangeStateForm(request.POST)
form.docname=name
if form.is_valid():
next_state = form.cleaned_data['state']
new_state = form.cleaned_data['state']
prev_state = doc.get_state("draft-iesg")
prev_friendly_state = doc.friendly_state()
tag = form.cleaned_data['substate']
comment = form.cleaned_data['comment'].strip()
# tag handling is a bit awkward since the UI still works
# as if IESG tags are a substate
prev_tag = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
prev_tag = prev_tag[0] if prev_tag else None
if next_state != prev_state or tag != prev_tag:
prev_tags = doc.tags.filter(slug__in=IESG_SUBSTATE_TAGS)
new_tags = [tag] if tag else []
if new_state != prev_state or set(new_tags) != set(prev_tags):
save_document_in_history(doc)
doc.set_state(next_state)
doc.set_state(new_state)
if prev_tag:
doc.tags.remove(prev_tag)
doc.tags.remove(*prev_tags)
doc.tags.add(*new_tags)
if tag:
doc.tags.add(tag)
e = add_state_change_event(doc, login, prev_state, new_state,
prev_tags=prev_tags, new_tags=new_tags)
e = log_state_changed(request, doc, login, doc.friendly_state(), prev_friendly_state)
msg = e.desc
if comment:
c = DocEvent(type="added_comment")
@ -101,23 +99,23 @@ def change_state(request, name):
c.desc = comment
c.save()
e.desc += "<br>" + comment
msg += "\n" + comment
doc.time = e.time
doc.save()
email_state_changed(request, doc, e.desc)
email_ad(request, doc, doc.ad, login, e.desc)
email_state_changed(request, doc, msg)
email_ad(request, doc, doc.ad, login, msg)
if prev_state and prev_state.slug in ("ann", "rfcqueue") and next_state.slug not in ("rfcqueue", "pub"):
email_pulled_from_rfc_queue(request, doc, comment, prev_state, next_state)
if prev_state and prev_state.slug in ("ann", "rfcqueue") and new_state.slug not in ("rfcqueue", "pub"):
email_pulled_from_rfc_queue(request, doc, comment, prev_state, new_state)
if next_state.slug in ("iesg-eva", "lc"):
if new_state.slug in ("iesg-eva", "lc"):
if not doc.get_state_slug("draft-iana-review"):
doc.set_state(State.objects.get(used=True, type="draft-iana-review", slug="need-rev"))
if next_state.slug == "lc-req":
if new_state.slug == "lc-req":
request_last_call(request, doc)
return render_to_response('doc/draft/last_call_requested.html',
@ -179,14 +177,14 @@ def change_iana_state(request, name, state_type):
if request.method == 'POST':
form = ChangeIanaStateForm(state_type, request.POST)
if form.is_valid():
next_state = form.cleaned_data['state']
new_state = form.cleaned_data['state']
if next_state != prev_state:
if new_state != prev_state:
save_document_in_history(doc)
doc.set_state(next_state)
doc.set_state(new_state)
e = add_state_change_event(doc, request.user.person, prev_state, next_state)
e = add_state_change_event(doc, request.user.person, prev_state, new_state)
doc.time = e.time
doc.save()
@ -1220,7 +1218,7 @@ def request_publication(request, name):
e.save()
# change state
prev_state = doc.get_state(next_state.type)
prev_state = doc.get_state(next_state.type_id)
if next_state != prev_state:
doc.set_state(next_state)
e = add_state_change_event(doc, request.user.person, prev_state, next_state)
@ -1322,7 +1320,7 @@ def adopt_draft(request, name):
new_state = State.objects.get(slug=adopt_state_slug, type="draft-stream-%s" % doc.stream_id, used=True)
if new_state != prev_state:
doc.set_state(new_state)
e = add_state_change_event(doc, by, prev_state, new_state, doc.time)
e = add_state_change_event(doc, by, prev_state, new_state, timestamp=doc.time)
due_date = None
if form.cleaned_data["weeks"] != None:
@ -1423,7 +1421,7 @@ def change_stream_state(request, name, state_type):
new_state = form.cleaned_data["new_state"]
if new_state != prev_state:
doc.set_state(new_state)
e = add_state_change_event(doc, by, prev_state, new_state, doc.time)
e = add_state_change_event(doc, by, prev_state, new_state, timestamp=doc.time)
due_date = None
if form.cleaned_data["weeks"] != None:

View file

@ -8,7 +8,7 @@ from django.template import RequestContext
from django.template.loader import render_to_string
from django.conf import settings
from ietf.doc.utils import log_state_changed, update_telechat
from ietf.doc.utils import add_state_change_event, update_telechat
from ietf.doc.models import save_document_in_history
from ietf.doc.utils import create_ballot_if_not_open, close_open_ballots, get_document_content
@ -51,14 +51,12 @@ def change_state(request, name, option=None):
c.desc = comment
c.save()
if new_state != status_change.get_state():
prev_state = status_change.get_state()
if new_state != prev_state:
save_document_in_history(status_change)
old_description = status_change.friendly_state()
status_change.set_state(new_state)
new_description = status_change.friendly_state()
log_state_changed(request, status_change, login, new_description, old_description)
add_state_change_event(status_change, login, prev_state, new_state)
status_change.time = datetime.datetime.now()
status_change.save()
@ -327,10 +325,11 @@ def approve(request, name):
save_document_in_history(status_change)
old_description = status_change.friendly_state()
status_change.set_state(State.objects.get(type='statchg', slug='appr-sent'))
new_description = status_change.friendly_state()
log_state_changed(request, status_change, login, new_description, old_description)
prev_state = status_change.get_state()
new_state = State.objects.get(type='statchg', slug='appr-sent')
status_change.set_state(new_state)
add_state_change_event(status_change, login, prev_state, new_state)
close_open_ballots(status_change, login)
@ -689,11 +688,11 @@ def last_call(request, name):
if "send_last_call_request" in request.POST:
save_document_in_history(status_change)
old_description = status_change.friendly_state()
status_change.set_state(State.objects.get(type='statchg', slug='lc-req'))
new_description = status_change.friendly_state()
prev_state = status_change.get_state()
new_state = State.objects.get(type='statchg', slug='lc-req')
e = log_state_changed(request, status_change, login, new_description, old_description)
status_change.set_state(new_state)
e = add_state_change_event(status_change, login, prev_state, new_state)
status_change.time = e.time
status_change.save()

View file

@ -8,7 +8,7 @@ from django.shortcuts import render_to_response, get_object_or_404, redirect
from django.template import RequestContext
from ietf.doc.models import DocEvent, Document, BallotDocEvent, BallotPositionDocEvent, TelechatDocEvent, WriteupDocEvent, save_document_in_history
from ietf.doc.utils import get_document_content, log_state_changed
from ietf.doc.utils import get_document_content, add_state_change_event
from ietf.group.models import Group
from ietf.name.models import BallotPositionName
from ietf.person.models import Person
@ -237,38 +237,35 @@ def doc_detail(request, date, name):
formset = BallotFormset(initial=initial_ballot)
state_form = ChangeStateForm(request.POST, initial=initial_state)
if state_form.is_valid():
state = state_form.cleaned_data['state']
prev_state = doc.get_state(state_type)
new_state = state_form.cleaned_data['state']
tag = state_form.cleaned_data['substate']
prev = doc.get_state(state_type)
# tag handling is a bit awkward since the UI still works
# as if IESG tags are a substate
prev_tag = doc.tags.filter(slug__in=(TELECHAT_TAGS))
prev_tag = prev_tag[0] if prev_tag else None
prev_tags = doc.tags.filter(slug__in=TELECHAT_TAGS)
new_tags = [tag] if tag else []
#if state != prev or tag != prev_tag:
if state_form.changed_data:
save_document_in_history(doc)
old_description = doc.friendly_state()
if 'state' in state_form.changed_data:
doc.set_state(state)
doc.set_state(new_state)
if 'substate' in state_form.changed_data:
if prev_tag:
doc.tags.remove(prev_tag)
if tag:
doc.tags.add(tag)
doc.tags.remove(*prev_tags)
doc.tags.add(*new_tags)
new_description = doc.friendly_state()
e = log_state_changed(request, doc, login, new_description, old_description)
e = add_state_change_event(doc, login, prev_state, new_state,
prev_tags=prev_tags, new_tags=new_tags)
doc.time = e.time
doc.save()
email_state_changed(request, doc, e.desc)
email_ad(request, doc, doc.ad, login, e.desc)
if state.slug == "lc-req":
if new_state.slug == "lc-req":
request_last_call(request, doc)
messages.success(request,'Document state updated')

View file

@ -187,7 +187,7 @@ def update_history_with_changes(changes, send_email=True):
# that we assume these changes are cronologically
# applied
prev_state = doc.get_state(state_type)
e = add_state_change_event(doc, system, prev_state, state, timestamp)
e = add_state_change_event(doc, system, prev_state, state, timestamp=timestamp)
if e:
# for logging purposes