Skip to content

Commit 6d7c5b5

Browse files
committed
Django 2.0 conversion. Test suite passes, except for javascript tests.
- Legacy-Id: 17762
1 parent 01027b9 commit 6d7c5b5

19 files changed

Lines changed: 185 additions & 203 deletions

ietf/dbtemplate/template.py

Lines changed: 44 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
from docutils.utils import SystemMessage
99
import debug # pyflakes:ignore
1010

11+
from django.template import Origin, TemplateDoesNotExist, Template as DjangoTemplate
1112
from django.template.loaders.base import Loader as BaseLoader
12-
from django.template.base import Template as DjangoTemplate, TemplateEncodingError # type: ignore
13-
from django.template.exceptions import TemplateDoesNotExist
14-
from django.utils.encoding import smart_text
1513

1614
from ietf.dbtemplate.models import DBTemplate
1715

@@ -20,15 +18,11 @@
2018
RST_TEMPLATE = os.path.join(BASE_DIR, 'resources/rst.txt')
2119

2220

23-
class Template(object):
21+
class Template(DjangoTemplate):
2422

25-
def __init__(self, template_string, origin=None, name='<Unknown Template>'):
26-
try:
27-
template_string = smart_text(template_string)
28-
except UnicodeDecodeError:
29-
raise TemplateEncodingError("Templates can only be constructed from unicode or UTF-8 strings.")
23+
def __init__(self, template_string, origin=None, name='<Unknown Template>', engine=None):
24+
super(Template, self).__init__(template_string, origin, name, engine)
3025
self.template_string = string.Template(template_string)
31-
self.name = name
3226

3327
def render(self, context):
3428
raise NotImplementedError
@@ -70,27 +64,43 @@ def __init__(self, engine):
7064
super(Loader, self).__init__(engine)
7165
self.is_usable = True
7266

73-
def load_template(self, template_name, template_dirs=None):
74-
try:
75-
template = DBTemplate.objects.get(path=template_name)
76-
if template.type.slug == 'rst':
77-
return (RSTTemplate(template.content), template)
78-
elif template.type.slug == 'django':
79-
return (DjangoTemplate(template.content), template)
80-
return (PlainTemplate(template.content), template)
81-
except DBTemplate.DoesNotExist:
82-
raise TemplateDoesNotExist(template_name)
83-
84-
85-
_loader = Loader(engine='django')
86-
87-
88-
def load_template_source(template_name, template_dirs=None):
89-
# For backwards compatibility
90-
import warnings
91-
warnings.warn(
92-
"'ietf.dbtemplate.template.load_template_source' is deprecated; use 'ietf.dbtemplate.template.Loader' instead.",
93-
PendingDeprecationWarning
94-
)
95-
return _loader.load_template_source(template_name, template_dirs)
96-
load_template_source.is_usable = True # type: ignore # https://github.com/python/mypy/issues/2087
67+
def get_template(self, template_name, skip=None):
68+
"""
69+
Call self.get_template_sources() and return a Template object for
70+
the first template matching template_name. If skip is provided, ignore
71+
template origins in skip. This is used to avoid recursion during
72+
template extending.
73+
"""
74+
tried = []
75+
76+
for origin in self.get_template_sources(template_name):
77+
if skip is not None and origin in skip:
78+
tried.append((origin, 'Skipped'))
79+
continue
80+
81+
try:
82+
template = DBTemplate.objects.get(path=origin)
83+
contents = template.content
84+
except DBTemplate.DoesNotExist:
85+
tried.append((origin, 'Source does not exist'))
86+
continue
87+
else:
88+
if template.type_id == 'rst':
89+
return RSTTemplate(contents, origin, origin.template_name, self.engine)
90+
elif template.type_id == 'plain':
91+
return PlainTemplate(contents, origin, origin.template_name, self.engine)
92+
elif template.type_id == 'django':
93+
return DjangoTemplate(contents, origin, origin.template_name, self.engine)
94+
else:
95+
return Template(contents, origin, origin.template_name, self.engine)
96+
97+
raise TemplateDoesNotExist(template_name, tried=tried)
98+
99+
def get_template_sources(self, template_name):
100+
for template in DBTemplate.objects.filter(path__endswith=template_name):
101+
yield Origin(
102+
name=template.path,
103+
template_name=template_name,
104+
loader=self,
105+
)
106+

ietf/group/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,6 +1000,7 @@ def diff(attr, name):
10001000
changed_personnel.update(set(old)^set(new))
10011001

10021002
if personnel_change_text!="":
1003+
changed_personnel = [ str(p) for p in changed_personnel ]
10031004
personnel_change_text = "%s has updated %s personnel:\n\n" % (request.user.person.plain_name(), group.acronym.upper() ) + personnel_change_text
10041005
email_personnel_change(request, group, personnel_change_text, changed_personnel)
10051006

ietf/meeting/tests_js.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,18 @@ def testUnschedule(self):
234234

235235
self.assertEqual(SchedTimeSessAssignment.objects.filter(session__meeting=meeting, session__group__acronym='mars', schedule__name='test-schedule').count(),1)
236236

237+
238+
ss = list(SchedTimeSessAssignment.objects.filter(session__meeting__number=72,session__group__acronym='mars',schedule__name='test-schedule')) # pyflakes:ignore
239+
debug.pprint('ss[0].json_dict("http:")')
240+
241+
237242
self.login()
238243
url = self.absreverse('ietf.meeting.views.edit_schedule',kwargs=dict(num='72',name='test-schedule',owner='plain@example.com'))
244+
js = self.absreverse('ietf.meeting.ajax.sessions_json', kwargs=dict(num='72'))
245+
debug.show('js')
246+
r = self.client.get(js) # pyflakes:ignore
247+
from ietf.utils.test_utils import unicontent # pyflakes:ignore
248+
debug.pprint('r.json()')
239249
self.driver.get(url)
240250

241251
s1 = Session.objects.filter(group__acronym='mars', meeting=meeting).first()

ietf/meeting/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2767,6 +2767,7 @@ def floor_plan(request, num=None, floor=None, ):
27672767
except FileNotFoundError:
27682768
raise Http404('Missing floorplan image for %s' % floor)
27692769
return render(request, 'meeting/floor-plan.html', {
2770+
"meeting": meeting,
27702771
"schedule": schedule,
27712772
"number": num,
27722773
"floors": floors,

ietf/person/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ def last_name(self):
9999
return name_parts(self.name)[3]
100100
def first_name(self):
101101
return name_parts(self.name)[1]
102+
def aliases(self):
103+
return [ str(a) for a in self.alias_set.all() ]
102104
def role_email(self, role_name, group=None):
103105
"""Lookup email for role for person, optionally on group which
104106
may be an object or the group acronym."""

ietf/settings.py

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,9 @@
1313
from typing import Any, Dict, List, Tuple # pyflakes:ignore
1414

1515
warnings.simplefilter("always", DeprecationWarning)
16+
warnings.filterwarnings("ignore", message="Add the `renderer` argument to the render\(\) method of", module="bootstrap3")
17+
warnings.filterwarnings("ignore", message="The logout\(\) view is superseded by")
1618
warnings.filterwarnings("ignore", message="Report.file_reporters will no longer be available in Coverage.py 4.2", module="coverage.report")
17-
warnings.filterwarnings("ignore", message="The popen2 module is deprecated. Use the subprocess module.", module="ietf.utils.pipe")
18-
warnings.filterwarnings("ignore", message="Usage of field.rel has been deprecated. Use field.remote_field instead.", module="tastypie.resources")
19-
warnings.filterwarnings("ignore", message="Importing from django.core.urlresolvers is deprecated in favor of django.urls.", module="tastypie.resources")
20-
warnings.filterwarnings("ignore", message="on_delete will be a required arg for OneToOneField in Django 2.0.", module="tastypie")
21-
warnings.filterwarnings("ignore", message=r"The load_template\(\) method is deprecated. Use get_template\(\) instead.")
22-
warnings.filterwarnings("ignore", message="escape isn't the last filter in")
23-
warnings.filterwarnings("ignore", message="Deprecated allow_tags attribute used on field")
24-
warnings.filterwarnings("ignore", message="You passed a bytestring as `filenames`. This will not work on Python 3.")
25-
warnings.filterwarnings("ignore", message="django.forms.extras is deprecated.", module="bootstrap3")
26-
warnings.filterwarnings("ignore", message="defusedxml.lxml is no longer supported and will be removed in a future release.", module="tastypie")
27-
warnings.filterwarnings("ignore", message="Duplicate index '.*' defined on the table")
28-
# Warnings found under Python 3.7:
29-
warnings.filterwarnings("ignore", message="Using or importing the ABCs from 'collections' instead of from 'collections.abc' is deprecated")
30-
warnings.filterwarnings("ignore", message="'U' mode is deprecated", module="docutils.io")
31-
warnings.filterwarnings("ignore", message="'U' mode is deprecated", module="xml2rfc")
32-
warnings.filterwarnings("ignore", message="'U' mode is deprecated", module="site")
33-
warnings.filterwarnings("ignore", message="Flags not at the start of the expression", module="genshi")
34-
warnings.filterwarnings("ignore", message="Flags not at the start of the expression", module="coverage")
35-
warnings.filterwarnings("ignore", message="encodestring\(\) is a deprecated alias since 3.1, use encodebytes\(\)")
3619

3720

3821
try:
@@ -367,7 +350,6 @@ def skip_unreadable_post(record):
367350
'django.middleware.common.CommonMiddleware',
368351
'django.contrib.sessions.middleware.SessionMiddleware',
369352
'django.contrib.auth.middleware.AuthenticationMiddleware',
370-
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
371353
'django.contrib.messages.middleware.MessageMiddleware',
372354
'django.middleware.http.ConditionalGetMiddleware',
373355
'simple_history.middleware.HistoryRequestMiddleware',
@@ -901,7 +883,6 @@ def skip_unreadable_post(record):
901883
SECR_PPT2PDF_COMMAND = ['/usr/bin/soffice','--headless','--convert-to','pdf:writer_globaldocument_pdf_Export','--outdir']
902884
STATS_REGISTRATION_ATTENDEES_JSON_URL = 'https://ietf.org/registration/attendees/{number}'
903885
NEW_PROCEEDINGS_START = 95
904-
USE_ETAGS=True
905886
YOUTUBE_API_KEY = ''
906887
YOUTUBE_API_SERVICE_NAME = 'youtube'
907888
YOUTUBE_API_VERSION = 'v3'
@@ -1061,7 +1042,6 @@ def skip_unreadable_post(record):
10611042
]
10621043

10631044
CHECKS_LIBRARY_PATCHES_TO_APPLY = [
1064-
'patch/fix-django-unicode-comparison-bug.patch',
10651045
'patch/fix-unidecode-argument-warning.patch',
10661046
'patch/fix-request-profiler-streaming-length.patch',
10671047
]

ietf/sync/iana.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def fetch_changes_json(url, start, end):
6868
# HTTP basic auth
6969
username = "ietfsync"
7070
password = settings.IANA_SYNC_PASSWORD
71-
headers = { "Authorization": "Basic %s" % force_str(base64.encodestring(smart_bytes("%s:%s" % (username, password)))).replace("\n", "") }
71+
headers = { "Authorization": "Basic %s" % force_str(base64.encodebytes(smart_bytes("%s:%s" % (username, password)))).replace("\n", "") }
7272
text = requests.get(url, headers=headers).text
7373
return text
7474

ietf/sync/rfceditor.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ def post_approved_draft(url, name):
532532
headers = {
533533
"Content-type": "application/x-www-form-urlencoded",
534534
"Accept": "text/plain",
535-
"Authorization": "Basic %s" % force_str(base64.encodestring(smart_bytes("%s:%s" % (username, password)))).replace("\n", ""),
535+
"Authorization": "Basic %s" % force_str(base64.encodebytes(smart_bytes("%s:%s" % (username, password)))).replace("\n", ""),
536536
}
537537

538538
log("Posting RFC-Editor notifcation of approved draft '%s' to '%s'" % (name, url))

ietf/templates/meeting/agenda_by_room.html

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

1919
{% block content %}
2020

21-
{% include "meeting/meeting_heading.html" with meeting=schedule.meeting updated=meeting.updated selected="by-room" title_extra="by Room" %}
21+
{% include "meeting/meeting_heading.html" with updated=meeting.updated selected="by-room" title_extra="by Room" %}
2222

2323
<ul class="daylist">
2424
{% for day,sessions in ss_by_day.items %}

ietf/templates/meeting/agenda_by_type.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
{% block title %}Agenda for {{meeting}} by Session Type{% endblock %}
2828

2929
{% block content %}
30-
{% include "meeting/meeting_heading.html" with meeting=schedule.meeting updated=meeting.updated selected="by-type" title_extra="by Session Type" %}
30+
{% include "meeting/meeting_heading.html" with updated=meeting.updated selected="by-type" title_extra="by Session Type" %}
3131

3232
{% regroup assignments by session.type.slug as type_list %}
3333
<ul class="typelist">

0 commit comments

Comments
 (0)