From 63d80bff4cb6b6520c5c6dbe05214e734f600082 Mon Sep 17 00:00:00 2001 From: Lars Eggert Date: Tue, 21 Jun 2022 22:05:02 +0300 Subject: [PATCH] chore: Remove various unused template tags (#4101) * chore: Remove various unused template tags * Replace rfcnospace with parameterized prettystdname * Use URL resolver * Use the URL resolver more --- ietf/doc/templatetags/ietf_filters.py | 82 +------------------ .../templatetags/agenda_filter_tags.py | 20 ----- ietf/meeting/tests_views.py | 23 ------ ietf/templates/api/index.html | 2 +- ietf/templates/help/personal-information.html | 2 +- ietf/templates/ipr/search_doc_result.html | 6 +- .../templates/ipr/search_doctitle_result.html | 8 +- ietf/templates/ipr/search_wg_result.html | 8 +- ietf/templates/liaisons/field_help.html | 2 +- ietf/templates/liaisons/guide_from_ietf.html | 6 +- ietf/templates/liaisons/guide_to_ietf.html | 2 +- ietf/templates/meeting/agenda_filter.html | 1 - .../meeting/proceedings_progress_report.html | 2 +- ietf/templates/nomcom/announcements.html | 8 +- ietf/templates/person/profile.html | 2 +- ietf/templates/submit/submission_status.html | 4 +- 16 files changed, 28 insertions(+), 150 deletions(-) delete mode 100644 ietf/meeting/templatetags/agenda_filter_tags.py diff --git a/ietf/doc/templatetags/ietf_filters.py b/ietf/doc/templatetags/ietf_filters.py index 27487dd60..a0edacf41 100644 --- a/ietf/doc/templatetags/ietf_filters.py +++ b/ietf/doc/templatetags/ietf_filters.py @@ -6,8 +6,6 @@ import datetime import re from urllib.parse import urljoin -from email.utils import parseaddr - from django import template from django.conf import settings from django.utils.html import escape @@ -47,21 +45,6 @@ def unindent(value): """Remove indentation from string.""" return re.sub("\n +", "\n", value) -@register.filter -def strip_email(value): - """Get rid of email part of name/email string like 'Some Name '.""" - if not value: - return "" - if "@" not in value: - return value - return parseaddr(value)[0] - -@register.filter(name='fix_angle_quotes') -def fix_angle_quotes(value): - if "<" in value: - value = re.sub(r"<([\w\-\.]+@[\w\-\.]+)>", "<\1>", value) - return value - # there's an "ahref -> a href" in GEN_UTIL # but let's wait until we understand what that's for. @register.filter(name='make_one_per_line') @@ -142,44 +125,10 @@ def bracketpos(pos,posslug): register.filter('fill', fill) -@register.filter(name='rfcspace') -def rfcspace(string): - """ - If the string is an RFC designation, and doesn't have - a space between 'RFC' and the rfc-number, a space is - added - """ - string = str(string) - if string[:3].lower() == "rfc" and string[3] != " ": - return string[:3].upper() + " " + string[3:] - else: - return string - -@register.filter(name='rfcnospace') -def rfcnospace(string): - """ - If the string is an RFC designation, and does have - a space between 'RFC' and the rfc-number, remove it. - """ - string = str(string) - if string[:3].lower() == "rfc" and string[3] == " ": - return string[:3] + string[4:] - else: - return string - @register.filter -def prettystdname(string): +def prettystdname(string, space=" "): from ietf.doc.utils import prettify_std_name - return prettify_std_name(force_text(string or "")) - -@register.filter(name='rfcurl') -def rfclink(string): - """ - This takes just the RFC number, and turns it into the - URL for that RFC. - """ - string = str(string); - return "https://datatracker.ietf.org/doc/html/rfc" + string; + return prettify_std_name(force_text(string or ""), space) @register.filter def rfceditor_info_url(rfcnum : str): @@ -365,11 +314,6 @@ def underline(string): """Return string with an extra line underneath of dashes, for plain text underlining.""" return string + "\n" + ("-" * len(string)) -@register.filter(name='lstrip') -def lstripw(string, chars): - """Strip matching leading characters from words in string""" - return " ".join([word.lstrip(chars) for word in string.split()]) - @register.filter(name='timesince_days') def timesince_days(date): """Returns the number of days since 'date' (relative to now)""" @@ -378,14 +322,6 @@ def timesince_days(date): delta = datetime.datetime.now() - date return delta.days -@register.filter(name='truncate_ellipsis') -def truncate_ellipsis(text, arg): - num = int(arg) - if len(text) > num: - return escape(text[:num-1])+"…" - else: - return escape(text) - @register.filter def split(text, splitter=None): return text.split(splitter) @@ -399,11 +335,6 @@ def compress_empty_lines(text): text = re.sub("( *\n){3,}", "\n\n", text) return text -@register.filter(name="remove_empty_lines") -def remove_empty_lines(text): - text = re.sub("( *\n){2,}", "\n", text) - return text - @register.filter(name='linebreaks_crlf') def linebreaks_crlf(text): """ @@ -634,11 +565,6 @@ def lower_allcaps(text): result = result.replace(token, token.lower()) return result -@register.filter -def emailwrap(email): - email = str(email) - return mark_safe(email.replace('@', '@')) - @register.filter def document_content(doc): if doc is None: @@ -653,10 +579,6 @@ def format_timedelta(timedelta): minutes, seconds = divmod(remainder, 60) return '{hours:02d}:{minutes:02d}'.format(hours=hours,minutes=minutes) -@register.filter() -def nbsp(value): - return mark_safe(" ".join(value.split(' '))) - @register.filter() def comma_separated_list(seq, end_word="and"): if len(seq) < 2: diff --git a/ietf/meeting/templatetags/agenda_filter_tags.py b/ietf/meeting/templatetags/agenda_filter_tags.py deleted file mode 100644 index 8f9851815..000000000 --- a/ietf/meeting/templatetags/agenda_filter_tags.py +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright The IETF Trust 2020, All Rights Reserved -# -*- coding: utf-8 -*- - -"""Custom tags for the agenda filter template""" - -from django import template - -register = template.Library() - -@register.filter -def agenda_width_scale(filter_categories, spacer_scale): - """Compute the width scale for the agenda filter button table - - Button columns are spacer_scale times as wide as the spacer columns between - categories. There is one fewer spacer column than categories. - """ - category_count = len(filter_categories) - column_count = sum([len(cat) for cat in filter_categories]) - # Refuse to return less than 1 to avoid width calculation problems. - return max(spacer_scale * column_count + category_count - 1, 1) diff --git a/ietf/meeting/tests_views.py b/ietf/meeting/tests_views.py index 2ca1cabe7..a3351ffdc 100644 --- a/ietf/meeting/tests_views.py +++ b/ietf/meeting/tests_views.py @@ -6593,29 +6593,6 @@ class HasMeetingsTests(TestCase): class AgendaFilterTests(TestCase): """Tests for the AgendaFilter template""" - def test_agenda_width_scale_filter(self): - """Test calculation of UI column width by agenda_width_scale filter""" - template = Template('{% load agenda_filter_tags %}{{ categories|agenda_width_scale:spacing }}') - - # Should get '1' as min value when input is empty - context = Context({'categories': [], 'spacing': 7}) - self.assertEqual(template.render(context), '1') - - # 3 columns, no spacers - context = Context({'categories': [range(3)], 'spacing': 7}) - self.assertEqual(template.render(context), '21') - - # 6 columns, 1 spacer - context = Context({'categories': [range(3), range(3)], 'spacing': 7}) - self.assertEqual(template.render(context), '43') - - # 10 columns, 2 spacers - context = Context({'categories': [range(3), range(3), range(4)], 'spacing': 7}) - self.assertEqual(template.render(context), '72') - - # 10 columns, 2 spacers, different spacer scale - context = Context({'categories': [range(3), range(3), range(4)], 'spacing': 5}) - self.assertEqual(template.render(context), '52') def test_agenda_filter_template(self): """Test rendering of input data by the agenda filter template""" diff --git a/ietf/templates/api/index.html b/ietf/templates/api/index.html index 9d2fa24ce..a1bc93aec 100644 --- a/ietf/templates/api/index.html +++ b/ietf/templates/api/index.html @@ -284,7 +284,7 @@ $ curl -S -F "apikey=DgAAAMLSi3coaE5TjrRs518xO8eBRlCmFF3eQcC8_SjUTtRGLGiJh7-1SYP

When sending notifications to other APIs, the datatracker may sign information with a - + RFC 7515: JSON Web Signature (JWS) , diff --git a/ietf/templates/help/personal-information.html b/ietf/templates/help/personal-information.html index cc9288f43..8676472de 100644 --- a/ietf/templates/help/personal-information.html +++ b/ietf/templates/help/personal-information.html @@ -8,7 +8,7 @@ {% origin %}

Personal Information in the Datatracker

- RFC 3935, "A Mission Statement for the IETF" + RFC 3935, "A Mission Statement for the IETF" lays out the goal and the mission of the IETF as follows

diff --git a/ietf/templates/ipr/search_doc_result.html b/ietf/templates/ipr/search_doc_result.html index cd60bd99b..5a0186c8f 100644 --- a/ietf/templates/ipr/search_doc_result.html +++ b/ietf/templates/ipr/search_doc_result.html @@ -58,7 +58,7 @@ - Results for {{ doc.name|rfcspace|lstrip:"0"|urlize_ietf_docs }} ("{{ doc.document.title }}"){% if not forloop.first %}{% if doc.related %}, which was {{ doc.relation|lower }} {{ doc.related.source|rfcspace|lstrip:"0"|urlize_ietf_docs }} ("{{ doc.related.source.title }}"){% endif %}{% endif %} + Results for {{ doc.name|prettystdname|urlize_ietf_docs }} ("{{ doc.document.title }}"){% if not forloop.first %}{% if doc.related %}, which was {{ doc.relation|lower }} {{ doc.related.source|prettystdname|urlize_ietf_docs }} ("{{ doc.related.source.title }}"){% endif %}{% endif %} @@ -81,7 +81,7 @@ - No IPR disclosures have been submitted directly on {{ doc.name|rfcspace|lstrip:"0"|urlize_ietf_docs }}{% if iprs %}, + No IPR disclosures have been submitted directly on {{ doc.name|prettystdname|urlize_ietf_docs }}{% if iprs %}, but there are disclosures on {% if docs|length == 2 %}a related document{% else %}related documents{% endif %}, listed on this page{% endif %}. @@ -122,4 +122,4 @@ {% block js %} -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/ietf/templates/ipr/search_doctitle_result.html b/ietf/templates/ipr/search_doctitle_result.html index 8d0ecbadb..b7a8a8b31 100644 --- a/ietf/templates/ipr/search_doctitle_result.html +++ b/ietf/templates/ipr/search_doctitle_result.html @@ -28,9 +28,9 @@ - IPR that is related to {{ alias.name|lstrip:"0"|rfcnospace|urlize_ietf_docs }} ("{{ alias.document.title }}") + IPR that is related to {{ alias.name|prettystdname:""|urlize_ietf_docs }} ("{{ alias.document.title }}") {% if alias.related %} - that was {{ alias.relation|lower }} {{ alias.related.source.name|lstrip:"0"|rfcnospace|urlize_ietf_docs }} ("{{ alias.related.source.title }}") + that was {{ alias.relation|lower }} {{ alias.related.source.name|prettystdname:""|urlize_ietf_docs }} ("{{ alias.related.source.title }}") {% endif %} @@ -58,7 +58,7 @@ - No IPR disclosures related to {{ alias.name|lstrip:"0"|urlize_ietf_docs }} have been submitted. + No IPR disclosures related to {{ alias.name|prettystdname|urlize_ietf_docs }} have been submitted. {% endif %} @@ -68,4 +68,4 @@ {% endblock %} {% block js %} -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/ietf/templates/ipr/search_wg_result.html b/ietf/templates/ipr/search_wg_result.html index 20bf592f2..ae477a269 100644 --- a/ietf/templates/ipr/search_wg_result.html +++ b/ietf/templates/ipr/search_wg_result.html @@ -24,9 +24,9 @@ - IPR related to {{ alias.name|rfcspace|lstrip:"0"|urlize_ietf_docs }} ("{{ alias.document.title }}") + IPR related to {{ alias.name|prettystdname|urlize_ietf_docs }} ("{{ alias.document.title }}") {% if alias.related %} - that was {{ alias.relation|lower }} {{ alias.related.source|rfcspace|lstrip:"0"|urlize_ietf_docs }} ("{{ alias.related.source.title|escape }}") + that was {{ alias.relation|lower }} {{ alias.related.source|prettystdname|urlize_ietf_docs }} ("{{ alias.related.source.title|escape }}") {% endif %} {% if alias.product_of_this_wg %}, a product of the {{ q }} WG{% endif %} : @@ -57,7 +57,7 @@ - No IPR disclosures related to {{ alias.name|rfcspace|lstrip:"0" }} have been submitted. + No IPR disclosures related to {{ alias.name|prettystdname|urlize_ietf_docs }} have been submitted. {% endif %} @@ -68,4 +68,4 @@ {% endblock %} {% block js %} -{% endblock %} +{% endblock %} \ No newline at end of file diff --git a/ietf/templates/liaisons/field_help.html b/ietf/templates/liaisons/field_help.html index 799dee2a9..7d5b755ba 100644 --- a/ietf/templates/liaisons/field_help.html +++ b/ietf/templates/liaisons/field_help.html @@ -34,7 +34,7 @@

For definitive information on generating liaison statements, please see - RFC 4053 (BCP 103) "Procedures for Handling Liaison Statements to and from the IETF." + RFC 4053 (BCP 103) "Procedures for Handling Liaison Statements to and from the IETF."

diff --git a/ietf/templates/liaisons/guide_from_ietf.html b/ietf/templates/liaisons/guide_from_ietf.html index 6dee086f2..953f9f416 100644 --- a/ietf/templates/liaisons/guide_from_ietf.html +++ b/ietf/templates/liaisons/guide_from_ietf.html @@ -25,10 +25,10 @@

@@ -114,7 +114,7 @@

(1) Please see Section 4., "Approval and Transmission of Liaison Statements," of - + RFC 4052 for information on who may submit a liaison statement on behalf of an IETF entity, and who should be copied. diff --git a/ietf/templates/liaisons/guide_to_ietf.html b/ietf/templates/liaisons/guide_to_ietf.html index ff0ae590c..a0bbed0f2 100644 --- a/ietf/templates/liaisons/guide_to_ietf.html +++ b/ietf/templates/liaisons/guide_to_ietf.html @@ -19,7 +19,7 @@

For definitive information on generating liaison statements, please see - RFC 4053 (BCP 103) "Procedures for Handling Liaison Statements to and from the IETF." + RFC 4053 (BCP 103) "Procedures for Handling Liaison Statements to and from the IETF."

diff --git a/ietf/templates/meeting/agenda_filter.html b/ietf/templates/meeting/agenda_filter.html index 124032ee4..1e986fb94 100644 --- a/ietf/templates/meeting/agenda_filter.html +++ b/ietf/templates/meeting/agenda_filter.html @@ -6,7 +6,6 @@ Optional parameters: always_show - if False or absent, menu closes when not in use and "Customize" button is shown customize_button_text - text to show on the "Customize" button (defaults to "Customize...") {% endcomment %} -{% load agenda_filter_tags %}

diff --git a/ietf/templates/meeting/proceedings_progress_report.html b/ietf/templates/meeting/proceedings_progress_report.html index 10b688ada..a51fb01e6 100644 --- a/ietf/templates/meeting/proceedings_progress_report.html +++ b/ietf/templates/meeting/proceedings_progress_report.html @@ -54,7 +54,7 @@ {% for rfc in rfcs %}

- +
- {{ rfc.doc.canonical_name|rfcspace|upper }} + {{ rfc.doc.canonical_name|prettystdname }} {{ rfc.doc.intended_std_level.name }} diff --git a/ietf/templates/nomcom/announcements.html b/ietf/templates/nomcom/announcements.html index b126ecd2d..aa67fbb68 100644 --- a/ietf/templates/nomcom/announcements.html +++ b/ietf/templates/nomcom/announcements.html @@ -52,15 +52,15 @@

References

RFC {{ doc.rfc_number }} {{ doc.pub_date|date:"b Y"|title|nbsp }}{{ doc.pub_date|date:"b Y"|title }} {{ doc.title|urlize_ietf_docs }} {% with doc.referenced_by_rfcs.count as refbycount %} diff --git a/ietf/templates/submit/submission_status.html b/ietf/templates/submit/submission_status.html index 5f57001ce..b5c47ac75 100644 --- a/ietf/templates/submit/submission_status.html +++ b/ietf/templates/submit/submission_status.html @@ -51,7 +51,7 @@ will require additional consideration by the stream manager (for example, the IESG), and publication may be declined unless sufficient justification is provided. See - RFC 7322, section 4.1.1 + RFC 7322, section 4.1.1 for details.

{% endif %} @@ -598,4 +598,4 @@ {{ all_forms|merge_media:'js' }} -{% endblock %} +{% endblock %} \ No newline at end of file