Skip to content

Commit 8f0b459

Browse files
refactor: Replace is_rfc() tests (ietf-tools#5925)
* refactor: Remove is_rfc() - test type_id instead * fix: Guard against unknown pub_date This should not ever come up - we have a published_rfc event for every rfc. Should investigate fixing pub_date() to always return a val.
1 parent 5d9d878 commit 8f0b459

12 files changed

Lines changed: 31 additions & 28 deletions

File tree

ietf/api/views.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,12 +317,9 @@ def get_previous_url(name, rev=None):
317317
previous_url = ''
318318
if condition in ('historic version', 'current version'):
319319
doc = history if history else document
320-
if found_rev:
321-
doc.is_rfc = lambda: False
322320
previous_url = doc.get_href()
323321
elif condition == 'version dochistory not found':
324322
document.rev = found_rev
325-
document.is_rfc = lambda: False
326323
previous_url = document.get_href()
327324
return previous_url
328325

@@ -335,7 +332,7 @@ def rfcdiff_latest_json(request, name, rev=None):
335332
raise Http404
336333
elif condition in ('historic version', 'current version'):
337334
doc = history if history else document
338-
if not found_rev and doc.is_rfc():
335+
if not found_rev and doc.type_id == "rfc":
339336
response['content_url'] = doc.get_href()
340337
response['name']=doc.canonical_name()
341338
if doc.name != doc.canonical_name():
@@ -345,7 +342,6 @@ def rfcdiff_latest_json(request, name, rev=None):
345342
response['previous'] = f'{doc.name}-{prev_rev}'
346343
response['previous_url'] = get_previous_url(doc.name, prev_rev)
347344
else:
348-
doc.is_rfc = lambda: False
349345
response['content_url'] = doc.get_href()
350346
response['rev'] = doc.rev
351347
response['name'] = doc.name
@@ -371,7 +367,6 @@ def rfcdiff_latest_json(request, name, rev=None):
371367
response['name'] = document.name
372368
response['rev'] = found_rev
373369
document.rev = found_rev
374-
document.is_rfc = lambda: False
375370
response['content_url'] = document.get_href()
376371
# not sure what to do if non-numeric values come back, so at least log it
377372
log.assertion('found_rev.isdigit()')

ietf/doc/forms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ def clean_rfc(self):
148148
raise forms.ValidationError("Please provide a referenced RFC and a referencing Internet-Draft")
149149

150150
rfc = self.cleaned_data['rfc']
151-
if not rfc.document.is_rfc():
151+
if rfc.type_id != "rfc":
152152
raise forms.ValidationError("Cannot find the RFC: " + rfc.name)
153153
return rfc
154154

ietf/doc/models.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def _get_ref(self, meeting=None, meeting_doc_refs=settings.MEETING_DOC_HREFS):
245245
format = settings.DOC_HREFS[self.type_id]
246246
elif self.type_id in settings.DOC_HREFS:
247247
self.is_meeting_related = False
248-
if self.is_rfc():
248+
if self.type_id == "rfc":
249249
format = settings.DOC_HREFS['rfc']
250250
else:
251251
format = settings.DOC_HREFS[self.type_id]
@@ -383,9 +383,6 @@ def friendly_state(self):
383383
else:
384384
return state.name
385385

386-
def is_rfc(self):
387-
return self.type_id == "rfc"
388-
389386
def author_list(self):
390387
best_addresses = []
391388
for author in self.documentauthor_set.all():
@@ -994,7 +991,7 @@ def pub_date(self):
994991
995992
This is the rfc publication date for RFCs, and the new-revision date for other documents.
996993
"""
997-
if self.is_rfc():
994+
if self.type_id == "rfc":
998995
# As of Sept 2022, in ietf.sync.rfceditor.update_docs_from_rfc_index() `published_rfc` events are
999996
# created with a timestamp whose date *in the PST8PDT timezone* is the official publication date
1000997
# assigned by the RFC editor.

ietf/doc/templatetags/ietf_filters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ def consensus(doc):
556556
@register.filter
557557
def std_level_to_label_format(doc):
558558
"""Returns valid Bootstrap classes to label a status level badge."""
559-
if doc.is_rfc():
559+
if doc.type_id == "rfc":
560560
if doc.related_that("obs"):
561561
return "obs"
562562
else:

ietf/doc/utils_search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def fill_in_document_table_attributes(docs, have_telechat_date=False):
9393
# emulate canonical name which is used by a lot of the utils
9494
# d.canonical_name = wrap_value(rfc_aliases[d.pk] if d.pk in rfc_aliases else d.name)
9595

96-
if d.is_rfc() and d.latest_event_cache["published_rfc"]:
96+
if d.type_id == "rfc" and d.latest_event_cache["published_rfc"]:
9797
d.latest_revision_date = d.latest_event_cache["published_rfc"].time
9898
elif d.latest_event_cache["new_revision"]:
9999
d.latest_revision_date = d.latest_event_cache["new_revision"].time

ietf/doc/views_ballot.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,13 @@ def approve_downrefs(request, name):
953953

954954
login = request.user.person
955955

956-
downrefs_to_rfc = [rel for rel in doc.relateddocument_set.all() if rel.is_downref() and not rel.is_approved_downref() and rel.target.document.is_rfc()]
956+
downrefs_to_rfc = [
957+
rel
958+
for rel in doc.relateddocument_set.all()
959+
if rel.is_downref()
960+
and not rel.is_approved_downref()
961+
and rel.target.document.type_id == "rfc"
962+
]
957963

958964
downrefs_to_rfc_qs = RelatedDocument.objects.filter(pk__in=[r.pk for r in downrefs_to_rfc])
959965

ietf/doc/views_doc.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def document_main(request, name, rev=None, document_html=False):
240240

241241

242242
# specific document types
243-
if doc.is_rfc():
243+
if doc.type_id == "rfc":
244244
split_content = request.COOKIES.get("full_draft", settings.USER_PREFERENCE_DEFAULTS["full_draft"]) == "off"
245245
if request.GET.get('include_text') == "0":
246246
split_content = True
@@ -988,7 +988,7 @@ def document_html(request, name, rev=None):
988988
doc = found.documents.get()
989989
rev = found.matched_rev
990990

991-
if not requested_rev and doc.is_rfc(): # Someone asked for /doc/html/8989
991+
if not requested_rev and doc.type_id == "rfc": # Someone asked for /doc/html/8989
992992
if not name.startswith('rfc'):
993993
return redirect('ietf.doc.views_doc.document_html', name=doc.canonical_name())
994994

@@ -998,7 +998,12 @@ def document_html(request, name, rev=None):
998998
if not os.path.exists(doc.get_file_name()):
999999
raise Http404("File not found: %s" % doc.get_file_name())
10001000

1001-
return document_main(request, name=doc.name if requested_rev else doc.canonical_name(), rev=doc.rev if requested_rev or not doc.is_rfc() else None, document_html=True)
1001+
return document_main(
1002+
request,
1003+
name=doc.name if requested_rev else doc.canonical_name(),
1004+
rev=doc.rev if requested_rev or doc.type_id != "rfc" else None,
1005+
document_html=True,
1006+
)
10021007

10031008
def document_pdfized(request, name, rev=None, ext=None):
10041009

@@ -1221,7 +1226,7 @@ def document_bibtex(request, name, rev=None):
12211226
doc = h
12221227
break
12231228

1224-
if doc.is_rfc():
1229+
if doc.type_id == "rfc":
12251230
# This needs to be replaced with a lookup, as the mapping may change
12261231
# over time. Probably by updating ietf/sync/rfceditor.py to add the
12271232
# as a DocAlias, and use a method on Document to retrieve it.

ietf/group/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ def group_documents_txt(request, acronym, group_type=None):
534534

535535
rows = []
536536
for d in itertools.chain(docs, docs_related):
537-
if d.is_rfc():
537+
if d.type_id == "rfc":
538538
name = str(d.rfc_number)
539539
else:
540540
name = "%s-%s" % (d.name, d.rev)

ietf/iesg/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ def agenda_json(request, date=None):
151151
if doc.type_id == "draft":
152152
docinfo['rev'] = doc.rev
153153
docinfo['intended-std-level'] = str(doc.intended_std_level)
154-
if doc.is_rfc():
154+
if doc.type_id == "rfc":
155155
docinfo['rfc-number'] = doc.rfc_number
156156

157157
iana_state = doc.get_state("draft-iana-review")

ietf/templates/doc/document_info.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@
1111
<th scope="row">{% if document_html %}Document type{% else %}Type{% endif %}</th>
1212
<td class="edit"></td>
1313
<td>
14-
{% if doc.is_rfc %}
14+
{% if doc.type_id == "rfc" %}
1515
<span class="text-success">RFC
1616
{% if not document_html %}
1717
- {{ doc.std_level }}
1818
{% else %}
1919
<span class="badge rounded-pill badge-{% if not snapshot %}{{ doc|std_level_to_label_format }}{% else %}draft{% endif %}">{{ doc.std_level }}</span>
2020
{% endif %}
2121
</span>
22-
{% if doc.is_rfc %}
22+
{% if doc.pub_date %}
2323
{% if document_html %}<br>{% else %}({% endif %}{{ doc.pub_date|date:"F Y" }}{% if not document_html %}){% endif %}
2424
{% else %}
2525
<span class="text-muted">(Publication date unknown)</span>
@@ -132,7 +132,7 @@
132132
</td>
133133
</tr>
134134
{% endif %}
135-
{% if not doc.is_rfc %}
135+
{% if doc.type_id != "rfc" %}
136136
{% if replaces or not document_html and can_edit_stream_info %}
137137
<tr>
138138
<td></td>
@@ -265,7 +265,7 @@
265265
{% endif %}
266266
</td>
267267
</tr>
268-
{% if not doc.is_rfc and not snapshot %}
268+
{% if doc.type_id != "rfc" and not snapshot %}
269269
<tr>
270270
<td></td>
271271
<th scope="row">
@@ -341,7 +341,7 @@
341341
</tr>
342342
{% endif %}
343343
{% endfor %}
344-
{% if not doc.is_rfc %}{# do not show reviews or conflict_reviews for RFCs, even if present #}
344+
{% if doc.type_id != "rfc" %}{# do not show reviews or conflict_reviews for RFCs, even if present #}
345345
{% if review_assignments or can_request_review %}
346346
<tr>
347347
<td></td>

0 commit comments

Comments
 (0)