Skip to content

Commit 8027025

Browse files
committed
Make obsoletes/updates/etc. lists links (with new urlize_ietf_docs template filter)
- Legacy-Id: 2020
1 parent 2ee2c4c commit 8027025

4 files changed

Lines changed: 23 additions & 9 deletions

File tree

ietf/idtracker/templatetags/ietf_filters.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
import django
55
from django import template
66
from django.utils.html import escape, fix_ampersands
7-
from django.template.defaultfilters import linebreaksbr, wordwrap
7+
from django.template.defaultfilters import linebreaksbr, wordwrap, stringfilter
88
from django.template import resolve_variable
9+
from django.utils.safestring import mark_safe, SafeData
910
try:
1011
from email import utils as emailutils
1112
except ImportError:
1213
from email import Utils as emailutils
1314
import re
1415
import datetime
1516
import types
16-
#from ietf.utils import log
1717

1818
register = template.Library()
1919

@@ -215,6 +215,20 @@ def rfclink(string):
215215
string = str(string);
216216
return "http://tools.ietf.org/html/rfc" + string;
217217

218+
@register.filter(name='urlize_ietf_docs')
219+
def urlize_ietf_docs(string, autoescape=None):
220+
"""
221+
Make occurrences of RFC NNNN and draft-foo-bar links to /doc/.
222+
"""
223+
if autoescape and not isinstance(string, SafeData):
224+
string = escape(string)
225+
string = re.sub("(?<!>)(RFC ?)0{0,3}(\d+)", "<a href=\"/doc/rfc\\2/\">\\1\\2</a>", string)
226+
string = re.sub("(?<!>)(draft-[-0-9a-zA-Z._+]+)", "<a href=\"/doc/\\1/\">\\1</a>", string)
227+
return mark_safe(string)
228+
urlize_ietf_docs.is_safe = True
229+
urlize_ietf_docs.needs_autoescape = True
230+
urlize_ietf_docs = stringfilter(urlize_ietf_docs)
231+
218232
@register.filter(name='dashify')
219233
def dashify(string):
220234
"""

ietf/templates/idrfc/doc_main_id.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
{% block doc_metatable %}
4141
<tr><td style="width:18ex;">Document type:</td><td>{{ info.type|escape }}
42-
{% with doc.replaces as r %}{% if r %}<br />Replaces {% for rep in r %}<a href="/doc/{{rep}}/">{{rep}}</a>{% if not forloop.last %}, {%endif%}{% endfor %}{% endif %}{% endwith %}
42+
{% with doc.replaces as r %}{% if r %}<br />Replaces {% filter urlize_ietf_docs %}{{ r|join:", "}}{% endfilter %}{% endif %}{% endwith %}
4343
</td></tr>
4444
<tr><td>Last updated:</td><td> {{ doc.publication_date|default:"(data missing)" }}</td></tr>
4545
<tr><td>State:</td><td>

ietf/templates/idrfc/doc_main_rfc.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@
3939

4040
{% block doc_metatable %}
4141
<tr><td style="width:18ex;">Document type:</td><td>RFC - {{ doc.maturity_level }}
42-
{% if doc.obsoleted_by %}<br />Obsoleted by {{ doc.obsoleted_by }}{%endif %}
43-
{% if doc.updated_by %}<br />Updated by {{ doc.updated_by }}{%endif %}
44-
{% if doc.obsoletes %}<br />Obsoletes {{ doc.obsoletes }}{%endif %}
45-
{% if doc.updates %}<br />Updates {{ doc.updates }}{%endif %}
42+
{% if doc.obsoleted_by %}<br />Obsoleted by {{ doc.obsoleted_by|urlize_ietf_docs }}{%endif %}
43+
{% if doc.updated_by %}<br />Updated by {{ doc.updated_by|urlize_ietf_docs }}{%endif %}
44+
{% if doc.obsoletes %}<br />Obsoletes {{ doc.obsoletes|urlize_ietf_docs }}{%endif %}
45+
{% if doc.updates %}<br />Updates {{ doc.updates|urlize_ietf_docs }}{%endif %}
4646
{% if doc.draft_name %}<br/ >Was <a href="/doc/{{ doc.draft_name}}/">{{doc.draft_name}}</a>{% endif %}
4747
</td></tr>
4848
<tr><td>Published:</td><td> {{ doc.publication_date|default:"(data missing)" }}</td></tr>

ietf/templates/idrfc/search_result_row.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@
4848
<td class="status">{{ doc.friendly_state|safe }}
4949
{% if not doc.rfc %}{{ doc.id|state_age_colored|safe }}{% endif %}
5050
{% if doc.rfc %}
51-
{% if doc.rfc.obsoleted_by %}<br />Obsoleted by {{ doc.rfc.obsoleted_by }}{%endif %}
52-
{% if doc.rfc.updated_by %}<br />Updated by {{ doc.rfc.updated_by }}{%endif %}
51+
{% if doc.rfc.obsoleted_by %}<br />Obsoleted by {{ doc.rfc.obsoleted_by|urlize_ietf_docs }}{%endif %}
52+
{% if doc.rfc.updated_by %}<br />Updated by {{ doc.rfc.updated_by|urlize_ietf_docs }}{%endif %}
5353
{% if doc.rfc.has_errata %}<br /><a href="http://www.rfc-editor.org/errata_search.php?rfc={{doc.rfc.rfc_number}}" rel="nofollow">Errata</a>{% endif %}
5454
{% else %}
5555
{% if doc.id.rfc_editor_state %}<br />RFC Editor State: <a href="http://www.rfc-editor.org/queue2.html#{{doc.id.draft_name}}">{{ doc.id.rfc_editor_state|escape }}</a>{% endif %}

0 commit comments

Comments
 (0)