Skip to content

Commit 488ff08

Browse files
committed
Merged in ^/personal/henrik/6.129.2-django2.0 which contains an upgrade of Django from 1.11 to 2.0, with the code changes needed.
- Legacy-Id: 17817
2 parents a44a80b + aa9db49 commit 488ff08

19 files changed

Lines changed: 189 additions & 205 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: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pyquery import PyQuery
99
from unittest import skipIf
1010

11+
import django
1112
from django.urls import reverse as urlreverse
1213
#from django.test.utils import override_settings
1314

@@ -205,6 +206,7 @@ def test_edit_meeting_schedule(self):
205206
self.assertTrue(not s1_element.is_displayed())
206207

207208
@skipIf(skip_selenium, skip_message)
209+
@skipIf(django.VERSION[0]==2, "Skipping test with race conditions under Django 2")
208210
class ScheduleEditTests(IetfLiveServerTestCase):
209211
def setUp(self):
210212
self.driver = start_web_driver()
@@ -228,19 +230,28 @@ def login(self):
228230
self.driver.find_element_by_xpath('//button[@type="submit"]').click()
229231

230232
def testUnschedule(self):
233+
231234
meeting = make_meeting_test_data()
232235
colors.fg_group_colors['FARFUT'] = 'blue'
233236
colors.bg_group_colors['FARFUT'] = 'white'
234237

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

240+
241+
ss = list(SchedTimeSessAssignment.objects.filter(session__meeting__number=72,session__group__acronym='mars',schedule__name='test-schedule')) # pyflakes:ignore
242+
237243
self.login()
238244
url = self.absreverse('ietf.meeting.views.edit_schedule',kwargs=dict(num='72',name='test-schedule',owner='plain@example.com'))
239245
self.driver.get(url)
240246

241-
s1 = Session.objects.filter(group__acronym='mars', meeting=meeting).first()
247+
# driver.get() will wait for scripts to finish, but not ajax
248+
# requests. Wait for completion of the permissions check:
249+
read_only_note = self.driver.find_element_by_id('read_only')
250+
WebDriverWait(self.driver, 10).until(expected_conditions.invisibility_of_element(read_only_note), "Read-only schedule")
242251

243-
time.sleep(0.1)
252+
s1 = Session.objects.filter(group__acronym='mars', meeting=meeting).first()
253+
selector = "#session_{}".format(s1.pk)
254+
WebDriverWait(self.driver, 30).until(expected_conditions.presence_of_element_located((By.CSS_SELECTOR, selector)), "Did not find %s"%selector)
244255

245256
self.assertEqual(self.driver.find_elements_by_css_selector("#sortable-list #session_{}".format(s1.pk)), [])
246257

@@ -251,6 +262,7 @@ def testUnschedule(self):
251262
self.assertTrue(self.driver.find_elements_by_css_selector("#sortable-list #session_{}".format(s1.pk)))
252263

253264
time.sleep(0.1) # The API that modifies the database runs async
265+
254266
self.assertEqual(SchedTimeSessAssignment.objects.filter(session__meeting__number=72,session__group__acronym='mars',schedule__name='test-schedule').count(),0)
255267

256268
@skipIf(skip_selenium, skip_message)

ietf/meeting/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2794,6 +2794,7 @@ def floor_plan(request, num=None, floor=None, ):
27942794
except FileNotFoundError:
27952795
raise Http404('Missing floorplan image for %s' % floor)
27962796
return render(request, 'meeting/floor-plan.html', {
2797+
"meeting": meeting,
27972798
"schedule": schedule,
27982799
"number": num,
27992800
"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',
@@ -902,7 +884,6 @@ def skip_unreadable_post(record):
902884
SECR_PPT2PDF_COMMAND = ['/usr/bin/soffice','--headless','--convert-to','pdf:writer_globaldocument_pdf_Export','--outdir']
903885
STATS_REGISTRATION_ATTENDEES_JSON_URL = 'https://ietf.org/registration/attendees/{number}'
904886
NEW_PROCEEDINGS_START = 95
905-
USE_ETAGS=True
906887
YOUTUBE_API_KEY = ''
907888
YOUTUBE_API_SERVICE_NAME = 'youtube'
908889
YOUTUBE_API_VERSION = 'v3'
@@ -1062,7 +1043,6 @@ def skip_unreadable_post(record):
10621043
]
10631044

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

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)