From 799d3a1a3e90204923c0a74237478cca7f980180 Mon Sep 17 00:00:00 2001 From: Robert Sparks Date: Thu, 6 Jul 2023 17:24:05 -0500 Subject: [PATCH] fix: adjusted bibtex view and tests --- ietf/doc/tests.py | 6 ++-- ietf/doc/views_doc.py | 38 ++++++++++++++------------ ietf/templates/doc/document_bibtex.bib | 6 ++-- 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/ietf/doc/tests.py b/ietf/doc/tests.py index 158d2d7891..923d6fd959 100644 --- a/ietf/doc/tests.py +++ b/ietf/doc/tests.py @@ -1981,7 +1981,7 @@ def test_document_bibtex(self): r = self.client.get(url) entry = self._parse_bibtex_response(r)["rfc%s"%num] self.assertEqual(entry['series'], 'Request for Comments') - self.assertEqual(entry['number'], num) + self.assertEqual(int(entry['number']), num) self.assertEqual(entry['doi'], '10.17487/RFC%s'%num) self.assertEqual(entry['year'], '2010') self.assertEqual(entry['month'].lower()[0:3], 'oct') @@ -1995,7 +1995,7 @@ def test_document_bibtex(self): std_level_id = 'inf', time = datetime.datetime(1990, 4, 1, tzinfo=ZoneInfo(settings.TIME_ZONE)), ) - num = april1.rfc_number() + num = april1.rfc_number DocEventFactory.create( doc=april1, type='published_rfc', @@ -2007,7 +2007,7 @@ def test_document_bibtex(self): self.assertEqual(r.get('Content-Type'), 'text/plain; charset=utf-8') entry = self._parse_bibtex_response(r)["rfc%s"%num] self.assertEqual(entry['series'], 'Request for Comments') - self.assertEqual(entry['number'], num) + self.assertEqual(int(entry['number']), num) self.assertEqual(entry['doi'], '10.17487/RFC%s'%num) self.assertEqual(entry['year'], '1990') self.assertEqual(entry['month'].lower()[0:3], 'apr') diff --git a/ietf/doc/views_doc.py b/ietf/doc/views_doc.py index caa996dc34..c47f24a4e6 100644 --- a/ietf/doc/views_doc.py +++ b/ietf/doc/views_doc.py @@ -1241,31 +1241,35 @@ def document_bibtex(request, name, rev=None): doc = get_object_or_404(Document, docalias__name=name) - latest_revision = doc.latest_event(NewRevisionDocEvent, type="new_revision") - replaced_by = [d.name for d in doc.related_that("replaces")] - published = doc.latest_event(type="published_rfc") is not None - rfc = latest_revision.doc if latest_revision and latest_revision.doc.get_state_slug() == "rfc" else None - - if rev != None and rev != doc.rev: - # find the entry in the history - for h in doc.history_set.order_by("-time"): - if rev == h.rev: - doc = h - break - - if doc.type_id == "rfc": + doi = None + draft_became_rfc = None + replaced_by = None + latest_revision = None + if doc.type_id == "draft": + latest_revision = doc.latest_event(NewRevisionDocEvent, type="new_revision") + replaced_by = [d.name for d in doc.related_that("replaces")] + draft_became_rfc_alias = next(iter(doc.related_that_doc("became_rfc")), None) + + if rev != None and rev != doc.rev: + # find the entry in the history + for h in doc.history_set.order_by("-time"): + if rev == h.rev: + doc = h + break + + if draft_became_rfc_alias: + draft_became_rfc = draft_became_rfc_alias.document + + elif doc.type_id == "rfc": # This needs to be replaced with a lookup, as the mapping may change # over time. Probably by updating ietf/sync/rfceditor.py to add the # as a DocAlias, and use a method on Document to retrieve it. doi = f"10.17487/RFC{doc.rfc_number:04d}" - else: - doi = None return render(request, "doc/document_bibtex.bib", dict(doc=doc, replaced_by=replaced_by, - published=published, - rfc=rfc, + published_as=draft_became_rfc, latest_revision=latest_revision, doi=doi, ), diff --git a/ietf/templates/doc/document_bibtex.bib b/ietf/templates/doc/document_bibtex.bib index 5dda4649eb..2e4dc9c873 100644 --- a/ietf/templates/doc/document_bibtex.bib +++ b/ietf/templates/doc/document_bibtex.bib @@ -3,7 +3,7 @@ {% load ietf_filters %} {% load textfilters %} -{% if doc.get_state_slug == "rfc" %} +{% if doc.type_id == "rfc" %} {% if doc.stream|slugify == "legacy" %} % Datatracker information for RFCs on the Legacy Stream is unfortunately often % incorrect. Please correct the bibtex below based on the information in the @@ -16,7 +16,7 @@ @misc{ publisher = {RFC Editor}, doi = {% templatetag openbrace %}{{ doi }}{% templatetag closebrace %}, url = {% templatetag openbrace %}{{ doc.rfc_number|rfceditor_info_url }}{% templatetag closebrace %},{% else %} -{% if published %}%% You should probably cite rfc{{ latest_revision.doc.rfc_number }} instead of this I-D.{% else %}{% if replaced_by %}%% You should probably cite {{replaced_by|join:" or "}} instead of this I-D.{% else %} +{% if published_as %}%% You should probably cite rfc{{ published_as.rfc_number }} instead of this I-D.{% else %}{% if replaced_by %}%% You should probably cite {{replaced_by|join:" or "}} instead of this I-D.{% else %} {% if doc.rev != latest_revision.rev %}%% You should probably cite {{latest_revision.doc.name}}-{{latest_revision.rev}} instead of this revision.{%endif%}{% endif %}{% endif %} @techreport{% templatetag openbrace %}{{doc.name|slice:"6:"}}-{{doc.rev}}, number = {% templatetag openbrace %}{{doc.name}}-{{doc.rev}}{% templatetag closebrace %}, @@ -29,7 +29,7 @@ @techreport{ title = {% templatetag openbrace %}{% templatetag openbrace %}{{doc.title|texescape}}{% templatetag closebrace %}{% templatetag closebrace %}, pagetotal = {{ doc.pages }}, year = {{ doc.pub_date.year }}, - month = {{ doc.pub_date|date:"b" }},{% if not doc.rfc_number or doc.pub_date.day == 1 and doc.pub_date.month == 4 %} + month = {{ doc.pub_date|date:"b" }},{% if not doc.type_id == "rfc" or doc.pub_date.day == 1 and doc.pub_date.month == 4 %} day = {{ doc.pub_date.day }},{% endif %} abstract = {% templatetag openbrace %}{{ doc.abstract|clean_whitespace|texescape }}{% templatetag closebrace %}, {% templatetag closebrace %}