Skip to content

Commit

Permalink
fix: adjusted bibtex view and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rjsparks committed Jul 6, 2023
1 parent 400280e commit 799d3a1
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 23 deletions.
6 changes: 3 additions & 3 deletions ietf/doc/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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',
Expand All @@ -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')
Expand Down
38 changes: 21 additions & 17 deletions ietf/doc/views_doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
Expand Down
6 changes: 3 additions & 3 deletions ietf/templates/doc/document_bibtex.bib
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 %},
Expand All @@ -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 %}
Expand Down

0 comments on commit 799d3a1

Please sign in to comment.