Skip to content

Commit b14cba5

Browse files
committed
Refactored some document methods to align better with Django's get_absolute_url(), and added Person.get_absolute_uri()
- Legacy-Id: 17189
1 parent b2fc68a commit b14cba5

27 files changed

Lines changed: 63 additions & 54 deletions

ietf/doc/models.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright The IETF Trust 2010-2019, All Rights Reserved
1+
# Copyright The IETF Trust 2010-2020, All Rights Reserved
22
# -*- coding: utf-8 -*-
33
from __future__ import absolute_import, print_function, unicode_literals
44

@@ -189,11 +189,11 @@ def revisions(self):
189189
return revisions
190190

191191

192-
def href(self, meeting=None):
192+
def get_href(self, meeting=None):
193193
return self._get_ref(meeting=meeting,meeting_doc_refs=settings.MEETING_DOC_HREFS)
194194

195195

196-
def gref(self, meeting=None):
196+
def get_versionless_href(self, meeting=None):
197197
return self._get_ref(meeting=meeting,meeting_doc_refs=settings.MEETING_DOC_GREFS)
198198

199199

@@ -626,7 +626,7 @@ def __str__(self):
626626

627627
def get_absolute_url(self):
628628
"""
629-
Returns an url to the document view. This differs from .href(),
629+
Returns an url to the document view. This differs from .get_href(),
630630
which returns an url to the document content.
631631
"""
632632
if not hasattr(self, '_cached_absolute_url'):

ietf/doc/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright The IETF Trust 2011-2019, All Rights Reserved
1+
# Copyright The IETF Trust 2011-2020, All Rights Reserved
22
# -*- coding: utf-8 -*-
33

44

@@ -877,7 +877,7 @@ def add_markup(path, doc, lines):
877877
# make current draft rev bold
878878
line = re.sub(r'>(%s)<'%rev, r'><b>\g<1></b><', line)
879879
line = re.sub(r'IPR declarations', r'<a class="text-warning" href="%s">IPR declarations</a>'%(ipr_url, ), line)
880-
line = line.replace(r'[txt]', r'[<a href="%s">txt</a>]' % doc.href())
880+
line = line.replace(r'[txt]', r'[<a href="%s">txt</a>]' % doc.get_href())
881881
lines[i] = line
882882
return lines
883883
#

ietf/doc/views_doc.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ def document_main(request, name, rev=None):
523523
top=top,
524524
chartering=chartering,
525525
content=content,
526-
txt_url=doc.href(),
526+
txt_url=doc.get_href(),
527527
revisions=revisions,
528528
latest_rev=latest_rev,
529529
snapshot=snapshot,
@@ -612,7 +612,7 @@ def document_main(request, name, rev=None):
612612
content = None
613613
other_types = []
614614
globs = glob.glob(pathname + ".*")
615-
url = doc.href()
615+
url = doc.get_href()
616616
urlbase, urlext = os.path.splitext(url)
617617
for g in globs:
618618
extension = os.path.splitext(g)[1]
@@ -782,9 +782,9 @@ def document_history(request, name):
782782
if name.startswith("charter"):
783783
url = request.build_absolute_uri(urlreverse('ietf.doc.views_charter.charter_with_milestones_txt', kwargs=dict(name=e.doc.name, rev=e.rev)))
784784
elif name.startswith("conflict-review"):
785-
url = find_history_active_at(e.doc, e.time).href()
785+
url = find_history_active_at(e.doc, e.time).get_href()
786786
elif name.startswith("status-change"):
787-
url = find_history_active_at(e.doc, e.time).href()
787+
url = find_history_active_at(e.doc, e.time).get_href()
788788
elif name.startswith("draft") or name.startswith("rfc"):
789789
# rfcdiff tool has special support for IDs
790790
url = e.doc.name + "-" + e.rev

ietf/meeting/feeds.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright The IETF Trust 2007-2019, All Rights Reserved
1+
# Copyright The IETF Trust 2007-2020, All Rights Reserved
22
# -*- coding: utf-8 -*-
33

44

@@ -27,7 +27,7 @@ def items(self):
2727
title=doc.type_id,
2828
group_acronym=doc.name.split("-")[2],
2929
date=doc.time,
30-
# FIXME: why isn't this using gref or href?
30+
# FIXME: why isn't this using get_versionless_href or get_href?
3131
link=self.base_url + os.path.join(doc.get_file_path(), doc.uploaded_filename)[len(settings.AGENDA_PATH):],
3232
author=""
3333
)

ietf/meeting/templatetags/proceedings_filters.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# Copyright The IETF Trust 2016-2020, All Rights Reserved
12
from django import template
23

34
import debug # pyflakes:ignore
@@ -21,4 +22,4 @@ def status_for_meeting(group,meeting):
2122

2223
@register.filter
2324
def meeting_href(doc,meeting):
24-
return doc.href(meeting)
25+
return doc.get_href(meeting)

ietf/meeting/tests_views.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright The IETF Trust 2009-2019, All Rights Reserved
1+
# Copyright The IETF Trust 2009-2020, All Rights Reserved
22
# -*- coding: utf-8 -*-
33

44

@@ -136,7 +136,7 @@ def test_meeting_agenda(self):
136136
self.assertIn(time_interval, agenda_content)
137137

138138
# Make sure there's a frame for the agenda and it points to the right place
139-
self.assertTrue(any([session.materials.get(type='agenda').href() in x.attrib["data-src"] for x in q('tr div.modal-body div.frame')]))
139+
self.assertTrue(any([session.materials.get(type='agenda').get_href() in x.attrib["data-src"] for x in q('tr div.modal-body div.frame')]))
140140

141141
# Make sure undeleted slides are present and deleted slides are not
142142
self.assertTrue(any([session.materials.filter(type='slides').exclude(states__type__slug='slides',states__slug='deleted').first().title in x.text for x in q('tr div.modal-body ul a')]))
@@ -187,8 +187,8 @@ def test_meeting_agenda(self):
187187
self.assertContains(r, "BEGIN:VTIMEZONE")
188188
self.assertContains(r, "END:VTIMEZONE")
189189

190-
self.assertContains(r, session.agenda().href())
191-
self.assertContains(r, session.materials.filter(type='slides').exclude(states__type__slug='slides',states__slug='deleted').first().href())
190+
self.assertContains(r, session.agenda().get_href())
191+
self.assertContains(r, session.materials.filter(type='slides').exclude(states__type__slug='slides',states__slug='deleted').first().get_href())
192192
# TODO - the ics view uses .all on a queryset in a view so it's showing the deleted slides.
193193
#self.assertNotContains(r, session.materials.filter(type='slides',states__type__slug='slides',states__slug='deleted').first().get_absolute_url())
194194

ietf/meeting/views.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright The IETF Trust 2007-2019, All Rights Reserved
1+
# Copyright The IETF Trust 2007-2020, All Rights Reserved
22
# -*- coding: utf-8 -*-
33

44

@@ -826,7 +826,7 @@ def week_view(request, num=None, name=None, owner=None):
826826
item["room"] = a.timeslot.get_location()
827827

828828
if a.session and a.session.agenda():
829-
item["agenda"] = a.session.agenda().href()
829+
item["agenda"] = a.session.agenda().get_href()
830830

831831
if a.session.current_status == 'canceled':
832832
item["name"] = "CANCELLED - " + item["name"]
@@ -1007,10 +1007,10 @@ def json_agenda(request, num=None ):
10071007
if asgn.timeslot.location: # Some socials have an assignment but no location
10081008
locations.add(asgn.timeslot.location)
10091009
if asgn.session.agenda():
1010-
sessdict['agenda'] = asgn.session.agenda().href()
1010+
sessdict['agenda'] = asgn.session.agenda().get_href()
10111011

10121012
if asgn.session.minutes():
1013-
sessdict['minutes'] = asgn.session.minutes().href()
1013+
sessdict['minutes'] = asgn.session.minutes().get_href()
10141014
if asgn.session.slides():
10151015
sessdict['presentations'] = []
10161016
presentations = SessionPresentation.objects.filter(session=asgn.session, document__type__slug='slides')

ietf/person/models.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright The IETF Trust 2010-2019, All Rights Reserved
1+
# Copyright The IETF Trust 2010-2020, All Rights Reserved
22
# -*- coding: utf-8 -*-
33

44

@@ -19,6 +19,7 @@
1919
from django.core.validators import validate_email
2020
from django.db import models
2121
from django.template.loader import render_to_string
22+
from django.urls import reverse as urlreverse
2223
from django.utils.encoding import python_2_unicode_compatible, smart_bytes
2324
from django.utils.text import slugify
2425

@@ -55,6 +56,8 @@ class Person(models.Model):
5556

5657
def __str__(self):
5758
return self.plain_name()
59+
def get_absolute_url(self):
60+
return urlreverse('ietf.person.views.profile', kwargs={'email_or_name': self.name})
5861
def name_parts(self):
5962
return name_parts(self.name)
6063
def ascii_parts(self):

ietf/person/tests.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright The IETF Trust 2014-2019, All Rights Reserved
1+
# Copyright The IETF Trust 2014-2020, All Rights Reserved
22
# -*- coding: utf-8 -*-
33

44

@@ -10,6 +10,7 @@
1010
from pyquery import PyQuery
1111
from io import StringIO
1212
from django.urls import reverse as urlreverse
13+
from django.utils.encoding import iri_to_uri
1314

1415
import debug # pyflakes:ignore
1516

@@ -127,6 +128,10 @@ def test_merge_post(self):
127128
self.assertContains(r, 'Merged', status_code=200)
128129
self.assertFalse(Person.objects.filter(pk=p1.pk))
129130

131+
def test_absolute_url(self):
132+
p = PersonFactory()
133+
self.assertEqual(p.get_absolute_url(), iri_to_uri('/person/%s' % p.name))
134+
130135
class PersonUtilsTests(TestCase):
131136
def test_determine_merge_order(self):
132137
p1 = get_person_no_user()

ietf/secr/templates/proceedings/recording.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ <h2>{{ meeting }} - Recordings</h2>
6565
<td>{{ session.group.acronym }}</td>
6666
<td>{{ session.official_timeslotassignment.timeslot.time|date:"m-d H:i" }}</td>
6767
<td class="document-name" >{{ recording.name }}</td>
68-
<td><a href="{{ recording.href }}">{{ recording.href }}</a></td>
68+
<td><a href="{{ recording.get_href }}">{{ recording.get_href }}</a></td>
6969
<td><a href="{% url 'ietf.secr.proceedings.views.recording_edit' meeting_num=meeting.number name=recording.name %}">Edit</a></td>
7070
</tr>
7171
{% endfor %}

0 commit comments

Comments
 (0)