Gather related document information a little more efficiently for the draft main view
- Legacy-Id: 19553
This commit is contained in:
parent
dd0e1496e6
commit
19fb998c95
|
@ -236,13 +236,31 @@ def urlize_ietf_docs(string, autoescape=None):
|
||||||
return mark_safe(string)
|
return mark_safe(string)
|
||||||
urlize_ietf_docs = stringfilter(urlize_ietf_docs)
|
urlize_ietf_docs = stringfilter(urlize_ietf_docs)
|
||||||
|
|
||||||
@register.filter(name='urlize_doc_list', is_safe=True, needs_autoescape=True)
|
@register.filter(name='urlize_related_source_list', is_safe=True, needs_autoescape=True)
|
||||||
def urlize_doc_list(docs, autoescape=None):
|
def urlize_related_source_list(related, autoescape=None):
|
||||||
"""Convert a list of DocAliases into list of links using canonical name"""
|
"""Convert a list of DocumentRelations into list of links using the source document's canonical name"""
|
||||||
links = []
|
links = []
|
||||||
for doc in docs:
|
for rel in related:
|
||||||
name=doc.document.canonical_name()
|
name=rel.source.canonical_name()
|
||||||
title = doc.document.title
|
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))
|
url = urlreverse('ietf.doc.views_doc.document_main', kwargs=dict(name=name))
|
||||||
if autoescape:
|
if autoescape:
|
||||||
name = escape(name)
|
name = escape(name)
|
||||||
|
|
|
@ -56,7 +56,8 @@ import debug # pyflakes:ignore
|
||||||
|
|
||||||
from ietf.doc.models import ( Document, DocAlias, DocHistory, DocEvent, BallotDocEvent, BallotType,
|
from ietf.doc.models import ( Document, DocAlias, DocHistory, DocEvent, BallotDocEvent, BallotType,
|
||||||
ConsensusDocEvent, NewRevisionDocEvent, TelechatDocEvent, WriteupDocEvent, IanaExpertDocEvent,
|
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,
|
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,
|
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,
|
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,
|
selected=tab,
|
||||||
name=name))
|
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):
|
def document_main(request, name, rev=None):
|
||||||
doc = get_object_or_404(Document.objects.select_related(), docalias__name=name)
|
doc = get_object_or_404(Document.objects.select_related(), docalias__name=name)
|
||||||
|
@ -128,9 +148,6 @@ def document_main(request, name, rev=None):
|
||||||
for a in aliases:
|
for a in aliases:
|
||||||
if a.startswith("rfc"):
|
if a.startswith("rfc"):
|
||||||
return redirect("ietf.doc.views_doc.document_main", name=a)
|
return redirect("ietf.doc.views_doc.document_main", name=a)
|
||||||
|
|
||||||
if doc.type_id == 'conflrev':
|
|
||||||
conflictdoc = doc.related_that_doc('conflrev')[0].document
|
|
||||||
|
|
||||||
revisions = []
|
revisions = []
|
||||||
for h in doc.history_set.order_by("time", "id"):
|
for h in doc.history_set.order_by("time", "id"):
|
||||||
|
@ -182,6 +199,8 @@ def document_main(request, name, rev=None):
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
interesting_relations_that, interesting_relations_that_doc = interesting_doc_relations(doc)
|
||||||
|
|
||||||
iesg_state = doc.get_state("draft-iesg")
|
iesg_state = doc.get_state("draft-iesg")
|
||||||
if isinstance(doc, Document):
|
if isinstance(doc, Document):
|
||||||
log.assertion('iesg_state', note="A document's 'draft-iesg' state should never be unset'. Failed for %s"%doc.name)
|
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="~")
|
search_archive = quote(search_archive, safe="~")
|
||||||
|
|
||||||
# conflict reviews
|
# 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_change_docs = interesting_relations_that.filter(relationship__in=STATUSCHANGE_RELATIONS)
|
||||||
status_changes = [ rel.document for rel in status_change_docs if rel.document.get_state_slug() in ('appr-sent','appr-pend')]
|
status_changes = [ r.source for r in status_change_docs if r.source.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')]
|
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()
|
presentations = doc.future_presentations()
|
||||||
|
|
||||||
|
@ -454,14 +473,14 @@ def document_main(request, name, rev=None):
|
||||||
submission=submission,
|
submission=submission,
|
||||||
resurrected_by=resurrected_by,
|
resurrected_by=resurrected_by,
|
||||||
|
|
||||||
replaces=doc.related_that_doc("replaces"),
|
replaces=interesting_relations_that_doc.filter(relationship="replaces"),
|
||||||
replaced_by=doc.related_that("replaces"),
|
replaced_by=interesting_relations_that.filter(relationship="replaces"),
|
||||||
possibly_replaces=doc.related_that_doc("possibly_replaces"),
|
possibly_replaces=interesting_relations_that_doc.filter(relationship="possibly_replaces"),
|
||||||
possibly_replaced_by=doc.related_that("possibly_replaces"),
|
possibly_replaced_by=interesting_relations_that.filter(relationship="possibly_replaces"),
|
||||||
updates=doc.related_that_doc("updates"),
|
updates=interesting_relations_that_doc.filter(relationship="updates"),
|
||||||
updated_by=doc.related_that("updates"),
|
updated_by=interesting_relations_that.filter(relationship="updates"),
|
||||||
obsoletes=doc.related_that_doc("obs"),
|
obsoletes=interesting_relations_that_doc.filter(relationship="obs"),
|
||||||
obsoleted_by=doc.related_that("obs"),
|
obsoleted_by=interesting_relations_that.filter(relationship="obs"),
|
||||||
conflict_reviews=conflict_reviews,
|
conflict_reviews=conflict_reviews,
|
||||||
status_changes=status_changes,
|
status_changes=status_changes,
|
||||||
proposed_status_changes=proposed_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():
|
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()))
|
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",
|
return render(request, "doc/document_conflict_review.html",
|
||||||
dict(doc=doc,
|
dict(doc=doc,
|
||||||
top=top,
|
top=top,
|
||||||
|
|
|
@ -57,12 +57,12 @@
|
||||||
RFC - {{ doc.std_level }}
|
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 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 obsoleted_by %}<div>Obsoleted by {{ obsoleted_by|urlize_related_source_list|join:", " }}</div>{% endif %}
|
||||||
{% if updated_by %}<div>Updated by {{ updated_by|urlize_doc_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_doc_list|join:", " }}</div>{% endif %}
|
{% if obsoletes %}<div>Obsoletes {{ obsoletes|urlize_related_target_list|join:", " }}</div>{% endif %}
|
||||||
{% if updates %}<div> Updates {{ updates|urlize_doc_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_ietf_docs }}</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_ietf_docs }}</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 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 %}
|
{% if draft_name %}<div>Was <a href="/doc/{{ draft_name}}/">{{ draft_name }}</a> {% if submission %}({{ submission|safe }}){% endif %}</div>{% endif %}
|
||||||
{% else %}
|
{% else %}
|
||||||
|
@ -117,7 +117,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ replaces|urlize_doc_list|join:", "|default:"(None)" }}
|
{{ replaces|urlize_related_target_list|join:", "|default:"(None)" }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -128,7 +128,7 @@
|
||||||
<th>Replaced by</th>
|
<th>Replaced by</th>
|
||||||
<td class="edit"></td>
|
<td class="edit"></td>
|
||||||
<td>
|
<td>
|
||||||
{{ replaced_by|urlize_doc_list|join:", " }}
|
{{ replaced_by|urlize_related_source_list|join:", " }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -144,7 +144,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ possibly_replaces|urlize_doc_list|join:", " }}
|
{{ possibly_replaces|urlize_related_target_list|join:", " }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -159,7 +159,7 @@
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
{{ possibly_replaced_by|urlize_doc_list|join:", " }}
|
{{ possibly_replaced_by|urlize_related_source_list|join:", " }}
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
Loading…
Reference in a new issue