Skip to content

Commit

Permalink
Corrected Document vs DocHistory mismatch when working with status-ch…
Browse files Browse the repository at this point in the history
…ange documents. Corrected creation of BallotDocEvent timestamps. Fixes bug #1396. Commit ready for merge

 - Legacy-Id: 7705
  • Loading branch information
rjsparks committed May 6, 2014
1 parent cb458b1 commit 18bfe66
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
11 changes: 11 additions & 0 deletions ietf/doc/tests_status_change.py
Expand Up @@ -422,6 +422,11 @@ def test_subsequent_submission(self):
with open(path,'w') as f:
f.write('This is the old proposal.')
f.close()
# Put the old proposal into IESG review (exercises ballot tab when looking at an older revision below)
state_change_url = urlreverse('status_change_change_state',kwargs=dict(name=doc.name))
iesgeval_pk = str(State.objects.get(slug='iesgeval',type__slug='statchg').pk)
r = self.client.post(state_change_url,dict(new_state=iesgeval_pk))
self.assertEqual(r.status_code, 302)

# normal get
r = self.client.get(url)
Expand Down Expand Up @@ -457,6 +462,12 @@ def test_subsequent_submission(self):
q = PyQuery(r.content)
self.assertTrue(q('textarea')[0].text.strip().startswith("Provide a description"))

# make sure we can see the old revision
url = urlreverse('doc_view',kwargs=dict(name=doc.name,rev='00'))
r = self.client.get(url)
self.assertEqual(r.status_code,200)
self.assertTrue("This is the old proposal." in r.content)

def setUp(self):
make_test_data()
self.test_dir = os.path.abspath("tmp-status-change-testdir")
Expand Down
2 changes: 1 addition & 1 deletion ietf/doc/urls.py
Expand Up @@ -50,7 +50,7 @@
url(r'^all/$', views_search.index_all_drafts, name="index_all_drafts"),
url(r'^active/$', views_search.index_active_drafts, name="index_active_drafts"),

url(r'^(?P<name>[A-Za-z0-9._+-]+)/((?P<rev>[0-9-]+)/)?$', views_doc.document_main, name="doc_view"),
url(r'^(?P<name>[A-Za-z0-9._+-]+)/(?:(?P<rev>[0-9-]+)/)?$', views_doc.document_main, name="doc_view"),
url(r'^(?P<name>[A-Za-z0-9._+-]+)/history/$', views_doc.document_history, name="doc_history"),
url(r'^(?P<name>[A-Za-z0-9._+-]+)/writeup/$', views_doc.document_writeup, name="doc_writeup"),
url(r'^(?P<name>[A-Za-z0-9._+-]+)/shepherdwriteup/$', views_doc.document_shepherd_writeup, name="doc_shepherd_writeup"),
Expand Down
17 changes: 14 additions & 3 deletions ietf/doc/utils.py
Expand Up @@ -4,8 +4,10 @@
import math

from django.conf import settings
from django.db.models.query import EmptyQuerySet

from ietf.utils import markup_txt
from ietf.doc.models import Document, DocHistory
from ietf.doc.models import DocAlias, RelatedDocument, BallotType, DocReminder
from ietf.doc.models import DocEvent, BallotDocEvent, NewRevisionDocEvent, StateDocEvent
from ietf.name.models import DocReminderTypeName, DocRelationshipName
Expand Down Expand Up @@ -88,7 +90,13 @@ def needed_ballot_positions(doc, active_positions):
if doc.type_id == "draft" and doc.intended_std_level_id in ("bcp", "ps", "ds", "std"):
needed = two_thirds_rule(recused=len(recuse))
elif doc.type_id == "statchg":
for rel in doc.relateddocument_set.filter(relationship__slug__in=['tops', 'tois', 'tohist', 'toinf', 'tobcp', 'toexp']):
if isinstance(doc,Document):
related_set = doc.relateddocument_set
elif isinstance(doc,DocHistory):
related_set = doc.relateddochistory_set
else:
related_set = EmptyQuerySet()
for rel in related_set.filter(relationship__slug__in=['tops', 'tois', 'tohist', 'toinf', 'tobcp', 'toexp']):
if (rel.target.document.std_level.slug in ['bcp','ps','ds','std']) or (rel.relationship.slug in ['tops','tois','tobcp']):
needed = two_thirds_rule(recused=len(recuse))
break
Expand All @@ -111,9 +119,12 @@ def needed_ballot_positions(doc, active_positions):

return " ".join(answer)

def create_ballot_if_not_open(doc, by, ballot_slug):
def create_ballot_if_not_open(doc, by, ballot_slug, time=None):
if not doc.ballot_open(ballot_slug):
e = BallotDocEvent(type="created_ballot", by=by, doc=doc)
if time:
e = BallotDocEvent(type="created_ballot", by=by, doc=doc, time=time)
else:
e = BallotDocEvent(type="created_ballot", by=by, doc=doc)
e.ballot_type = BallotType.objects.get(doc_type=doc.type, slug=ballot_slug)
e.desc = u'Created "%s" ballot' % e.ballot_type.name
e.save()
Expand Down
2 changes: 1 addition & 1 deletion ietf/doc/views_status_change.py
Expand Up @@ -59,7 +59,7 @@ def change_state(request, name, option=None):
status_change.save()

if new_state.slug == "iesgeval":
create_ballot_if_not_open(status_change, login, "statchg")
create_ballot_if_not_open(status_change, login, "statchg", e.time)
ballot = status_change.latest_event(BallotDocEvent, type="created_ballot")
if has_role(request.user, "Area Director") and not status_change.latest_event(BallotPositionDocEvent, ad=login, ballot=ballot, type="changed_ballot_position"):

Expand Down

0 comments on commit 18bfe66

Please sign in to comment.