diff --git a/wagtail/utils/urlpatterns.py b/wagtail/utils/urlpatterns.py index 95b1e5979f..10271df640 100644 --- a/wagtail/utils/urlpatterns.py +++ b/wagtail/utils/urlpatterns.py @@ -1,6 +1,5 @@ from __future__ import absolute_import, unicode_literals from functools import update_wrapper -from django import VERSION as DJANGO_VERSION def decorate_urlpatterns(urlpatterns, decorator): @@ -11,25 +10,7 @@ def decorate_urlpatterns(urlpatterns, decorator): # contained in it decorate_urlpatterns(pattern.url_patterns, decorator) - if DJANGO_VERSION < (1, 10): - # Prior to Django 1.10, RegexURLPattern accepted both strings and callables as - # the callback parameter; `callback` is a property that consistently returns it as - # a callable. - # - # * if RegexURLPattern was given a string, _callback will be None, and will be - # populated on the first call to the `callback` property - # * if RegexURLPattern was given a callable, _callback will be set to that callable, - # and the `callback` property will return it - # - # In either case, we wrap the result of `callback` and write it back to `_callback`, - # so that future calls to `callback` will return our wrapped version. - - if hasattr(pattern, '_callback'): - pattern._callback = update_wrapper(decorator(pattern.callback), pattern.callback) - else: - # In Django 1.10 and above, RegexURLPattern only accepts a callable as the callback - # parameter; this is directly accessible as the `callback` attribute. - if getattr(pattern, 'callback', None): - pattern.callback = update_wrapper(decorator(pattern.callback), pattern.callback) + if getattr(pattern, 'callback', None): + pattern.callback = update_wrapper(decorator(pattern.callback), pattern.callback) return urlpatterns diff --git a/wagtail/wagtailadmin/tests/test_pages_views.py b/wagtail/wagtailadmin/tests/test_pages_views.py index 170bc25f6d..0873af2412 100644 --- a/wagtail/wagtailadmin/tests/test_pages_views.py +++ b/wagtail/wagtailadmin/tests/test_pages_views.py @@ -1161,14 +1161,7 @@ class TestPageEdit(TestCase, WagtailTestUtils): # Check the new file exists file_page = FilePage.objects.get() - # In Django < 1.10 the file_field.name starts with ./ whereas in 1.10 it is the basename; - # we test against os.path.basename(file_page.file_field.name) so that both possibilities - # are handled. os.path.basename can be removed when support for Django <= 1.9 is dropped. - - # (hello, future person grepping for the string `if DJANGO_VERSION < (1, 10)`) - - self.assertEqual(os.path.basename(file_page.file_field.name), - os.path.basename(file_upload.name)) + self.assertEqual(file_page.file_field.name, file_upload.name) self.assertTrue(os.path.exists(file_page.file_field.path)) self.assertEqual(file_page.file_field.read(), b"A new file") @@ -1196,16 +1189,9 @@ class TestPageEdit(TestCase, WagtailTestUtils): # Publish the draft just created FilePage.objects.get().get_latest_revision().publish() - # In Django < 1.10 the file_field.name starts with ./ whereas in 1.10 it is the basename; - # we test against os.path.basename(file_page.file_field.name) so that both possibilities - # are handled. os.path.basename can be removed when support for Django <= 1.9 is dropped. - - # (hello, future person grepping for the string `if DJANGO_VERSION < (1, 10)`) - # Get the file page, check the file is set file_page = FilePage.objects.get() - self.assertEqual(os.path.basename(file_page.file_field.name), - os.path.basename(file_upload.name)) + self.assertEqual(file_page.file_field.name, file_upload.name) self.assertTrue(os.path.exists(file_page.file_field.path)) self.assertEqual(file_page.file_field.read(), b"A new file") diff --git a/wagtail/wagtailcore/migrations/0001_squashed_0016_change_page_url_path_to_text_field.py b/wagtail/wagtailcore/migrations/0001_squashed_0016_change_page_url_path_to_text_field.py index ae014e84f3..03c8a3ce14 100644 --- a/wagtail/wagtailcore/migrations/0001_squashed_0016_change_page_url_path_to_text_field.py +++ b/wagtail/wagtailcore/migrations/0001_squashed_0016_change_page_url_path_to_text_field.py @@ -2,7 +2,6 @@ from __future__ import unicode_literals import django.db.models.deletion -from django import VERSION as DJANGO_VERSION from django.conf import settings from django.db import migrations, models @@ -19,8 +18,7 @@ def initial_data(apps, schema_editor): # Create page content type page_content_type, created = ContentType.objects.get_or_create( model='page', - app_label='wagtailcore', - defaults={'name': 'page'} if DJANGO_VERSION < (1, 8) else {} + app_label='wagtailcore' ) # Create root page diff --git a/wagtail/wagtailcore/migrations/0002_initial_data.py b/wagtail/wagtailcore/migrations/0002_initial_data.py index 7714b91493..42a11aef7b 100644 --- a/wagtail/wagtailcore/migrations/0002_initial_data.py +++ b/wagtail/wagtailcore/migrations/0002_initial_data.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django import VERSION as DJANGO_VERSION from django.db import migrations @@ -15,8 +14,7 @@ def initial_data(apps, schema_editor): # Create page content type page_content_type, created = ContentType.objects.get_or_create( model='page', - app_label='wagtailcore', - defaults={'name': 'page'} if DJANGO_VERSION < (1, 8) else {} + app_label='wagtailcore' ) # Create root page diff --git a/wagtail/wagtailcore/migrations/0029_unicode_slugfield_dj19.py b/wagtail/wagtailcore/migrations/0029_unicode_slugfield_dj19.py index 19a55439ed..3d4b346103 100644 --- a/wagtail/wagtailcore/migrations/0029_unicode_slugfield_dj19.py +++ b/wagtail/wagtailcore/migrations/0029_unicode_slugfield_dj19.py @@ -3,7 +3,6 @@ from __future__ import unicode_literals from django.db import migrations, models -from django import VERSION as DJANGO_VERSION class Migration(migrations.Migration): @@ -12,12 +11,10 @@ class Migration(migrations.Migration): ('wagtailcore', '0028_merge'), ] - operations = [] - if DJANGO_VERSION >= (1, 9): - operations += [ - migrations.AlterField( - model_name='page', - name='slug', - field=models.SlugField(allow_unicode=True, help_text='The name of the page as it will appear in URLs e.g http://domain.com/blog/[my-slug]/', max_length=255, verbose_name='slug'), - ), - ] + operations = [ + migrations.AlterField( + model_name='page', + name='slug', + field=models.SlugField(allow_unicode=True, help_text='The name of the page as it will appear in URLs e.g http://domain.com/blog/[my-slug]/', max_length=255, verbose_name='slug'), + ), + ] diff --git a/wagtail/wagtailcore/models.py b/wagtail/wagtailcore/models.py index 22d2704d9a..ead9555106 100644 --- a/wagtail/wagtailcore/models.py +++ b/wagtail/wagtailcore/models.py @@ -3,7 +3,6 @@ from __future__ import absolute_import, unicode_literals import json import logging from collections import defaultdict -from django import VERSION as DJANGO_VERSION from django.conf import settings from django.contrib.auth.models import Group, Permission @@ -205,11 +204,6 @@ class PageBase(models.base.ModelBase): def __init__(cls, name, bases, dct): super(PageBase, cls).__init__(name, bases, dct) - if DJANGO_VERSION < (1, 10) and getattr(cls, '_deferred', False): - # this is an internal class built for Django's deferred-attribute mechanism; - # don't proceed with all this page type registration stuff - return - if 'template' not in dct: # Define a default template path derived from the app name and model name cls.template = "%s/%s.html" % (cls._meta.app_label, camelcase_to_underscore(name)) @@ -255,20 +249,12 @@ class Page(six.with_metaclass(PageBase, AbstractPage, index.Indexed, Clusterable max_length=255, editable=False ) - # use django 1.9+ SlugField with unicode support - if DJANGO_VERSION >= (1, 9): - slug = models.SlugField( - verbose_name=_('slug'), - allow_unicode=True, - max_length=255, - help_text=_("The name of the page as it will appear in URLs e.g http://domain.com/blog/[my-slug]/") - ) - else: - slug = models.SlugField( - verbose_name=_('slug'), - max_length=255, - help_text=_("The name of the page as it will appear in URLs e.g http://domain.com/blog/[my-slug]/") - ) + slug = models.SlugField( + verbose_name=_('slug'), + allow_unicode=True, + max_length=255, + help_text=_("The name of the page as it will appear in URLs e.g http://domain.com/blog/[my-slug]/") + ) content_type = models.ForeignKey( 'contenttypes.ContentType', verbose_name=_('content type'), @@ -436,10 +422,7 @@ class Page(six.with_metaclass(PageBase, AbstractPage, index.Indexed, Clusterable if not self.slug: # Try to auto-populate slug from title - if DJANGO_VERSION >= (1, 9): - base_slug = slugify(self.title, allow_unicode=True) - else: - base_slug = slugify(self.title) + base_slug = slugify(self.title, allow_unicode=True) # only proceed if we get a non-empty base slug back from slugify if base_slug: diff --git a/wagtail/wagtailcore/query.py b/wagtail/wagtailcore/query.py index cffd1936af..1ac7d8df76 100644 --- a/wagtail/wagtailcore/query.py +++ b/wagtail/wagtailcore/query.py @@ -3,11 +3,11 @@ from __future__ import absolute_import, unicode_literals import posixpath from collections import defaultdict -from django import VERSION as DJANGO_VERSION from django.apps import apps from django.contrib.contenttypes.models import ContentType from django.db.models import CharField, Q from django.db.models.functions import Length, Substr +from django.db.models.query import BaseIterable from treebeard.mp_tree import MP_NodeQuerySet from wagtail.wagtailsearch.queryset import SearchableQuerySetMixin @@ -343,12 +343,9 @@ class PageQuerySet(SearchableQuerySetMixin, TreeQuerySet): This efficiently gets all the specific pages for the queryset, using the minimum number of queries. """ - if DJANGO_VERSION >= (1, 9): - clone = self._clone() - clone._iterable_class = SpecificIterable - return clone - else: - return self._clone(klass=SpecificQuerySet) + clone = self._clone() + clone._iterable_class = SpecificIterable + return clone def in_site(self, site): """ @@ -387,17 +384,6 @@ def specific_iterator(qs): yield pages_by_type[content_type][pk] -# Django 1.9 changed how extending QuerySets with different iterators behaved -# considerably, in a way that is not easily compatible between the two versions -if DJANGO_VERSION >= (1, 9): - from django.db.models.query import BaseIterable - - class SpecificIterable(BaseIterable): - def __iter__(self): - return specific_iterator(self.queryset) - -else: - from django.db.models.query import QuerySet - - class SpecificQuerySet(QuerySet): - iterator = specific_iterator +class SpecificIterable(BaseIterable): + def __iter__(self): + return specific_iterator(self.queryset) diff --git a/wagtail/wagtaildocs/migrations/0002_initial_data.py b/wagtail/wagtaildocs/migrations/0002_initial_data.py index eb137f12bd..7ab567ca4b 100644 --- a/wagtail/wagtaildocs/migrations/0002_initial_data.py +++ b/wagtail/wagtaildocs/migrations/0002_initial_data.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django import VERSION as DJANGO_VERSION from django.db import migrations @@ -13,8 +12,7 @@ def add_document_permissions_to_admin_groups(apps, schema_editor): # Get document permissions document_content_type, _created = ContentType.objects.get_or_create( model='document', - app_label='wagtaildocs', - defaults={'name': 'document'} if DJANGO_VERSION < (1, 8) else {} + app_label='wagtaildocs' ) add_document_permission, _created = Permission.objects.get_or_create( diff --git a/wagtail/wagtailimages/migrations/0002_initial_data.py b/wagtail/wagtailimages/migrations/0002_initial_data.py index 42e57eda8c..a4a8c9b99d 100644 --- a/wagtail/wagtailimages/migrations/0002_initial_data.py +++ b/wagtail/wagtailimages/migrations/0002_initial_data.py @@ -1,7 +1,6 @@ # -*- coding: utf-8 -*- from __future__ import unicode_literals -from django import VERSION as DJANGO_VERSION from django.db import migrations @@ -13,8 +12,7 @@ def add_image_permissions_to_admin_groups(apps, schema_editor): # Get image permissions image_content_type, _created = ContentType.objects.get_or_create( model='image', - app_label='wagtailimages', - defaults={'name': 'image'} if DJANGO_VERSION < (1, 8) else {} + app_label='wagtailimages' ) add_image_permission, _created = Permission.objects.get_or_create(