From a6cc12c14b55137023f36b8d50a4149b786293bc Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Tue, 20 Jun 2023 20:07:45 +0300 Subject: [PATCH] fix: Don't (re)sort obsoleted/updated info (#5391) * fix: Don't (re)sort obsoleted/updated info Rebased against feat/postgres * Update ietf/doc/utils_search.py Co-authored-by: Robert Sparks * Update ietf/doc/utils_search.py Co-authored-by: Robert Sparks * Update ietf/doc/utils_search.py Co-authored-by: Robert Sparks * Fix review comments --------- Co-authored-by: Robert Sparks --- ietf/doc/utils_search.py | 33 ++++++++++++++++++++++++++------- ietf/doc/views_doc.py | 1 + 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/ietf/doc/utils_search.py b/ietf/doc/utils_search.py index 00046ed304..31aedda0d7 100644 --- a/ietf/doc/utils_search.py +++ b/ietf/doc/utils_search.py @@ -140,17 +140,36 @@ def fill_in_document_table_attributes(docs, have_telechat_date=False): d.obsoleted_by_list = [] d.updated_by_list = [] - xed_by = RelatedDocument.objects.filter(target__name__in=list(rfc_aliases.values()), - relationship__in=("obs", "updates")).select_related('target') - rel_rfc_aliases = dict([ (a.document.id, re.sub(r"rfc(\d+)", r"RFC \1", a.name, flags=re.IGNORECASE)) for a in DocAlias.objects.filter(name__startswith="rfc", docs__id__in=[rel.source_id for rel in xed_by]) ]) + # Revisit this block after RFCs become first-class Document objects + xed_by = list( + RelatedDocument.objects.filter( + target__name__in=list(rfc_aliases.values()), + relationship__in=("obs", "updates"), + ).select_related("target") + ) + rel_rfc_aliases = { + a.document.id: re.sub(r"rfc(\d+)", r"RFC \1", a.name, flags=re.IGNORECASE) + for a in DocAlias.objects.filter( + name__startswith="rfc", docs__id__in=[rel.source_id for rel in xed_by] + ) + } + xed_by.sort( + key=lambda rel: int( + re.sub( + r"rfc\s*(\d+)", + r"\1", + rel_rfc_aliases[rel.source_id], + flags=re.IGNORECASE, + ) + ) + ) for rel in xed_by: d = doc_dict[rel.target.document.id] + s = rel_rfc_aliases[rel.source_id] if rel.relationship_id == "obs": - l = d.obsoleted_by_list + d.obsoleted_by_list.append(s) elif rel.relationship_id == "updates": - l = d.updated_by_list - l.append(rel_rfc_aliases[rel.source_id]) - l.sort() + d.updated_by_list.append(s) def augment_docs_with_related_docs_info(docs): """Augment all documents with related documents information. diff --git a/ietf/doc/views_doc.py b/ietf/doc/views_doc.py index 39c8bf19be..b693f54e13 100644 --- a/ietf/doc/views_doc.py +++ b/ietf/doc/views_doc.py @@ -151,6 +151,7 @@ def interesting_doc_relations(doc): that_doc_relationships = ('replaces', 'possibly_replaces', 'updates', 'obs') + # TODO: This returns the relationships in database order, which may not be the order we want to display them in. 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')