Skip to content

Commit 63d80bf

Browse files
authored
chore: Remove various unused template tags (ietf-tools#4101)
* chore: Remove various unused template tags * Replace rfcnospace with parameterized prettystdname * Use URL resolver * Use the URL resolver more
1 parent bbeb9ae commit 63d80bf

16 files changed

Lines changed: 28 additions & 150 deletions

ietf/doc/templatetags/ietf_filters.py

Lines changed: 2 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import re
77
from urllib.parse import urljoin
88

9-
from email.utils import parseaddr
10-
119
from django import template
1210
from django.conf import settings
1311
from django.utils.html import escape
@@ -47,21 +45,6 @@ def unindent(value):
4745
"""Remove indentation from string."""
4846
return re.sub("\n +", "\n", value)
4947

50-
@register.filter
51-
def strip_email(value):
52-
"""Get rid of email part of name/email string like 'Some Name <email@example.com>'."""
53-
if not value:
54-
return ""
55-
if "@" not in value:
56-
return value
57-
return parseaddr(value)[0]
58-
59-
@register.filter(name='fix_angle_quotes')
60-
def fix_angle_quotes(value):
61-
if "<" in value:
62-
value = re.sub(r"<([\w\-\.]+@[\w\-\.]+)>", "&lt;\1&gt;", value)
63-
return value
64-
6548
# there's an "ahref -> a href" in GEN_UTIL
6649
# but let's wait until we understand what that's for.
6750
@register.filter(name='make_one_per_line')
@@ -142,44 +125,10 @@ def bracketpos(pos,posslug):
142125

143126
register.filter('fill', fill)
144127

145-
@register.filter(name='rfcspace')
146-
def rfcspace(string):
147-
"""
148-
If the string is an RFC designation, and doesn't have
149-
a space between 'RFC' and the rfc-number, a space is
150-
added
151-
"""
152-
string = str(string)
153-
if string[:3].lower() == "rfc" and string[3] != " ":
154-
return string[:3].upper() + " " + string[3:]
155-
else:
156-
return string
157-
158-
@register.filter(name='rfcnospace')
159-
def rfcnospace(string):
160-
"""
161-
If the string is an RFC designation, and does have
162-
a space between 'RFC' and the rfc-number, remove it.
163-
"""
164-
string = str(string)
165-
if string[:3].lower() == "rfc" and string[3] == " ":
166-
return string[:3] + string[4:]
167-
else:
168-
return string
169-
170128
@register.filter
171-
def prettystdname(string):
129+
def prettystdname(string, space=" "):
172130
from ietf.doc.utils import prettify_std_name
173-
return prettify_std_name(force_text(string or ""))
174-
175-
@register.filter(name='rfcurl')
176-
def rfclink(string):
177-
"""
178-
This takes just the RFC number, and turns it into the
179-
URL for that RFC.
180-
"""
181-
string = str(string);
182-
return "https://datatracker.ietf.org/doc/html/rfc" + string;
131+
return prettify_std_name(force_text(string or ""), space)
183132

184133
@register.filter
185134
def rfceditor_info_url(rfcnum : str):
@@ -365,11 +314,6 @@ def underline(string):
365314
"""Return string with an extra line underneath of dashes, for plain text underlining."""
366315
return string + "\n" + ("-" * len(string))
367316

368-
@register.filter(name='lstrip')
369-
def lstripw(string, chars):
370-
"""Strip matching leading characters from words in string"""
371-
return " ".join([word.lstrip(chars) for word in string.split()])
372-
373317
@register.filter(name='timesince_days')
374318
def timesince_days(date):
375319
"""Returns the number of days since 'date' (relative to now)"""
@@ -378,14 +322,6 @@ def timesince_days(date):
378322
delta = datetime.datetime.now() - date
379323
return delta.days
380324

381-
@register.filter(name='truncate_ellipsis')
382-
def truncate_ellipsis(text, arg):
383-
num = int(arg)
384-
if len(text) > num:
385-
return escape(text[:num-1])+"&hellip;"
386-
else:
387-
return escape(text)
388-
389325
@register.filter
390326
def split(text, splitter=None):
391327
return text.split(splitter)
@@ -399,11 +335,6 @@ def compress_empty_lines(text):
399335
text = re.sub("( *\n){3,}", "\n\n", text)
400336
return text
401337

402-
@register.filter(name="remove_empty_lines")
403-
def remove_empty_lines(text):
404-
text = re.sub("( *\n){2,}", "\n", text)
405-
return text
406-
407338
@register.filter(name='linebreaks_crlf')
408339
def linebreaks_crlf(text):
409340
"""
@@ -634,11 +565,6 @@ def lower_allcaps(text):
634565
result = result.replace(token, token.lower())
635566
return result
636567

637-
@register.filter
638-
def emailwrap(email):
639-
email = str(email)
640-
return mark_safe(email.replace('@', '<wbr>@'))
641-
642568
@register.filter
643569
def document_content(doc):
644570
if doc is None:
@@ -653,10 +579,6 @@ def format_timedelta(timedelta):
653579
minutes, seconds = divmod(remainder, 60)
654580
return '{hours:02d}:{minutes:02d}'.format(hours=hours,minutes=minutes)
655581

656-
@register.filter()
657-
def nbsp(value):
658-
return mark_safe("&nbsp;".join(value.split(' ')))
659-
660582
@register.filter()
661583
def comma_separated_list(seq, end_word="and"):
662584
if len(seq) < 2:

ietf/meeting/templatetags/agenda_filter_tags.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

ietf/meeting/tests_views.py

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6593,29 +6593,6 @@ def test_appears_on_announce(self):
65936593

65946594
class AgendaFilterTests(TestCase):
65956595
"""Tests for the AgendaFilter template"""
6596-
def test_agenda_width_scale_filter(self):
6597-
"""Test calculation of UI column width by agenda_width_scale filter"""
6598-
template = Template('{% load agenda_filter_tags %}{{ categories|agenda_width_scale:spacing }}')
6599-
6600-
# Should get '1' as min value when input is empty
6601-
context = Context({'categories': [], 'spacing': 7})
6602-
self.assertEqual(template.render(context), '1')
6603-
6604-
# 3 columns, no spacers
6605-
context = Context({'categories': [range(3)], 'spacing': 7})
6606-
self.assertEqual(template.render(context), '21')
6607-
6608-
# 6 columns, 1 spacer
6609-
context = Context({'categories': [range(3), range(3)], 'spacing': 7})
6610-
self.assertEqual(template.render(context), '43')
6611-
6612-
# 10 columns, 2 spacers
6613-
context = Context({'categories': [range(3), range(3), range(4)], 'spacing': 7})
6614-
self.assertEqual(template.render(context), '72')
6615-
6616-
# 10 columns, 2 spacers, different spacer scale
6617-
context = Context({'categories': [range(3), range(3), range(4)], 'spacing': 5})
6618-
self.assertEqual(template.render(context), '52')
66196596

66206597
def test_agenda_filter_template(self):
66216598
"""Test rendering of input data by the agenda filter template"""

ietf/templates/api/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ <h2 id="signing-keys">
284284
<p>
285285
When sending notifications to other APIs, the datatracker may sign
286286
information with a
287-
<a href="https://datatracker.ietf.org/doc/html/rfc7515">
287+
<a href="{% url 'ietf.doc.views_doc.document_html' name='rfc7515' %}">
288288
RFC
289289
7515: JSON Web Signature (JWS)
290290
</a>,

ietf/templates/help/personal-information.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
{% origin %}
99
<h1>Personal Information in the Datatracker</h1>
1010
<p>
11-
<a href="https://datatracker.ietf.org/doc/html/rfc3935">RFC 3935, "A Mission Statement for the IETF"</a>
11+
<a href="{% url 'ietf.doc.views_doc.document_html' name='rfc3935' %}">RFC 3935, "A Mission Statement for the IETF"</a>
1212
lays out
1313
the goal and the mission of the IETF as follows
1414
</p>

ietf/templates/ipr/search_doc_result.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
<tbody>
5959
<tr>
6060
<th scope="col" class="table-info" colspan="3">
61-
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 %}
61+
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 %}
6262
</th>
6363
</tr>
6464
</tbody>
@@ -81,7 +81,7 @@
8181
<td></td>
8282
<td></td>
8383
<td>
84-
No IPR disclosures have been submitted directly on {{ doc.name|rfcspace|lstrip:"0"|urlize_ietf_docs }}{% if iprs %},
84+
No IPR disclosures have been submitted directly on {{ doc.name|prettystdname|urlize_ietf_docs }}{% if iprs %},
8585
but there are disclosures on {% if docs|length == 2 %}a related document{% else %}related documents{% endif %}, listed on this page{% endif %}.
8686
</td>
8787
</tr>
@@ -122,4 +122,4 @@
122122

123123
{% block js %}
124124
<script src="{% static "ietf/js/list.js" %}"></script>
125-
{% endblock %}
125+
{% endblock %}

ietf/templates/ipr/search_doctitle_result.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@
2828
<tbody>
2929
<tr>
3030
<th scope="col" class="table-info" colspan="3">
31-
IPR that is related to {{ alias.name|lstrip:"0"|rfcnospace|urlize_ietf_docs }} ("{{ alias.document.title }}")
31+
IPR that is related to {{ alias.name|prettystdname:""|urlize_ietf_docs }} ("{{ alias.document.title }}")
3232
{% if alias.related %}
33-
that was {{ alias.relation|lower }} {{ alias.related.source.name|lstrip:"0"|rfcnospace|urlize_ietf_docs }} ("{{ alias.related.source.title }}")
33+
that was {{ alias.relation|lower }} {{ alias.related.source.name|prettystdname:""|urlize_ietf_docs }} ("{{ alias.related.source.title }}")
3434
{% endif %}
3535
</th>
3636
</tr>
@@ -58,7 +58,7 @@
5858
<tr>
5959
<td></td>
6060
<td></td>
61-
<td>No IPR disclosures related to {{ alias.name|lstrip:"0"|urlize_ietf_docs }} have been submitted.</td>
61+
<td>No IPR disclosures related to {{ alias.name|prettystdname|urlize_ietf_docs }} have been submitted.</td>
6262
</tr>
6363
{% endif %}
6464
</tbody>
@@ -68,4 +68,4 @@
6868
{% endblock %}
6969
{% block js %}
7070
<script src="{% static "ietf/js/list.js" %}"></script>
71-
{% endblock %}
71+
{% endblock %}

ietf/templates/ipr/search_wg_result.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
<tbody>
2525
<tr class="table-info">
2626
<th scope="col" colspan="3">
27-
IPR related to {{ alias.name|rfcspace|lstrip:"0"|urlize_ietf_docs }} ("{{ alias.document.title }}")
27+
IPR related to {{ alias.name|prettystdname|urlize_ietf_docs }} ("{{ alias.document.title }}")
2828
{% if alias.related %}
29-
that was {{ alias.relation|lower }} {{ alias.related.source|rfcspace|lstrip:"0"|urlize_ietf_docs }} ("{{ alias.related.source.title|escape }}")
29+
that was {{ alias.relation|lower }} {{ alias.related.source|prettystdname|urlize_ietf_docs }} ("{{ alias.related.source.title|escape }}")
3030
{% endif %}
3131
{% if alias.product_of_this_wg %}, a product of the {{ q }} WG{% endif %}
3232
:
@@ -57,7 +57,7 @@
5757
<td></td>
5858
<td></td>
5959
<td>
60-
No IPR disclosures related to <i>{{ alias.name|rfcspace|lstrip:"0" }}</i> have been submitted.
60+
No IPR disclosures related to <i>{{ alias.name|prettystdname|urlize_ietf_docs }}</i> have been submitted.
6161
</td>
6262
</tr>
6363
{% endif %}
@@ -68,4 +68,4 @@
6868
{% endblock %}
6969
{% block js %}
7070
<script src="{% static "ietf/js/list.js" %}"></script>
71-
{% endblock %}
71+
{% endblock %}

ietf/templates/liaisons/field_help.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ <h1>Liaison statement field help</h1>
3434
<p>
3535
For definitive information on generating liaison statements, please
3636
see
37-
<a href="{{ "4053"|rfcurl }}">RFC 4053 (BCP 103) "Procedures for Handling Liaison Statements to and from the IETF."</a>
37+
<a href="{% url 'ietf.doc.views_doc.document_html' name='rfc4053' %}">RFC 4053 (BCP 103) "Procedures for Handling Liaison Statements to and from the IETF."</a>
3838
</p>
3939
<table class="table table-sm table-striped tablesorter">
4040
<thead>

ietf/templates/liaisons/guide_from_ietf.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ <h1>
2525
</p>
2626
<ul>
2727
<li>
28-
<a href="{{ "4052"|rfcurl }}">RFC 4052 (BCP 102), "IAB Processes for Management of IETF Liaison Relationships"</a>
28+
<a href="{% url 'ietf.doc.views_doc.document_html' name='rfc4052' %}">RFC 4052 (BCP 102), "IAB Processes for Management of IETF Liaison Relationships"</a>
2929
</li>
3030
<li>
31-
<a href="{{ "4053"|rfcurl }}">RFC 4053 (BCP 103), "Procedures for Handling Liaison Statements to and from the IETF"</a>
31+
<a href="{% url 'ietf.doc.views_doc.document_html' name='rfc4053' %}">RFC 4053 (BCP 103), "Procedures for Handling Liaison Statements to and from the IETF"</a>
3232
</li>
3333
</ul>
3434
<table class="table table-sm table-striped tablesorter">
@@ -114,7 +114,7 @@ <h1>
114114
<p>
115115
<sup><small>(1)</small></sup> Please see Section 4., "Approval and Transmission of Liaison Statements,"
116116
of
117-
<a href="{{ "4052"|rfcurl }}">
117+
<a href="{% url 'ietf.doc.views_doc.document_html' name='rfc4052' %}">
118118
RFC 4052
119119
</a>
120120
for information on who may submit a liaison statement on behalf of an IETF entity, and who should be copied.

0 commit comments

Comments
 (0)