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 19fb998c95
This commit is contained in:
Robert Sparks 2021-11-08 18:39:32 +00:00
commit 5bfea0f0f3
3 changed files with 71 additions and 32 deletions

View file

@ -236,13 +236,31 @@ def urlize_ietf_docs(string, autoescape=None):
return mark_safe(string)
urlize_ietf_docs = stringfilter(urlize_ietf_docs)
@register.filter(name='urlize_doc_list', is_safe=True, needs_autoescape=True)
def urlize_doc_list(docs, autoescape=None):
"""Convert a list of DocAliases into list of links using canonical name"""
@register.filter(name='urlize_related_source_list', is_safe=True, needs_autoescape=True)
def urlize_related_source_list(related, autoescape=None):
"""Convert a list of DocumentRelations into list of links using the source document's canonical name"""
links = []
for doc in docs:
name=doc.document.canonical_name()
title = doc.document.title
for rel in related:
name=rel.source.canonical_name()
title = rel.source.title
url = urlreverse('ietf.doc.views_doc.document_main', kwargs=dict(name=name))
if autoescape:
name = escape(name)
title = escape(title)
links.append(mark_safe(
'<a href="%(url)s" title="%(title)s">%(name)s</a>' % dict(name=prettify_std_name(name),
title=title,
url=url)
))
return links
@register.filter(name='urlize_related_target_list', is_safe=True, needs_autoescape=True)
def urlize_related_target_list(related, autoescape=None):
"""Convert a list of DocumentRelations into list of links using the source document's canonical name"""
links = []
for rel in related:
name=rel.target.document.canonical_name()
title = rel.target.document.title
url = urlreverse('ietf.doc.views_doc.document_main', kwargs=dict(name=name))
if autoescape:
name = escape(name)

View file

@ -56,7 +56,8 @@ import debug # pyflakes:ignore
from ietf.doc.models import ( Document, DocAlias, DocHistory, DocEvent, BallotDocEvent, BallotType,
ConsensusDocEvent, NewRevisionDocEvent, TelechatDocEvent, WriteupDocEvent, IanaExpertDocEvent,
IESG_BALLOT_ACTIVE_STATES, STATUSCHANGE_RELATIONS, DocumentActionHolder, DocumentAuthor)
IESG_BALLOT_ACTIVE_STATES, STATUSCHANGE_RELATIONS, DocumentActionHolder, DocumentAuthor,
RelatedDocument, RelatedDocHistory)
from ietf.doc.utils import (add_links_in_new_revision_events, augment_events_with_revision,
can_adopt_draft, can_unadopt_draft, get_chartering_type, get_tags_for_stream_id,
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):
selected=tab,
name=name))
def interesting_doc_relations(doc):
if isinstance(doc, Document):
cls = RelatedDocument
target = doc
elif isinstance(doc, DocHistory):
cls = RelatedDocHistory
target = doc.doc
else:
raise TypeError("Expected this method to be called with a Document or DocHistory object")
that_relationships = STATUSCHANGE_RELATIONS + ('conflrev', 'replaces', 'possibly_replaces', 'updates', 'obs')
that_doc_relationships = ('replaces', 'possibly_replaces', 'updates', 'obs')
interesting_relations_that = cls.objects.filter(target__docs=target, relationship__in=that_relationships).select_related('source')
interesting_relations_that_doc = cls.objects.filter(source=doc, relationship__in=that_doc_relationships).prefetch_related('target__docs')
return interesting_relations_that, interesting_relations_that_doc
def document_main(request, name, rev=None):
doc = get_object_or_404(Document.objects.select_related(), docalias__name=name)
@ -129,9 +149,6 @@ def document_main(request, name, rev=None):
if a.startswith("rfc"):
return redirect("ietf.doc.views_doc.document_main", name=a)
if doc.type_id == 'conflrev':
conflictdoc = doc.related_that_doc('conflrev')[0].document
revisions = []
for h in doc.history_set.order_by("time", "id"):
if h.rev and not h.rev in revisions:
@ -182,6 +199,8 @@ def document_main(request, name, rev=None):
else:
pass
interesting_relations_that, interesting_relations_that_doc = interesting_doc_relations(doc)
iesg_state = doc.get_state("draft-iesg")
if isinstance(doc, Document):
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):
search_archive = quote(search_archive, safe="~")
# conflict reviews
conflict_reviews = [d.document.name for d in doc.related_that("conflrev")]
conflict_reviews = [r.source.name for r in interesting_relations_that.filter(relationship="conflrev")]
status_change_docs = doc.related_that(STATUSCHANGE_RELATIONS)
status_changes = [ rel.document for rel in status_change_docs if rel.document.get_state_slug() in ('appr-sent','appr-pend')]
proposed_status_changes = [ rel.document for rel in status_change_docs if rel.document.get_state_slug() in ('needshep','adrev','iesgeval','defer','appr-pr')]
status_change_docs = interesting_relations_that.filter(relationship__in=STATUSCHANGE_RELATIONS)
status_changes = [ r.source for r in status_change_docs if r.source.get_state_slug() in ('appr-sent','appr-pend')]
proposed_status_changes = [ r.source for r in status_change_docs if r.source.get_state_slug() in ('needshep','adrev','iesgeval','defer','appr-pr')]
presentations = doc.future_presentations()
@ -454,14 +473,14 @@ def document_main(request, name, rev=None):
submission=submission,
resurrected_by=resurrected_by,
replaces=doc.related_that_doc("replaces"),
replaced_by=doc.related_that("replaces"),
possibly_replaces=doc.related_that_doc("possibly_replaces"),
possibly_replaced_by=doc.related_that("possibly_replaces"),
updates=doc.related_that_doc("updates"),
updated_by=doc.related_that("updates"),
obsoletes=doc.related_that_doc("obs"),
obsoleted_by=doc.related_that("obs"),
replaces=interesting_relations_that_doc.filter(relationship="replaces"),
replaced_by=interesting_relations_that.filter(relationship="replaces"),
possibly_replaces=interesting_relations_that_doc.filter(relationship="possibly_replaces"),
possibly_replaced_by=interesting_relations_that.filter(relationship="possibly_replaces"),
updates=interesting_relations_that_doc.filter(relationship="updates"),
updated_by=interesting_relations_that.filter(relationship="updates"),
obsoletes=interesting_relations_that_doc.filter(relationship="obs"),
obsoleted_by=interesting_relations_that.filter(relationship="obs"),
conflict_reviews=conflict_reviews,
status_changes=status_changes,
proposed_status_changes=proposed_status_changes,
@ -565,6 +584,8 @@ def document_main(request, name, rev=None):
if doc.get_state_slug() in ("iesgeval", ) and doc.active_ballot():
ballot_summary = needed_ballot_positions(doc, list(doc.active_ballot().active_balloter_positions().values()))
conflictdoc = doc.related_that_doc('conflrev')[0].document
return render(request, "doc/document_conflict_review.html",
dict(doc=doc,
top=top,

View file

@ -57,12 +57,12 @@
RFC - {{ doc.std_level }}
({% 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 %})
{% if obsoleted_by %}<div>Obsoleted by {{ obsoleted_by|urlize_doc_list|join:", " }}</div>{% endif %}
{% if updated_by %}<div>Updated by {{ updated_by|urlize_doc_list|join:", " }}</div>{% endif %}
{% if obsoletes %}<div>Obsoletes {{ obsoletes|urlize_doc_list|join:", " }}</div>{% endif %}
{% if updates %}<div> Updates {{ updates|urlize_doc_list|join:", " }}</div>{% endif %}
{% if status_changes %}<div>Status changed by {{ status_changes|join:", "|urlize_ietf_docs }}</div>{% endif %}
{% if proposed_status_changes %}<div>Proposed status changed by {{ proposed_status_changes|join:", "|urlize_ietf_docs }}</div>{% endif %}
{% if obsoleted_by %}<div>Obsoleted by {{ obsoleted_by|urlize_related_source_list|join:", " }}</div>{% endif %}
{% if updated_by %}<div>Updated by {{ updated_by|urlize_related_source_list|join:", " }}</div>{% endif %}
{% if obsoletes %}<div>Obsoletes {{ obsoletes|urlize_related_target_list|join:", " }}</div>{% endif %}
{% if updates %}<div> Updates {{ updates|urlize_related_target_list|join:", " }}</div>{% endif %}
{% if status_changes %}<div>Status changed by {{ status_changes|join:", "|urlize_related_source_list }}</div>{% endif %}
{% if proposed_status_changes %}<div>Proposed status changed by {{ proposed_status_changes|join:", "|urlize_related_source_list }}</div>{% endif %}
{% if rfc_aliases %}<div>Also known as {{ rfc_aliases|join:", "|urlize_ietf_docs }}</div>{% endif %}
{% if draft_name %}<div>Was <a href="/doc/{{ draft_name}}/">{{ draft_name }}</a> {% if submission %}({{ submission|safe }}){% endif %}</div>{% endif %}
{% else %}
@ -117,7 +117,7 @@
{% endif %}
</td>
<td>
{{ replaces|urlize_doc_list|join:", "|default:"(None)" }}
{{ replaces|urlize_related_target_list|join:", "|default:"(None)" }}
</td>
</tr>
{% endif %}
@ -128,7 +128,7 @@
<th>Replaced by</th>
<td class="edit"></td>
<td>
{{ replaced_by|urlize_doc_list|join:", " }}
{{ replaced_by|urlize_related_source_list|join:", " }}
</td>
</tr>
{% endif %}
@ -144,7 +144,7 @@
{% endif %}
</td>
<td>
{{ possibly_replaces|urlize_doc_list|join:", " }}
{{ possibly_replaces|urlize_related_target_list|join:", " }}
</td>
</tr>
{% endif %}
@ -159,7 +159,7 @@
{% endif %}
</td>
<td>
{{ possibly_replaced_by|urlize_doc_list|join:", " }}
{{ possibly_replaced_by|urlize_related_source_list|join:", " }}
</td>
</tr>
{% endif %}