Skip to content

Commit a603b8e

Browse files
committed
Show approved milestones on /doc/charter-xyz/ page if the charter is
approved instead of only showing proposed milestones for proposed charters - Legacy-Id: 5794
1 parent bf81451 commit a603b8e

4 files changed

Lines changed: 49 additions & 36 deletions

File tree

ietf/idrfc/views_doc.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
from ietf.utils.history import find_history_active_at
5656
from ietf.ietfauth.decorators import has_role
5757
from ietf.doc.views_status_change import RELATION_SLUGS as status_change_relationships
58+
from ietf.wgcharter.utils import historic_milestones_for_charter
5859

5960
def render_document_top(request, doc, tab, name):
6061
tabs = []
@@ -92,7 +93,7 @@ def document_main(request, name, rev=None):
9293
raise Http404()
9394
return document_main_idrfc(request, name, tab="document")
9495

95-
doc = get_object_or_404(Document, docalias__name=name)
96+
orig_doc = doc = get_object_or_404(Document, docalias__name=name)
9697
group = doc.group
9798
if doc.type_id == 'conflrev':
9899
conflictdoc = doc.relateddocument_set.get(relationship__slug='conflrev').target.document
@@ -153,9 +154,7 @@ def document_main(request, name, rev=None):
153154
chartering = get_chartering_type(doc)
154155

155156
# inject milestones from group
156-
milestones = None
157-
if chartering and not snapshot:
158-
milestones = doc.group.groupmilestone_set.filter(state="charter")
157+
milestones = historic_milestones_for_charter(orig_doc, doc.rev)
159158

160159
return render_to_response("idrfc/document_charter.html",
161160
dict(doc=doc,

ietf/templates/idrfc/document_charter.html

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,8 @@ <h3>Charter {{ doc.canonical_name }}-{{ doc.rev }}
139139
</div>
140140
{% endif %}
141141

142-
{% if not snapshot and chartering %}
143-
<h3>Proposed Milestones
144-
{% if user|has_role:"Area Director,Secretariat" %}
142+
<h3>{% if chartering %}Proposed{% endif %} Milestones
143+
{% if not snapshot and user|has_role:"Area Director,Secretariat" %}
145144
<a class="edit" href="{% url wg_edit_charter_milestones acronym=doc.group.acronym %}">Edit charter milestones</a>
146145
{% endif %}
147146
</h3>
@@ -151,7 +150,6 @@ <h3>Proposed Milestones
151150
{% else %}
152151
<p>No milestones for charter found.</p>
153152
{% endif %}
154-
{% endif %}
155153

156154
{% endblock %}
157155

ietf/wgcharter/utils.py

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
from django.conf import settings
44

55
from ietf.group.models import GroupEvent, ChangeStateGroupEvent
6-
from ietf.doc.models import Document, DocAlias, DocHistory, RelatedDocument, DocumentAuthor, DocEvent
6+
from ietf.doc.models import Document, DocAlias, DocHistory, RelatedDocument, DocumentAuthor, DocEvent, NewRevisionDocEvent
7+
from ietf.utils.history import find_history_active_at
78

89
def log_state_changed(request, doc, by, prev_state):
910
e = DocEvent(doc=doc, by=by)
@@ -43,6 +44,44 @@ def read_charter_text(doc):
4344
except IOError:
4445
return "Error: couldn't read charter text"
4546

47+
def historic_milestones_for_charter(charter, rev):
48+
"""Return GroupMilestone/GroupMilestoneHistory objects for charter
49+
document at rev by looking through the history."""
50+
51+
chartering = "-" in rev
52+
if chartering:
53+
need_state = "charter"
54+
else:
55+
need_state = "active"
56+
57+
# slight complication - we can assign milestones to a revision up
58+
# until the point where the next superseding revision is
59+
# published, so that time shall be our limit
60+
revision_event = charter.latest_event(NewRevisionDocEvent, type="new_revision", rev=rev)
61+
if not revision_event:
62+
return []
63+
64+
e = charter.docevent_set.filter(time__gt=revision_event.time, type="new_revision").order_by("time")
65+
if not chartering:
66+
e = e.exclude(newrevisiondocevent__rev__contains="-")
67+
68+
if e:
69+
# subtract a margen of error to avoid collisions with
70+
# milestones being published at the same time as the new
71+
# revision (when approving a charter)
72+
just_before_next_rev = e[0].time - datetime.timedelta(seconds=5)
73+
else:
74+
just_before_next_rev = datetime.datetime.now()
75+
76+
res = []
77+
for m in charter.chartered_group.groupmilestone_set.all():
78+
mh = find_history_active_at(m, just_before_next_rev)
79+
if mh and mh.state_id == need_state:
80+
res.append(mh)
81+
82+
return res
83+
84+
4685
def update_telechat(request, doc, by, new_telechat_date):
4786
# FIXME: reuse function in idrfc/utils.py instead of this one
4887
# (need to fix auto-setting returning item problem first though)

ietf/wgcharter/views.py

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -716,35 +716,12 @@ def charter_with_milestones_txt(request, name, rev):
716716
charter_text = "Error reading charter text %s" % filename
717717

718718

719-
# find milestones
720-
721-
chartering = "-" in rev
722-
if chartering:
723-
need_state = "charter"
724-
else:
725-
need_state = "active"
726-
727-
# slight complication - we can assign milestones to a revision up
728-
# until the point where the next superseding revision is
729-
# published, so that time shall be our limit
730-
e = charter.docevent_set.filter(time__gt=revision_event.time, type="new_revision").order_by("time")
731-
if not chartering:
732-
e = e.exclude(newrevisiondocevent__rev__contains="-")
733-
734-
if e:
735-
# subtract a margen of error
736-
just_before_next_rev = e[0].time - datetime.timedelta(seconds=5)
737-
else:
738-
just_before_next_rev = datetime.datetime.now()
719+
milestones = historic_milestones_for_charter(charter, rev)
739720

721+
# wrap the output nicely
740722
wrapper = textwrap.TextWrapper(initial_indent="", subsequent_indent=" " * 11, width=80, break_long_words=False)
741-
742-
milestones = []
743-
for m in charter.chartered_group.groupmilestone_set.all():
744-
mh = find_history_active_at(m, just_before_next_rev)
745-
if mh and mh.state_id == need_state:
746-
mh.desc_filled = wrapper.fill(mh.desc)
747-
milestones.append(mh)
723+
for m in milestones:
724+
m.desc_filled = wrapper.fill(m.desc)
748725

749726
return render_to_response('wgcharter/charter_with_milestones.txt',
750727
dict(charter_text=charter_text,

0 commit comments

Comments
 (0)