Skip to content

Commit 891ac25

Browse files
committed
Use revision numbers to identify ballots and put a warning on closed ballots.
- Legacy-Id: 4352
1 parent 79d9eb8 commit 891ac25

3 files changed

Lines changed: 49 additions & 25 deletions

File tree

ietf/doc/utils.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,28 @@ def get_chartering_type(doc):
121121

122122
return chartering
123123

124+
def augment_events_with_revision(doc, events):
125+
"""Take a set of events for doc and add a .rev attribute with the
126+
revision they refer to by checking NewRevisionDocEvents."""
127+
128+
event_revisions = list(NewRevisionDocEvent.objects.filter(doc=doc).order_by('time', 'id').values('id', 'rev', 'time'))
129+
130+
cur_rev = doc.rev
131+
if doc.get_state_slug() == "rfc":
132+
cur_rev = "RFC"
133+
134+
for e in sorted(events, key=lambda e: (e.time, e.id), reverse=True):
135+
while event_revisions and (e.time, e.id) < (event_revisions[-1]["time"], event_revisions[-1]["id"]):
136+
event_revisions.pop()
137+
138+
if event_revisions:
139+
cur_rev = event_revisions[-1]["rev"]
140+
else:
141+
cur_rev = "00"
142+
143+
e.rev = cur_rev
144+
145+
124146
def augment_with_telechat_date(docs):
125147
"""Add a telechat_date attribute to each document with the
126148
scheduled telechat or None if it's not scheduled."""

ietf/idrfc/views_doc.py

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
from ietf.idrfc.idrfc_wrapper import BallotWrapper, IdWrapper, RfcWrapper
5151
from ietf.ietfworkflows.utils import get_full_info_for_draft
5252
from ietf.doc.models import *
53-
from ietf.doc.utils import get_chartering_type, needed_ballot_positions, active_ballot_positions
53+
from ietf.doc.utils import *
5454
from ietf.utils.history import find_history_active_at
5555
from ietf.ietfauth.decorators import has_role
5656

@@ -190,23 +190,7 @@ def document_history(request, name):
190190
# grab event history
191191
events = doc.docevent_set.all().order_by("-time", "-id").select_related("by")
192192

193-
# fill in revision numbers
194-
event_revisions = list(NewRevisionDocEvent.objects.filter(doc=doc).order_by('time', 'id').values('rev', 'time'))
195-
196-
cur_rev = doc.rev
197-
if doc.get_state_slug() == "rfc":
198-
cur_rev = "RFC"
199-
200-
for e in events:
201-
while event_revisions and e.time < event_revisions[-1]["time"]:
202-
event_revisions.pop()
203-
204-
if event_revisions:
205-
cur_rev = event_revisions[-1]["rev"]
206-
else:
207-
cur_rev = "00"
208-
209-
e.rev = cur_rev
193+
augment_events_with_revision(doc, events)
210194

211195
return render_to_response("idrfc/document_history.html",
212196
dict(doc=doc,
@@ -255,13 +239,21 @@ def document_writeup(request, name):
255239

256240
def document_ballot_content(request, doc, ballot_id, editable=True):
257241
"""Render HTML string with content of ballot page."""
242+
all_ballots = list(BallotDocEvent.objects.filter(doc=doc, type="created_ballot").order_by("time"))
243+
augment_events_with_revision(doc, all_ballots)
244+
245+
ballot = None
258246
if ballot_id != None:
259-
ballot = doc.latest_event(BallotDocEvent, type="created_ballot", pk=ballot_id)
260-
else:
261-
ballot = doc.latest_event(BallotDocEvent, type="created_ballot")
247+
ballot_id = int(ballot_id)
248+
for b in all_ballots:
249+
if b.id == ballot_id:
250+
ballot = b
251+
break
252+
elif all_ballots:
253+
ballot = all_ballots[-1]
262254

263255
if not ballot:
264-
raise Http404()
256+
raise Http404
265257

266258
deferred = None
267259
if doc.type_id == "draft" and doc.get_state_slug("draft-iesg") == "defer":
@@ -314,14 +306,20 @@ def document_ballot_content(request, doc, ballot_id, editable=True):
314306
text_positions = [p for p in positions if p.discuss or p.comment]
315307
text_positions.sort(key=lambda p: (p.old_ad, p.ad.plain_name()))
316308

317-
all_ballots = BallotDocEvent.objects.filter(doc=doc, type="created_ballot")
309+
ballot_open = not BallotDocEvent.objects.filter(doc=doc,
310+
type__in=("closed_ballot", "created_ballot"),
311+
time__gt=ballot.time,
312+
ballot_type=ballot.ballot_type)
313+
if not ballot_open:
314+
editable = False
318315

319316
return render_to_string("idrfc/document_ballot_content.html",
320317
dict(doc=doc,
321318
ballot=ballot,
322319
position_groups=position_groups,
323320
text_positions=text_positions,
324321
editable=editable,
322+
ballot_open=ballot_open,
325323
deferred=deferred,
326324
summary=summary,
327325
all_ballots=all_ballots,

ietf/templates/idrfc/document_ballot_content.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,19 @@
3939

4040
{% if all_ballots and all_ballots|length > 1 %}
4141
<div class="other-ballots">
42-
Other ballots:
42+
Available ballots:
4343
{% for b in all_ballots %}
44-
<a{% if b != ballot %} href="{% url doc_ballot name=doc.name,ballot_id=b.pk %}"{% endif %}>{{ b.ballot_type.name }} ({{ b.time|date:"Y-m-d" }})</a>
44+
<a{% if b != ballot %} href="{% url doc_ballot name=doc.name,ballot_id=b.pk %}"{% endif %}>{{ b.ballot_type.name }} ({{ b.rev }})</a>
4545
{% endfor %}
4646
</div>
4747
{% endif %}
4848

4949
<h2 style="margin-top:12px;">{{ ballot.ballot_type.question }}</h2>
5050

51+
{% if not ballot_open %}
52+
<p>Note: This ballot was opened for revision {{ ballot.rev }} and is now closed.</p>
53+
{% endif %}
54+
5155
<p>Summary: <i>{{ summary }}</i></p>
5256

5357
{% for p in text_positions %}

0 commit comments

Comments
 (0)