mirror of
https://github.com/wagtail/wagtail.git
synced 2024-11-29 09:33:54 +01:00
Remove remaining DJANGO_VERSION checks for Django <1.11
This commit is contained in:
parent
1f54141aeb
commit
6ab10b5e11
@ -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
|
||||
|
@ -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")
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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'),
|
||||
),
|
||||
]
|
||||
|
@ -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:
|
||||
|
@ -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)
|
||||
|
@ -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(
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user