Skip to content

Commit c09fd9d

Browse files
larseggertrjsparks
andauthored
chore: Use URL resolver in more places (ietf-tools#4104)
* chore: Use URL resolver more * Use settings.IDTRACKER_BASE_URL * More fixes * Use URL resolver for things under /accounts * Use URL resolver for things under /stream * Use URL resolver for things under /iesg * Use URL resolver for things under /meeting * Fix bugs * Use URL resolver for things under /help * Use URL resolver for things under /ipr * More changes * Revert vnu.jar * Fix typos * Address review comments by @rjsparks Co-authored-by: Robert Sparks <rjsparks@nostrum.com>
1 parent 4f34c04 commit c09fd9d

61 files changed

Lines changed: 219 additions & 221 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

ietf/doc/templatetags/ietf_filters.py

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,14 @@ def find_unique(n):
169169
return ""
170170

171171

172-
def link_charter_doc_match1(match):
172+
def link_charter_doc_match(match):
173173
if not doc_canonical_name(match[0]):
174174
return match[0]
175-
return f'<a href="/doc/{match[1][:-1]}/{match[2]}/">{match[0]}</a>'
176-
177-
178-
def link_charter_doc_match2(match):
179-
if not doc_canonical_name(match[0]):
180-
return match[0]
181-
return f'<a href="/doc/{match[1][:-1]}/{match[2]}/">{match[0]}</a>'
175+
url = urlreverse(
176+
"ietf.doc.views_doc.document_main",
177+
kwargs=dict(name=match[1][:-1], rev=match[2]),
178+
)
179+
return f'<a href="{url}">{match[0]}</a>'
182180

183181

184182
def link_non_charter_doc_match(match):
@@ -187,20 +185,26 @@ def link_non_charter_doc_match(match):
187185
if not cname:
188186
return match[0]
189187
if name == cname:
190-
return f'<a href="/doc/{cname}/">{match[0]}</a>'
188+
url = urlreverse("ietf.doc.views_doc.document_main", kwargs=dict(name=cname))
189+
return f'<a href="{url}">{match[0]}</a>'
191190

192191
# if we get here, the name probably has a version number and/or extension at the end
193192
rev_split = re.search(r"^(" + re.escape(cname) + r")-(\d{2,})", name)
194193
if rev_split:
195194
name = rev_split.group(1)
196195
else:
197-
return f'<a href="/doc/{cname}/">{match[0]}</a>'
196+
url = urlreverse("ietf.doc.views_doc.document_main", kwargs=dict(name=cname))
197+
return f'<a href="{url}">{match[0]}</a>'
198198

199199
cname = doc_canonical_name(name)
200200
if not cname:
201201
return match[0]
202202
if name == cname:
203-
return f'<a href="/doc/{cname}/{rev_split.group(2)}/">{match[0]}</a>'
203+
url = urlreverse(
204+
"ietf.doc.views_doc.document_main",
205+
kwargs=dict(name=cname, rev=rev_split.group(2)),
206+
)
207+
return f'<a href="{url}">{match[0]}</a>'
204208

205209
# if we get here, we can't linkify
206210
return match[0]
@@ -211,44 +215,33 @@ def link_other_doc_match(match):
211215
rev = match[3]
212216
if not doc_canonical_name(doc + rev):
213217
return match[0]
214-
return f'<a href="/doc/{doc}{rev}/">{match[1]}</a>'
218+
url = urlreverse("ietf.doc.views_doc.document_main", kwargs=dict(name=doc + rev))
219+
return f'<a href="{url}">{match[1]}</a>'
215220

216221

217222
@register.filter(name="urlize_ietf_docs", is_safe=True, needs_autoescape=True)
218223
def urlize_ietf_docs(string, autoescape=None):
219224
"""
220-
Make occurrences of RFC NNNN and draft-foo-bar links to /doc/.
225+
Make occurrences of RFC NNNN and draft-foo-bar links to the doc pages.
221226
"""
222227
if autoescape and not isinstance(string, SafeData):
223228
if "<" in string:
224229
string = escape(string)
225230
else:
226231
string = mark_safe(string)
227-
exp1 = r"\b(?<![/\-:=#])(charter-(?:[\d\w\.+]+-)*)(\d{2}-\d{2})(\.(?:txt|ps|pdf|html))?\b"
228-
exp2 = r"\b(?<![/\-:=#])(charter-(?:[\d\w\.+]+-)*)(\d{2})(\.(?:txt|ps|pdf|html))?\b"
229-
if re.search(exp1, string):
230-
string = re.sub(
231-
exp1,
232-
link_charter_doc_match1,
233-
string,
234-
flags=re.IGNORECASE | re.ASCII,
235-
)
236-
elif re.search(exp2, string):
237-
string = re.sub(
238-
exp2,
239-
link_charter_doc_match2,
240-
string,
241-
flags=re.IGNORECASE | re.ASCII,
242-
)
232+
string = re.sub(
233+
r"\b(?<![/\-:=#])(charter-(?:[\d\w\.+]+-)*)(\d{2}(?:-\d{2}))(\.(?:txt|ps|pdf|html))?\b",
234+
link_charter_doc_match,
235+
string,
236+
flags=re.IGNORECASE | re.ASCII,
237+
)
243238
string = re.sub(
244239
r"\b(?<![/\-:=#])((?:draft-|bofreq-|conflict-review-|status-change-)[\d\w\.+-]+(?![-@]))",
245-
# r"\b(?<![/\-:=#])(((?:draft-|bofreq-|conflict-review-|status-change-)(?:[\d\w\.+]+-)*)([\d\w\.+]+?)(\.(?:txt|ps|pdf|html))?)\b(?![-@])",
246240
link_non_charter_doc_match,
247241
string,
248242
flags=re.IGNORECASE | re.ASCII,
249243
)
250244
string = re.sub(
251-
# r"\b((RFC|BCP|STD|FYI|(?:draft-|bofreq-|conflict-review-|status-change-|charter-)[-\d\w.+]+)\s*0*(\d+))\b",
252245
r"\b(?<![/\-:=#])((RFC|BCP|STD|FYI)\s*0*(\d+))\b",
253246
link_other_doc_match,
254247
string,

ietf/doc/tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1887,7 +1887,7 @@ def test_document_bibtex(self):
18871887
self.assertEqual(entry['year'], str(draft.pub_date().year))
18881888
self.assertEqual(entry['month'], draft.pub_date().strftime('%b').lower())
18891889
self.assertEqual(entry['day'], str(draft.pub_date().day))
1890-
self.assertEqual(entry['url'], f'https://datatracker.ietf.org/doc/html/{docname}')
1890+
self.assertEqual(entry['url'], settings.IDTRACKER_BASE_URL + urlreverse("ietf.doc.views_doc.document_main", kwargs=dict(name=draft.name, rev=draft.rev)))
18911891
#
18921892
self.assertNotIn('doi', entry)
18931893

ietf/doc/tests_bofreq.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ def test_start_new_bofreq(self):
322322
self.assertContains(r,'Fill in the details below. Keep items in the order they appear here.',status_code=200)
323323
r = self.client.post(url, dict(title='default',
324324
bofreq_submission='enter',
325-
bofreq_content=render_to_string('doc/bofreq/bofreq_template.md',{})))
325+
bofreq_content=render_to_string('doc/bofreq/bofreq_template.md',{'settings': settings})))
326326
self.assertContains(r, 'The example content may not be saved.', status_code=200)
327327
file = NamedTemporaryFile(delete=False,mode="w+",encoding='utf-8')
328328
file.write('some stuff')

ietf/doc/views_bofreq.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import io
66

77
from django import forms
8+
from django.conf import settings
89
from django.contrib.auth.decorators import login_required
910
from django.shortcuts import get_object_or_404, redirect, render
1011
from django.template.loader import render_to_string
@@ -57,7 +58,7 @@ def require_field(f):
5758
if submission_method == "enter":
5859
if require_field("bofreq_content"):
5960
content = self.cleaned_data["bofreq_content"].replace("\r", "")
60-
default_content = render_to_string('doc/bofreq/bofreq_template.md',{})
61+
default_content = render_to_string('doc/bofreq/bofreq_template.md', {'settings': settings})
6162
if content==default_content:
6263
raise forms.ValidationError('The example content may not be saved. Edit it as instructed to document this BOF request.')
6364
elif submission_method == "upload":
@@ -178,7 +179,7 @@ def new_bof_request(request):
178179
return redirect('ietf.doc.views_doc.document_main', name=bofreq.name)
179180

180181
else:
181-
init = {'bofreq_content':escape(render_to_string('doc/bofreq/bofreq_template.md',{})),
182+
init = {'bofreq_content':escape(render_to_string('doc/bofreq/bofreq_template.md',{'settings': settings})),
182183
'bofreq_submission':'enter',
183184
}
184185
form = NewBofreqForm(request.user.person, initial=init)
@@ -346,4 +347,4 @@ def change_state(request, name, option=None):
346347
doc=bofreq,
347348
login=login,
348349
help_url=urlreverse('ietf.doc.views_help.state_help', kwargs=dict(type="bofreq")),
349-
))
350+
))

ietf/doc/views_search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ def index_all_drafts(request):
547547

548548
names.sort(key=lambda t: t[1])
549549

550-
names = ['<a href="/doc/' + n + '/">' + n +'</a>'
550+
names = [f'<a href=\"{urlreverse("ietf.doc.views_doc.document_main", kwargs=dict(name=n))}\">{n}</a>'
551551
for n, __ in names if n not in names_to_skip]
552552

553553
categories.append((state,

ietf/ietfauth/views.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,11 +744,11 @@ def login(request, extra_context=None):
744744
logout(request)
745745
response = render(request, 'registration/missing_person.html')
746746
if require_consent:
747-
messages.warning(request, mark_safe('''
747+
messages.warning(request, mark_safe(f'''
748748
749749
You have personal information associated with your account which is not
750750
derived from draft submissions or other ietf work, namely: %s. Please go
751-
to your <a href="/accounts/profile">account profile</a> and review your
751+
to your <a href="{urlreverse("ietf.ietfauth.views.profile")}">account profile</a> and review your
752752
personal information, then scoll to the bottom and check the 'confirm'
753753
checkbox and submit the form, in order to to indicate that that the
754754
provided personal information may be used and displayed within the IETF

ietf/secr/templates/base_site.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ <h1 id="site-name">{% if user|has_role:"Secretariat" %} Secretariat Dashboard {%
1414
</td>
1515
<td class="text-end">
1616
<br>
17-
<span class="login">{% if user|has_role:"Secretariat" %}Secretariat {% endif %}Logged in: <a href="/accounts/profile/">{{ user }}</a> | <a rel="nofollow" href="/accounts/logout/">Log out</a></span>
17+
<span class="login">{% if user|has_role:"Secretariat" %}Secretariat {% endif %}Logged in: <a href="{% url 'ietf.ietfauth.views.profile' %}">{{ user }}</a> | <a rel="nofollow" href="{% url 'django.contrib.auth.views.logout' %}">Log out</a></span>
1818
</td>
1919
</tr>
2020
</tbody>
@@ -36,4 +36,4 @@ <h1 id="site-name">{% if user|has_role:"Secretariat" %} Secretariat Dashboard {%
3636
<a href="https://www.amsl.com/"><img src="{% static 'secr/images/ams_logo.png' %}" alt="AMS" class="text-end p-3" ></a>
3737
</div>
3838
</div>
39-
{% endblock %}
39+
{% endblock %}

ietf/secr/templates/base_site_bootstrap.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ <h1 id="site-name">{% if user|has_role:"Secretariat" %} Secretariat Dashboard {%
1414
</td>
1515
<td class="text-end">
1616
<br>
17-
<span class="login">{% if user|has_role:"Secretariat" %}Secretariat {% endif %}Logged in: <a href="/accounts/profile/">{{ user }}</a> | <a rel="nofollow" href="/accounts/logout/">Log out</a></span>
17+
<span class="login">{% if user|has_role:"Secretariat" %}Secretariat {% endif %}Logged in: <a href="{% url 'ietf.ietfauth.views.profile' %}">{{ user }}</a> | <a rel="nofollow" href="{% url 'django.contrib.auth.views.logout' %}">Log out</a></span>
1818
</td>
1919
</tr>
2020
</tbody>
@@ -36,4 +36,4 @@ <h1 id="site-name">{% if user|has_role:"Secretariat" %} Secretariat Dashboard {%
3636
<a href="https://www.amsl.com/"><img src="{% static 'secr/images/ams_logo.png' %}" alt="AMS" class="text-end p-3" ></a>
3737
</div>
3838
</div>
39-
{% endblock %}
39+
{% endblock %}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<ul>
2-
<li><a href="https://datatracker.ietf.org/meeting/{{ meeting.number }}/agenda.txt" target="_blank">View Agenda</a>.</li>
2+
<li><a href="{% url 'ietf.meeting.views.agenda' num=meeting.number ext='.txt' %}" target="_blank">View Agenda</a>.</li>
33
</ul>

ietf/secr/templates/proceedings/interim_directory.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ <h2>Interim Meeting Proceedings</h2>
1313
{% for meeting in meetings %}
1414
<tr class="{% cycle 'row1' 'row2' %}">
1515
<td class="text-start text-nowrap">{{ meeting.date }}</td>
16-
<td><a href="https://datatracker.ietf.org/wg/{{ meeting.group.acronym }}">{{ meeting.group.acronym }}</a></td>
16+
<td><a href="{% url 'ietf.group.views.group_home' acronym=meeting.group.acronym %}">{{ meeting.group.acronym }}</a></td>
1717
{% if meeting.schedule %}
1818
<td class="text-center"><a href="{{ meeting.schedule.get_absolute_url }}">Agenda</a></td>
1919
{% else %}
@@ -33,4 +33,4 @@ <h2>Interim Meeting Proceedings</h2>
3333
{% endfor %}
3434
</table>
3535

36-
{% endblock %}
36+
{% endblock %}

0 commit comments

Comments
 (0)