Refactored some document methods to align better with Django's get_absolute_url(), and added Person.get_absolute_uri()

- Legacy-Id: 17189
This commit is contained in:
Henrik Levkowetz 2020-01-07 13:33:02 +00:00
parent b2fc68a978
commit b14cba5f15
27 changed files with 63 additions and 54 deletions

View file

@ -1,4 +1,4 @@
# Copyright The IETF Trust 2010-2019, All Rights Reserved
# Copyright The IETF Trust 2010-2020, All Rights Reserved
# -*- coding: utf-8 -*-
from __future__ import absolute_import, print_function, unicode_literals
@ -189,11 +189,11 @@ class DocumentInfo(models.Model):
return revisions
def href(self, meeting=None):
def get_href(self, meeting=None):
return self._get_ref(meeting=meeting,meeting_doc_refs=settings.MEETING_DOC_HREFS)
def gref(self, meeting=None):
def get_versionless_href(self, meeting=None):
return self._get_ref(meeting=meeting,meeting_doc_refs=settings.MEETING_DOC_GREFS)
@ -626,7 +626,7 @@ class Document(DocumentInfo):
def get_absolute_url(self):
"""
Returns an url to the document view. This differs from .href(),
Returns an url to the document view. This differs from .get_href(),
which returns an url to the document content.
"""
if not hasattr(self, '_cached_absolute_url'):

View file

@ -1,4 +1,4 @@
# Copyright The IETF Trust 2011-2019, All Rights Reserved
# Copyright The IETF Trust 2011-2020, All Rights Reserved
# -*- coding: utf-8 -*-
@ -877,7 +877,7 @@ def build_doc_meta_block(doc, path):
# make current draft rev bold
line = re.sub(r'>(%s)<'%rev, r'><b>\g<1></b><', line)
line = re.sub(r'IPR declarations', r'<a class="text-warning" href="%s">IPR declarations</a>'%(ipr_url, ), line)
line = line.replace(r'[txt]', r'[<a href="%s">txt</a>]' % doc.href())
line = line.replace(r'[txt]', r'[<a href="%s">txt</a>]' % doc.get_href())
lines[i] = line
return lines
#

View file

@ -523,7 +523,7 @@ def document_main(request, name, rev=None):
top=top,
chartering=chartering,
content=content,
txt_url=doc.href(),
txt_url=doc.get_href(),
revisions=revisions,
latest_rev=latest_rev,
snapshot=snapshot,
@ -612,7 +612,7 @@ def document_main(request, name, rev=None):
content = None
other_types = []
globs = glob.glob(pathname + ".*")
url = doc.href()
url = doc.get_href()
urlbase, urlext = os.path.splitext(url)
for g in globs:
extension = os.path.splitext(g)[1]
@ -782,9 +782,9 @@ def document_history(request, name):
if name.startswith("charter"):
url = request.build_absolute_uri(urlreverse('ietf.doc.views_charter.charter_with_milestones_txt', kwargs=dict(name=e.doc.name, rev=e.rev)))
elif name.startswith("conflict-review"):
url = find_history_active_at(e.doc, e.time).href()
url = find_history_active_at(e.doc, e.time).get_href()
elif name.startswith("status-change"):
url = find_history_active_at(e.doc, e.time).href()
url = find_history_active_at(e.doc, e.time).get_href()
elif name.startswith("draft") or name.startswith("rfc"):
# rfcdiff tool has special support for IDs
url = e.doc.name + "-" + e.rev

View file

@ -1,4 +1,4 @@
# Copyright The IETF Trust 2007-2019, All Rights Reserved
# Copyright The IETF Trust 2007-2020, All Rights Reserved
# -*- coding: utf-8 -*-
@ -27,7 +27,7 @@ class LatestMeetingMaterialFeed(Feed):
title=doc.type_id,
group_acronym=doc.name.split("-")[2],
date=doc.time,
# FIXME: why isn't this using gref or href?
# FIXME: why isn't this using get_versionless_href or get_href?
link=self.base_url + os.path.join(doc.get_file_path(), doc.uploaded_filename)[len(settings.AGENDA_PATH):],
author=""
)

View file

@ -1,3 +1,4 @@
# Copyright The IETF Trust 2016-2020, All Rights Reserved
from django import template
import debug # pyflakes:ignore
@ -21,4 +22,4 @@ def status_for_meeting(group,meeting):
@register.filter
def meeting_href(doc,meeting):
return doc.href(meeting)
return doc.get_href(meeting)

View file

@ -1,4 +1,4 @@
# Copyright The IETF Trust 2009-2019, All Rights Reserved
# Copyright The IETF Trust 2009-2020, All Rights Reserved
# -*- coding: utf-8 -*-
@ -136,7 +136,7 @@ class MeetingTests(TestCase):
self.assertIn(time_interval, agenda_content)
# Make sure there's a frame for the agenda and it points to the right place
self.assertTrue(any([session.materials.get(type='agenda').href() in x.attrib["data-src"] for x in q('tr div.modal-body div.frame')]))
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')]))
# Make sure undeleted slides are present and deleted slides are not
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 @@ class MeetingTests(TestCase):
self.assertContains(r, "BEGIN:VTIMEZONE")
self.assertContains(r, "END:VTIMEZONE")
self.assertContains(r, session.agenda().href())
self.assertContains(r, session.materials.filter(type='slides').exclude(states__type__slug='slides',states__slug='deleted').first().href())
self.assertContains(r, session.agenda().get_href())
self.assertContains(r, session.materials.filter(type='slides').exclude(states__type__slug='slides',states__slug='deleted').first().get_href())
# TODO - the ics view uses .all on a queryset in a view so it's showing the deleted slides.
#self.assertNotContains(r, session.materials.filter(type='slides',states__type__slug='slides',states__slug='deleted').first().get_absolute_url())

View file

@ -1,4 +1,4 @@
# Copyright The IETF Trust 2007-2019, All Rights Reserved
# Copyright The IETF Trust 2007-2020, All Rights Reserved
# -*- coding: utf-8 -*-
@ -826,7 +826,7 @@ def week_view(request, num=None, name=None, owner=None):
item["room"] = a.timeslot.get_location()
if a.session and a.session.agenda():
item["agenda"] = a.session.agenda().href()
item["agenda"] = a.session.agenda().get_href()
if a.session.current_status == 'canceled':
item["name"] = "CANCELLED - " + item["name"]
@ -1007,10 +1007,10 @@ def json_agenda(request, num=None ):
if asgn.timeslot.location: # Some socials have an assignment but no location
locations.add(asgn.timeslot.location)
if asgn.session.agenda():
sessdict['agenda'] = asgn.session.agenda().href()
sessdict['agenda'] = asgn.session.agenda().get_href()
if asgn.session.minutes():
sessdict['minutes'] = asgn.session.minutes().href()
sessdict['minutes'] = asgn.session.minutes().get_href()
if asgn.session.slides():
sessdict['presentations'] = []
presentations = SessionPresentation.objects.filter(session=asgn.session, document__type__slug='slides')

View file

@ -1,4 +1,4 @@
# Copyright The IETF Trust 2010-2019, All Rights Reserved
# Copyright The IETF Trust 2010-2020, All Rights Reserved
# -*- coding: utf-8 -*-
@ -19,6 +19,7 @@ from django.core.exceptions import ObjectDoesNotExist
from django.core.validators import validate_email
from django.db import models
from django.template.loader import render_to_string
from django.urls import reverse as urlreverse
from django.utils.encoding import python_2_unicode_compatible, smart_bytes
from django.utils.text import slugify
@ -55,6 +56,8 @@ class Person(models.Model):
def __str__(self):
return self.plain_name()
def get_absolute_url(self):
return urlreverse('ietf.person.views.profile', kwargs={'email_or_name': self.name})
def name_parts(self):
return name_parts(self.name)
def ascii_parts(self):

View file

@ -1,4 +1,4 @@
# Copyright The IETF Trust 2014-2019, All Rights Reserved
# Copyright The IETF Trust 2014-2020, All Rights Reserved
# -*- coding: utf-8 -*-
@ -10,6 +10,7 @@ import six
from pyquery import PyQuery
from io import StringIO
from django.urls import reverse as urlreverse
from django.utils.encoding import iri_to_uri
import debug # pyflakes:ignore
@ -127,6 +128,10 @@ class PersonTests(TestCase):
self.assertContains(r, 'Merged', status_code=200)
self.assertFalse(Person.objects.filter(pk=p1.pk))
def test_absolute_url(self):
p = PersonFactory()
self.assertEqual(p.get_absolute_url(), iri_to_uri('/person/%s' % p.name))
class PersonUtilsTests(TestCase):
def test_determine_merge_order(self):
p1 = get_person_no_user()

View file

@ -65,7 +65,7 @@
<td>{{ session.group.acronym }}</td>
<td>{{ session.official_timeslotassignment.timeslot.time|date:"m-d H:i" }}</td>
<td class="document-name" >{{ recording.name }}</td>
<td><a href="{{ recording.href }}">{{ recording.href }}</a></td>
<td><a href="{{ recording.get_href }}">{{ recording.get_href }}</a></td>
<td><a href="{% url 'ietf.secr.proceedings.views.recording_edit' meeting_num=meeting.number name=recording.name %}">Edit</a></td>
</tr>
{% endfor %}

View file

@ -655,7 +655,7 @@
<div class="panel-heading">
This Internet-Draft is no longer active. A copy of
the expired Internet-Draft can be found at<br/>
<a href="{{doc.href}}">{{doc.href}}</a>
<a href="{{doc.get_href}}">{{doc.get_href}}</a>
</div>
<div class="panel-body">
<p>

View file

@ -10,7 +10,7 @@
<dt>Charter</dt>
<dd>
<a href="{{ doc.href }}"><span class="fa fa-file"></span></a>
<a href="{{ doc.get_href }}"><span class="fa fa-file"></span></a>
<a href="{{ doc.get_absolute_url }}">{{ doc.name}}-({{doc.rev}})</a>
</dd>

View file

@ -7,7 +7,7 @@
{% with doc.conflictdoc as conflictdoc %}
<dt>Conflict review</dt>
<dd>
<a href="{{doc.href}}">
<a href="{{doc.get_href}}">
<span class="fa fa-file"></span>
</a>
<a href="{% url "ietf.doc.views_doc.document_main" name=doc.canonical_name %}">{{ doc.canonical_name }}</a>

View file

@ -15,7 +15,7 @@
{% if rfc_number %}
<a href="https://www.rfc-editor.org/rfc/rfc{{rfc_number}}/">
{% else %}
<a href="{{doc.href}}">
<a href="{{doc.get_href}}">
{% endif %}
<span class="fa fa-file"></span></a>
{% endwith %}

View file

@ -3,12 +3,12 @@
{{ doc.title }}
<br><a href="{% url "ietf.doc.views_doc.document_main" name=doc.canonical_name %}">{{doc.canonical_name}}</a>
<a href="{{doc.href}}">[txt]</a>
<a href="{{doc.get_href}}">[txt]</a>
<div style="padding-left:20px">
{{ doc.conflictdoc.title }} ({{ doc.conflictdoc.stream }}: {{ doc.conflictdoc.intended_std_level }})
<br><a href="{% url "ietf.doc.views_doc.document_main" name=doc.conflictdoc.canonical_name %}">{{ doc.conflictdoc.canonical_name }}</a>
<a href="{{doc.conflictdoc.href}}">[txt]</a>
<a href="{{doc.conflictdoc.get_href}}">[txt]</a>
{% if doc.conflictdoc.note %}
<br>Note: {{ doc.conflictdoc.note|linebreaksbr }}
{% endif %}

View file

@ -6,7 +6,7 @@
{% if rfc_number %}
<a href="http://www.rfc-editor.org/rfc/rfc{{ rfc_number }}/">[txt]</a>
{% else %}
<a href="{{doc.href}}">[txt]</a>
<a href="{{doc.get_href}}">[txt]</a>
{% endif %}
{% endwith %}

View file

@ -141,7 +141,7 @@
<th class="text-nowrap">Attachments</th>
<td>
{% for doc in liaison.active_attachments.all %}
<a href="{{ doc.href }}">{{ doc.title }}</a>
<a href="{{ doc.get_href }}">{{ doc.title }}</a>
{% if not forloop.last %}<br>{% endif %}
{% empty %}
(None)

View file

@ -4,7 +4,7 @@
{% if attachments %}
<ul>
{% for doc in attachments %}
<li><a href="{{ doc.href }}">{{ doc.title }}</a><br>
<li><a href="{{ doc.get_href }}">{{ doc.title }}</a><br>
{% endfor %}
</ul>
{% else %}

View file

@ -15,7 +15,7 @@ Body: {{ liaison.body }}
Attachments:
{% for doc in liaison.attachments.all %}
{{ doc.title }}
{{ doc.href }}
{{ doc.get_href }}
{% empty %}
No document has been attached
{% endfor %}{% endautoescape %}

View file

@ -216,7 +216,7 @@
</td>
<td>
{% if item.session.agenda %}
<a href="{{ item.session.agenda.href }}">
<a href="{{ item.session.agenda.get_href }}">
{{item.timeslot.name}}
</a>
{% else %}
@ -238,7 +238,7 @@
{% include "meeting/session_buttons_include.html" %}
{% else %}
{% for slide in item.session.slides %}
<a href="{{slide.href}}">{{ slide.title|clean_whitespace }}</a>
<a href="{{slide.get_href}}">{{ slide.title|clean_whitespace }}</a>
<br>
{% endfor %}
{% endif %}
@ -301,7 +301,7 @@
<td>
{% if item.session.agenda %}
<a href="{{ item.session.agenda.href }}">
<a href="{{ item.session.agenda.get_href }}">
{% endif %}
{% if item.timeslot.type.slug == 'plenary' %}
{{item.timeslot.name}}

View file

@ -11,11 +11,11 @@ CLASS:PUBLIC
DTSTART{% if schedule.meeting.time_zone %};TZID="{{schedule.meeting.time_zone}}"{%endif%}:{{ item.timeslot.time|date:"Ymd" }}T{{item.timeslot.time|date:"Hi"}}00
DTEND{% if schedule.meeting.time_zone %};TZID="{{schedule.meeting.time_zone}}"{%endif%}:{{ item.timeslot.end_time|date:"Ymd" }}T{{item.timeslot.end_time|date:"Hi"}}00
DTSTAMP:{{ item.timeslot.modified|date:"Ymd" }}T{{ item.timeslot.modified|date:"His" }}Z
{% if item.session.agenda %}URL:{{item.session.agenda.gref}}
{% if item.session.agenda %}URL:{{item.session.agenda.get_versionless_href}}
DESCRIPTION:{{item.timeslot.name|ics_esc}}\n{% if item.session.agenda_note %}
Note: {{item.session.agenda_note|ics_esc}}\n{% endif %}{% for material in item.session.materials.all %}
\n{{material.type}}{% if material.type.name != "Agenda" %}
({{material.title|ics_esc}}){% endif %}:
{{material.gref}}\n{% endfor %}
{{material.get_versionless_href}}\n{% endfor %}
{% endif %}END:VEVENT
{% endif %}{% endfor %}END:VCALENDAR{% endcache %}{% endautoescape %}

View file

@ -90,7 +90,7 @@
{% if draft.time > old %}
<span class="small fa fa-bell-o" title="Last Update: {{ draft.time|utc|date:"Y-m-d H:i:s" }}&nbsp;UTC" ></span>
{% endif %}
<a href="{{ draft.href }}">{{ draft.name }}</a><br>
<a href="{{ draft.get_href }}">{{ draft.name }}</a><br>
{% empty %}
<span class="label label-warning">No drafts</span>
{% endfor %}

View file

@ -24,7 +24,7 @@
{% for ss in assignments %}
if (room_names.indexOf("{{ss.timeslot.get_hidden_location}}") >= 0 )
{
items.push({room_index:room_names.indexOf("{{ss.timeslot.get_hidden_location}}"),day:{{ss.day}}, delta_from_beginning:{{ss.delta_from_beginning}},time:"{{ss.timeslot.time|date:"Hi"}}-{{ss.timeslot.end_time|date:"Hi"}}", verbose_time:"{{ss.timeslot.time|date:"D M d Hi"}}-{{ss.timeslot.end_time|date:"Hi"}}",duration:{{ss.timeslot.duration.total_seconds}}, type:"{{ss.timeslot.type}}", {% if ss.session.name %}name:"{{ss.session.name|escapejs}}",{% if ss.session.group.acronym %} wg:"{{ss.session.group.acronym}}",{%endif%}{% else %}{% if ss.timeslot.type.name == "Break" %}name:"{{ss.timeslot.name|escapejs}}", area:"break", wg:"break",{% elif ss.timeslot.type.slug == "unavail" %}name:"Unavailable",{% else %}name:"{{ss.session.group.name|escapejs}}{%if ss.session.group.state.name == "BOF"%} BOF{%endif%}",wg:"{{ss.session.group.acronym}}",state:"{{ss.session.group.state}}",area:"{{ss.session.group.parent.acronym}}",{% endif %}{% endif %} dayname:"{{ ss.timeslot.time|date:"l"|upper }}, {{ ss.timeslot.time|date:"F j, Y" }}"{% if ss.session.agenda %}, agenda:"{{ss.session.agenda.href}}"{% endif %} });
items.push({room_index:room_names.indexOf("{{ss.timeslot.get_hidden_location}}"),day:{{ss.day}}, delta_from_beginning:{{ss.delta_from_beginning}},time:"{{ss.timeslot.time|date:"Hi"}}-{{ss.timeslot.end_time|date:"Hi"}}", verbose_time:"{{ss.timeslot.time|date:"D M d Hi"}}-{{ss.timeslot.end_time|date:"Hi"}}",duration:{{ss.timeslot.duration.total_seconds}}, type:"{{ss.timeslot.type}}", {% if ss.session.name %}name:"{{ss.session.name|escapejs}}",{% if ss.session.group.acronym %} wg:"{{ss.session.group.acronym}}",{%endif%}{% else %}{% if ss.timeslot.type.name == "Break" %}name:"{{ss.timeslot.name|escapejs}}", area:"break", wg:"break",{% elif ss.timeslot.type.slug == "unavail" %}name:"Unavailable",{% else %}name:"{{ss.session.group.name|escapejs}}{%if ss.session.group.state.name == "BOF"%} BOF{%endif%}",wg:"{{ss.session.group.acronym}}",state:"{{ss.session.group.state}}",area:"{{ss.session.group.parent.acronym}}",{% endif %}{% endif %} dayname:"{{ ss.timeslot.time|date:"l"|upper }}, {{ ss.timeslot.time|date:"F j, Y" }}"{% if ss.session.agenda %}, agenda:"{{ss.session.agenda.get_href}}"{% endif %} });
}
{% endfor %}
{% endautoescape %}

View file

@ -18,7 +18,7 @@
{% if agenda %}
{% if agenda.file_extension == "txt" or agenda.file_extension == "md" or agenda.file_extension == "html" or agenda.file_extension == "htm" %}
<h4>Agenda</h4>
<div class="frame" data-src="{{agenda.href}}"></div>
<div class="frame" data-src="{{agenda.get_href}}"></div>
{% else %}
<span class="label label-info">Agenda submitted as {{agenda.file_extension|upper}}</span>
{% endif %}
@ -33,7 +33,7 @@
{% for slide in item.session.slides %}
<li>
<span class="fa-li fa fa-file-{{slide.file_extension|lower}}-o"></span>
<a href="{{ slide.gref }}">{{ slide.title|clean_whitespace }}</a>
<a href="{{ slide.get_versionless_href }}">{{ slide.title|clean_whitespace }}</a>
</li>
{% endfor %}
</ul>
@ -43,7 +43,7 @@
{% if minutes %}
{% if minutes.file_extension == "txt" or minutes.file_extension == "md" or minutes.file_extension == "html" or minutes.file_extension == "htm" %}
<h4>Minutes</h4>
<div class="frame2" data-src="{{minutes.href}}"></div>
<div class="frame2" data-src="{{minutes.get_href}}"></div>
{% else %}
<span class="label label-info">Minutes submitted as {{minutes.file_extension|upper}}</span>
{% endif %}

View file

@ -61,24 +61,24 @@
<!-- There's no guaranteed order, so this is a bit messy: -->
<!-- First, the audio recordings, if any -->
{% for r in recordings %}
{% if r.href and 'audio' in r.href %}
<a class="btn btn-default btn-xs" href="{{ r.href }}" title="{{ r.title}}">
{% if r.get_href and 'audio' in r.get_href %}
<a class="btn btn-default btn-xs" href="{{ r.get_href }}" title="{{ r.title}}">
<span class="fa fa-file-audio-o"></span>
</a>
{% endif %}
{% endfor %}
<!-- Then the youtube recordings -->
{% for r in recordings %}
{% if r.href and 'youtu' in r.href %}
<a class="btn btn-default btn-xs" href="{{ r.href }}" title="{{ r.title }}">
{% if r.get_href and 'youtu' in r.get_href %}
<a class="btn btn-default btn-xs" href="{{ r.get_href }}" title="{{ r.title }}">
<span class="fa fa-file-video-o"></span>
</a>
{% endif %}
{% endfor %}
<!-- Finally, any other recordings -->
{% for r in recordings %}
{% if r.href and not 'audio' in r.href and not 'youtu' in r.href %}
<a class="btn btn-default btn-xs" href="{{ r.href }}" title="{{ r.title }}">
{% if r.get_href and not 'audio' in r.get_href and not 'youtu' in r.get_href %}
<a class="btn btn-default btn-xs" href="{{ r.get_href }}" title="{{ r.title }}">
<span class="fa fa-file-o"></span>
</a>
{% endif %}

View file

@ -29,7 +29,7 @@
<tr>
{% url 'ietf.doc.views_doc.document_main' name=pres.document.name as url %}
<td>
<a href="{{pres.document.href}}">{{pres.document.title}}</a>
<a href="{{pres.document.get_href}}">{{pres.document.title}}</a>
<a href="{{url}}">({{ pres.document.name }})</a>
</td>
{% if user|has_role:"Secretariat" or can_manage_materials %}
@ -71,7 +71,7 @@
<tr name="{{pres.document.name}}">
{% url 'ietf.doc.views_doc.document_main' name=pres.document.name as url %}
<td>
<a href="{{pres.document.href}}">{{pres.document.title}} </a>
<a href="{{pres.document.get_href}}">{{pres.document.title}} </a>
<a href="{{url}}">({{ pres.document.name }}) </a>
</td>
{% if can_manage_materials %}

View file

@ -11,11 +11,11 @@ CLASS:PUBLIC
DTSTART{% if item.schedule.meeting.time_zone %};TZID="{{item.schedule.meeting.time_zone}}"{%endif%}:{{ item.timeslot.time|date:"Ymd" }}T{{item.timeslot.time|date:"Hi"}}00
DTEND{% if item.schedule.meeting.time_zone %};TZID="{{item.schedule.meeting.time_zone}}"{%endif%}:{{ item.timeslot.end_time|date:"Ymd" }}T{{item.timeslot.end_time|date:"Hi"}}00
DTSTAMP:{{ item.timeslot.modified|date:"Ymd" }}T{{ item.timeslot.modified|date:"His" }}Z
{% if item.session.agenda %}URL:{{item.session.agenda.href}}
{% if item.session.agenda %}URL:{{item.session.agenda.get_href}}
DESCRIPTION:{{item.timeslot.name|ics_esc}}\n{% if item.session.agenda_note %}
Note: {{item.session.agenda_note|ics_esc}}\n{% endif %}{% for material in item.session.materials.all %}
\n{{material.type}}{% if material.type.name != "Agenda" %}
({{material.title|ics_esc}}){% endif %}:
{{material.href}}\n{% endfor %}
{{material.get_href}}\n{% endfor %}
{% endif %}END:VEVENT
{% endfor %}END:VCALENDAR{% endautoescape %}