Skip to content

Commit 5bfea0f

Browse files
committed
Merged in [19553] from rjsparks@nostrum.com:
Gather related document information a little more efficiently for the draft main view - Legacy-Id: 19563 Note: SVN reference [19553] has been migrated to Git commit 19fb998
2 parents a7eb07b + 19fb998 commit 5bfea0f

3 files changed

Lines changed: 71 additions & 32 deletions

File tree

ietf/doc/templatetags/ietf_filters.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,13 +236,31 @@ def urlize_ietf_docs(string, autoescape=None):
236236
return mark_safe(string)
237237
urlize_ietf_docs = stringfilter(urlize_ietf_docs)
238238

239-
@register.filter(name='urlize_doc_list', is_safe=True, needs_autoescape=True)
240-
def urlize_doc_list(docs, autoescape=None):
241-
"""Convert a list of DocAliases into list of links using canonical name"""
239+
@register.filter(name='urlize_related_source_list', is_safe=True, needs_autoescape=True)
240+
def urlize_related_source_list(related, autoescape=None):
241+
"""Convert a list of DocumentRelations into list of links using the source document's canonical name"""
242242
links = []
243-
for doc in docs:
244-
name=doc.document.canonical_name()
245-
title = doc.document.title
243+
for rel in related:
244+
name=rel.source.canonical_name()
245+
title = rel.source.title
246+
url = urlreverse('ietf.doc.views_doc.document_main', kwargs=dict(name=name))
247+
if autoescape:
248+
name = escape(name)
249+
title = escape(title)
250+
links.append(mark_safe(
251+
'<a href="%(url)s" title="%(title)s">%(name)s</a>' % dict(name=prettify_std_name(name),
252+
title=title,
253+
url=url)
254+
))
255+
return links
256+
257+
@register.filter(name='urlize_related_target_list', is_safe=True, needs_autoescape=True)
258+
def urlize_related_target_list(related, autoescape=None):
259+
"""Convert a list of DocumentRelations into list of links using the source document's canonical name"""
260+
links = []
261+
for rel in related:
262+
name=rel.target.document.canonical_name()
263+
title = rel.target.document.title
246264
url = urlreverse('ietf.doc.views_doc.document_main', kwargs=dict(name=name))
247265
if autoescape:
248266
name = escape(name)

ietf/doc/views_doc.py

Lines changed: 37 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@
5656

5757
from ietf.doc.models import ( Document, DocAlias, DocHistory, DocEvent, BallotDocEvent, BallotType,
5858
ConsensusDocEvent, NewRevisionDocEvent, TelechatDocEvent, WriteupDocEvent, IanaExpertDocEvent,
59-
IESG_BALLOT_ACTIVE_STATES, STATUSCHANGE_RELATIONS, DocumentActionHolder, DocumentAuthor)
59+
IESG_BALLOT_ACTIVE_STATES, STATUSCHANGE_RELATIONS, DocumentActionHolder, DocumentAuthor,
60+
RelatedDocument, RelatedDocHistory)
6061
from ietf.doc.utils import (add_links_in_new_revision_events, augment_events_with_revision,
6162
can_adopt_draft, can_unadopt_draft, get_chartering_type, get_tags_for_stream_id,
6263
needed_ballot_positions, nice_consensus, prettify_std_name, update_telechat, has_same_ballot,
@@ -118,6 +119,25 @@ def render_document_top(request, doc, tab, name):
118119
selected=tab,
119120
name=name))
120121

122+
def interesting_doc_relations(doc):
123+
124+
if isinstance(doc, Document):
125+
cls = RelatedDocument
126+
target = doc
127+
elif isinstance(doc, DocHistory):
128+
cls = RelatedDocHistory
129+
target = doc.doc
130+
else:
131+
raise TypeError("Expected this method to be called with a Document or DocHistory object")
132+
133+
that_relationships = STATUSCHANGE_RELATIONS + ('conflrev', 'replaces', 'possibly_replaces', 'updates', 'obs')
134+
135+
that_doc_relationships = ('replaces', 'possibly_replaces', 'updates', 'obs')
136+
137+
interesting_relations_that = cls.objects.filter(target__docs=target, relationship__in=that_relationships).select_related('source')
138+
interesting_relations_that_doc = cls.objects.filter(source=doc, relationship__in=that_doc_relationships).prefetch_related('target__docs')
139+
140+
return interesting_relations_that, interesting_relations_that_doc
121141

122142
def document_main(request, name, rev=None):
123143
doc = get_object_or_404(Document.objects.select_related(), docalias__name=name)
@@ -128,9 +148,6 @@ def document_main(request, name, rev=None):
128148
for a in aliases:
129149
if a.startswith("rfc"):
130150
return redirect("ietf.doc.views_doc.document_main", name=a)
131-
132-
if doc.type_id == 'conflrev':
133-
conflictdoc = doc.related_that_doc('conflrev')[0].document
134151

135152
revisions = []
136153
for h in doc.history_set.order_by("time", "id"):
@@ -182,6 +199,8 @@ def document_main(request, name, rev=None):
182199
else:
183200
pass
184201

202+
interesting_relations_that, interesting_relations_that_doc = interesting_doc_relations(doc)
203+
185204
iesg_state = doc.get_state("draft-iesg")
186205
if isinstance(doc, Document):
187206
log.assertion('iesg_state', note="A document's 'draft-iesg' state should never be unset'. Failed for %s"%doc.name)
@@ -328,11 +347,11 @@ def document_main(request, name, rev=None):
328347
search_archive = quote(search_archive, safe="~")
329348

330349
# conflict reviews
331-
conflict_reviews = [d.document.name for d in doc.related_that("conflrev")]
350+
conflict_reviews = [r.source.name for r in interesting_relations_that.filter(relationship="conflrev")]
332351

333-
status_change_docs = doc.related_that(STATUSCHANGE_RELATIONS)
334-
status_changes = [ rel.document for rel in status_change_docs if rel.document.get_state_slug() in ('appr-sent','appr-pend')]
335-
proposed_status_changes = [ rel.document for rel in status_change_docs if rel.document.get_state_slug() in ('needshep','adrev','iesgeval','defer','appr-pr')]
352+
status_change_docs = interesting_relations_that.filter(relationship__in=STATUSCHANGE_RELATIONS)
353+
status_changes = [ r.source for r in status_change_docs if r.source.get_state_slug() in ('appr-sent','appr-pend')]
354+
proposed_status_changes = [ r.source for r in status_change_docs if r.source.get_state_slug() in ('needshep','adrev','iesgeval','defer','appr-pr')]
336355

337356
presentations = doc.future_presentations()
338357

@@ -454,14 +473,14 @@ def document_main(request, name, rev=None):
454473
submission=submission,
455474
resurrected_by=resurrected_by,
456475

457-
replaces=doc.related_that_doc("replaces"),
458-
replaced_by=doc.related_that("replaces"),
459-
possibly_replaces=doc.related_that_doc("possibly_replaces"),
460-
possibly_replaced_by=doc.related_that("possibly_replaces"),
461-
updates=doc.related_that_doc("updates"),
462-
updated_by=doc.related_that("updates"),
463-
obsoletes=doc.related_that_doc("obs"),
464-
obsoleted_by=doc.related_that("obs"),
476+
replaces=interesting_relations_that_doc.filter(relationship="replaces"),
477+
replaced_by=interesting_relations_that.filter(relationship="replaces"),
478+
possibly_replaces=interesting_relations_that_doc.filter(relationship="possibly_replaces"),
479+
possibly_replaced_by=interesting_relations_that.filter(relationship="possibly_replaces"),
480+
updates=interesting_relations_that_doc.filter(relationship="updates"),
481+
updated_by=interesting_relations_that.filter(relationship="updates"),
482+
obsoletes=interesting_relations_that_doc.filter(relationship="obs"),
483+
obsoleted_by=interesting_relations_that.filter(relationship="obs"),
465484
conflict_reviews=conflict_reviews,
466485
status_changes=status_changes,
467486
proposed_status_changes=proposed_status_changes,
@@ -565,6 +584,8 @@ def document_main(request, name, rev=None):
565584
if doc.get_state_slug() in ("iesgeval", ) and doc.active_ballot():
566585
ballot_summary = needed_ballot_positions(doc, list(doc.active_ballot().active_balloter_positions().values()))
567586

587+
conflictdoc = doc.related_that_doc('conflrev')[0].document
588+
568589
return render(request, "doc/document_conflict_review.html",
569590
dict(doc=doc,
570591
top=top,

ietf/templates/doc/document_draft.html

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@
5757
RFC - {{ doc.std_level }}
5858
({% if published %}{{ published.time|date:"F Y" }}{% else %}publication date unknown{% endif %}{% if has_errata %}; <a href="https://www.rfc-editor.org/errata_search.php?rfc={{ rfc_number }}" rel="nofollow">Errata</a>{% else %}; No errata{% endif %})
5959

60-
{% if obsoleted_by %}<div>Obsoleted by {{ obsoleted_by|urlize_doc_list|join:", " }}</div>{% endif %}
61-
{% if updated_by %}<div>Updated by {{ updated_by|urlize_doc_list|join:", " }}</div>{% endif %}
62-
{% if obsoletes %}<div>Obsoletes {{ obsoletes|urlize_doc_list|join:", " }}</div>{% endif %}
63-
{% if updates %}<div> Updates {{ updates|urlize_doc_list|join:", " }}</div>{% endif %}
64-
{% if status_changes %}<div>Status changed by {{ status_changes|join:", "|urlize_ietf_docs }}</div>{% endif %}
65-
{% if proposed_status_changes %}<div>Proposed status changed by {{ proposed_status_changes|join:", "|urlize_ietf_docs }}</div>{% endif %}
60+
{% if obsoleted_by %}<div>Obsoleted by {{ obsoleted_by|urlize_related_source_list|join:", " }}</div>{% endif %}
61+
{% if updated_by %}<div>Updated by {{ updated_by|urlize_related_source_list|join:", " }}</div>{% endif %}
62+
{% if obsoletes %}<div>Obsoletes {{ obsoletes|urlize_related_target_list|join:", " }}</div>{% endif %}
63+
{% if updates %}<div> Updates {{ updates|urlize_related_target_list|join:", " }}</div>{% endif %}
64+
{% if status_changes %}<div>Status changed by {{ status_changes|join:", "|urlize_related_source_list }}</div>{% endif %}
65+
{% if proposed_status_changes %}<div>Proposed status changed by {{ proposed_status_changes|join:", "|urlize_related_source_list }}</div>{% endif %}
6666
{% if rfc_aliases %}<div>Also known as {{ rfc_aliases|join:", "|urlize_ietf_docs }}</div>{% endif %}
6767
{% if draft_name %}<div>Was <a href="/doc/{{ draft_name}}/">{{ draft_name }}</a> {% if submission %}({{ submission|safe }}){% endif %}</div>{% endif %}
6868
{% else %}
@@ -117,7 +117,7 @@
117117
{% endif %}
118118
</td>
119119
<td>
120-
{{ replaces|urlize_doc_list|join:", "|default:"(None)" }}
120+
{{ replaces|urlize_related_target_list|join:", "|default:"(None)" }}
121121
</td>
122122
</tr>
123123
{% endif %}
@@ -128,7 +128,7 @@
128128
<th>Replaced by</th>
129129
<td class="edit"></td>
130130
<td>
131-
{{ replaced_by|urlize_doc_list|join:", " }}
131+
{{ replaced_by|urlize_related_source_list|join:", " }}
132132
</td>
133133
</tr>
134134
{% endif %}
@@ -144,7 +144,7 @@
144144
{% endif %}
145145
</td>
146146
<td>
147-
{{ possibly_replaces|urlize_doc_list|join:", " }}
147+
{{ possibly_replaces|urlize_related_target_list|join:", " }}
148148
</td>
149149
</tr>
150150
{% endif %}
@@ -159,7 +159,7 @@
159159
{% endif %}
160160
</td>
161161
<td>
162-
{{ possibly_replaced_by|urlize_doc_list|join:", " }}
162+
{{ possibly_replaced_by|urlize_related_source_list|join:", " }}
163163
</td>
164164
</tr>
165165
{% endif %}

0 commit comments

Comments
 (0)