mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-10 16:24:49 +00:00
Remove django.VERSION checks
This commit is contained in:
parent
5a0c36cdae
commit
67b1ddb665
17 changed files with 45 additions and 142 deletions
|
|
@ -38,11 +38,8 @@ def items_for_result(view, result):
|
|||
boolean = getattr(attr, 'boolean', False)
|
||||
if boolean or not value:
|
||||
allow_tags = True
|
||||
if django.VERSION >= (1, 9):
|
||||
result_repr = display_for_value(
|
||||
value, empty_value_display, boolean)
|
||||
else:
|
||||
result_repr = display_for_value(value, boolean)
|
||||
result_repr = display_for_value(
|
||||
value, empty_value_display, boolean)
|
||||
|
||||
# Strip HTML tags in the resulting text, except if the
|
||||
# function has an "allow_tags" attribute set to True.
|
||||
|
|
@ -58,11 +55,8 @@ def items_for_result(view, result):
|
|||
else:
|
||||
result_repr = field_val
|
||||
else:
|
||||
if django.VERSION >= (1, 9):
|
||||
result_repr = display_for_field(
|
||||
value, f, empty_value_display)
|
||||
else:
|
||||
result_repr = display_for_field(value, f)
|
||||
result_repr = display_for_field(
|
||||
value, f, empty_value_display)
|
||||
|
||||
if isinstance(f, (
|
||||
models.DateField, models.TimeField, models.ForeignKey)
|
||||
|
|
|
|||
|
|
@ -8,13 +8,8 @@ from wagtail.wagtailsearch.models import Query
|
|||
|
||||
register = template.Library()
|
||||
|
||||
if django.VERSION >= (1, 9):
|
||||
assignment_tag = register.simple_tag
|
||||
else:
|
||||
assignment_tag = register.assignment_tag
|
||||
|
||||
|
||||
@assignment_tag
|
||||
@register.simple_tag
|
||||
def get_search_promotions(search_query):
|
||||
if search_query:
|
||||
return Query.get(search_query).editors_picks.all()
|
||||
|
|
|
|||
|
|
@ -88,31 +88,17 @@ TEMPLATES = [
|
|||
},
|
||||
]
|
||||
|
||||
if django.VERSION >= (1, 10):
|
||||
MIDDLEWARE = (
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
MIDDLEWARE = (
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
|
||||
'wagtail.wagtailcore.middleware.SiteMiddleware',
|
||||
'wagtail.wagtailredirects.middleware.RedirectMiddleware',
|
||||
)
|
||||
else:
|
||||
MIDDLEWARE_CLASSES = (
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
||||
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
|
||||
'django.contrib.messages.middleware.MessageMiddleware',
|
||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||
|
||||
'wagtail.wagtailcore.middleware.SiteMiddleware',
|
||||
'wagtail.wagtailredirects.middleware.RedirectMiddleware',
|
||||
)
|
||||
'wagtail.wagtailcore.middleware.SiteMiddleware',
|
||||
'wagtail.wagtailredirects.middleware.RedirectMiddleware',
|
||||
)
|
||||
|
||||
INSTALLED_APPS = (
|
||||
# Install wagtailredirects with its appconfig
|
||||
|
|
@ -183,10 +169,7 @@ WAGTAILSEARCH_BACKENDS = {
|
|||
|
||||
AUTH_USER_MODEL = 'customuser.CustomUser'
|
||||
|
||||
if django.VERSION >= (1, 10) and os.environ.get('DATABASE_ENGINE') in (
|
||||
# Remove next line when Django 1.8 support is dropped.
|
||||
'django.db.backends.postgresql_psycopg2',
|
||||
'django.db.backends.postgresql'):
|
||||
if os.environ.get('DATABASE_ENGINE') == 'django.db.backends.postgresql':
|
||||
INSTALLED_APPS += ('wagtail.contrib.postgres_search',)
|
||||
WAGTAILSEARCH_BACKENDS['postgresql'] = {
|
||||
'BACKEND': 'wagtail.contrib.postgres_search.backend',
|
||||
|
|
|
|||
|
|
@ -301,10 +301,7 @@ class WagtailPageTests(WagtailTestUtils, TestCase):
|
|||
child_model._meta.app_label, child_model._meta.model_name, errors))
|
||||
raise self.failureException(msg)
|
||||
|
||||
if django.VERSION >= (1, 9):
|
||||
explore_url = reverse('wagtailadmin_explore', args=[parent.pk])
|
||||
else:
|
||||
explore_url = 'http://testserver' + reverse('wagtailadmin_explore', args=[parent.pk])
|
||||
explore_url = reverse('wagtailadmin_explore', args=[parent.pk])
|
||||
if response.redirect_chain != [(explore_url, 302)]:
|
||||
msg = self._formatMessage(msg, 'Creating a page %s.%s didnt redirect the user to the explorer, but to %s' % (
|
||||
child_model._meta.app_label, child_model._meta.model_name,
|
||||
|
|
|
|||
|
|
@ -3,15 +3,11 @@ from __future__ import absolute_import, unicode_literals
|
|||
import django
|
||||
|
||||
|
||||
# TODO: This compat function is now obsolete
|
||||
def user_is_authenticated(user):
|
||||
if django.VERSION >= (1, 10):
|
||||
return user.is_authenticated
|
||||
else:
|
||||
return user.is_authenticated()
|
||||
return user.is_authenticated
|
||||
|
||||
|
||||
# TODO: This compat function is now obsolete
|
||||
def user_is_anonymous(user):
|
||||
if django.VERSION >= (1, 10):
|
||||
return user.is_anonymous
|
||||
else:
|
||||
return user.is_anonymous()
|
||||
return user.is_anonymous
|
||||
|
|
|
|||
|
|
@ -748,10 +748,7 @@ class InlinePanel(object):
|
|||
self.classname = classname
|
||||
|
||||
def bind_to_model(self, model):
|
||||
if django.VERSION >= (1, 9):
|
||||
related = getattr(model, self.relation_name).rel
|
||||
else:
|
||||
related = getattr(model, self.relation_name).related
|
||||
related = getattr(model, self.relation_name).rel
|
||||
|
||||
return type(str('_InlinePanel'), (BaseInlinePanel,), {
|
||||
'model': model,
|
||||
|
|
|
|||
|
|
@ -321,13 +321,6 @@ class WagtailAdminPageForm(WagtailAdminModelForm):
|
|||
super(WagtailAdminPageForm, self).__init__(data, files, *args, **kwargs)
|
||||
self.parent_page = parent_page
|
||||
|
||||
if django.VERSION < (1, 9):
|
||||
def clean_title(self):
|
||||
return self.cleaned_data['title'].strip()
|
||||
|
||||
def clean_seo_title(self):
|
||||
return self.cleaned_data['seo_title'].strip()
|
||||
|
||||
def clean(self):
|
||||
|
||||
cleaned_data = super(WagtailAdminPageForm, self).clean()
|
||||
|
|
|
|||
|
|
@ -29,11 +29,6 @@ register = template.Library()
|
|||
|
||||
register.filter('intcomma', intcomma)
|
||||
|
||||
if django.VERSION >= (1, 9):
|
||||
assignment_tag = register.simple_tag
|
||||
else:
|
||||
assignment_tag = register.assignment_tag
|
||||
|
||||
|
||||
@register.simple_tag(takes_context=True)
|
||||
def menu_search(context):
|
||||
|
|
@ -121,7 +116,7 @@ def widgettype(bound_field):
|
|||
return ""
|
||||
|
||||
|
||||
@assignment_tag(takes_context=True)
|
||||
@register.simple_tag(takes_context=True)
|
||||
def page_permissions(context, page):
|
||||
"""
|
||||
Usage: {% page_permissions page as page_perms %}
|
||||
|
|
@ -137,7 +132,7 @@ def page_permissions(context, page):
|
|||
return context['user_page_permissions'].for_page(page)
|
||||
|
||||
|
||||
@assignment_tag(takes_context=True)
|
||||
@register.simple_tag(takes_context=True)
|
||||
def test_collection_is_public(context, collection):
|
||||
"""
|
||||
Usage: {% test_collection_is_public collection as is_public %}
|
||||
|
|
@ -156,7 +151,7 @@ def test_collection_is_public(context, collection):
|
|||
return not is_private
|
||||
|
||||
|
||||
@assignment_tag(takes_context=True)
|
||||
@register.simple_tag(takes_context=True)
|
||||
def test_page_is_public(context, page):
|
||||
"""
|
||||
Usage: {% test_page_is_public page as is_public %}
|
||||
|
|
@ -190,26 +185,22 @@ def hook_output(hook_name):
|
|||
return mark_safe(''.join(snippets))
|
||||
|
||||
|
||||
@assignment_tag
|
||||
@register.simple_tag
|
||||
def usage_count_enabled():
|
||||
return getattr(settings, 'WAGTAIL_USAGE_COUNT_ENABLED', False)
|
||||
|
||||
|
||||
@assignment_tag
|
||||
@register.simple_tag
|
||||
def base_url_setting():
|
||||
return getattr(settings, 'BASE_URL', None)
|
||||
|
||||
|
||||
@assignment_tag
|
||||
@register.simple_tag
|
||||
def allow_unicode_slugs():
|
||||
if django.VERSION < (1, 9):
|
||||
# Unicode slugs are unsupported on Django 1.8
|
||||
return False
|
||||
else:
|
||||
return getattr(settings, 'WAGTAIL_ALLOW_UNICODE_SLUGS', True)
|
||||
return getattr(settings, 'WAGTAIL_ALLOW_UNICODE_SLUGS', True)
|
||||
|
||||
|
||||
@assignment_tag
|
||||
@register.simple_tag
|
||||
def auto_update_preview():
|
||||
return getattr(settings, 'WAGTAIL_AUTO_UPDATE_PREVIEW', False)
|
||||
|
||||
|
|
|
|||
|
|
@ -957,10 +957,7 @@ class TestPageCreation(TestCase, WagtailTestUtils):
|
|||
)
|
||||
|
||||
# Check that a form error was raised
|
||||
if django.VERSION >= (1, 9):
|
||||
self.assertFormError(response, 'form', 'title', "This field is required.")
|
||||
else:
|
||||
self.assertFormError(response, 'form', 'title', "This field cannot be blank.")
|
||||
self.assertFormError(response, 'form', 'title', "This field is required.")
|
||||
|
||||
def test_whitespace_titles_with_tab(self):
|
||||
post_data = {
|
||||
|
|
@ -972,10 +969,7 @@ class TestPageCreation(TestCase, WagtailTestUtils):
|
|||
response = self.client.post(reverse('wagtailadmin_pages:add', args=('tests', 'simplepage', self.root_page.id)), post_data)
|
||||
|
||||
# Check that a form error was raised
|
||||
if django.VERSION >= (1, 9):
|
||||
self.assertFormError(response, 'form', 'title', "This field is required.")
|
||||
else:
|
||||
self.assertFormError(response, 'form', 'title', "This field cannot be blank.")
|
||||
self.assertFormError(response, 'form', 'title', "This field is required.")
|
||||
|
||||
def test_whitespace_titles_with_tab_in_seo_title(self):
|
||||
post_data = {
|
||||
|
|
|
|||
|
|
@ -95,10 +95,7 @@ def display_custom_404(view_func):
|
|||
try:
|
||||
return view_func(request, *args, **kwargs)
|
||||
except Http404:
|
||||
if django.VERSION < (1, 9):
|
||||
return page_not_found(request, template_name='wagtailadmin/404.html')
|
||||
else:
|
||||
return page_not_found(request, '', template_name='wagtailadmin/404.html')
|
||||
return page_not_found(request, '', template_name='wagtailadmin/404.html')
|
||||
|
||||
return wrapper
|
||||
|
||||
|
|
|
|||
|
|
@ -1,15 +1,10 @@
|
|||
from __future__ import absolute_import, unicode_literals
|
||||
|
||||
import django
|
||||
from django.utils.deprecation import MiddlewareMixin
|
||||
from wagtail.wagtailcore.models import Site
|
||||
|
||||
|
||||
if django.VERSION >= (1, 10):
|
||||
from django.utils.deprecation import MiddlewareMixin
|
||||
else:
|
||||
MiddlewareMixin = object
|
||||
|
||||
|
||||
class SiteMiddleware(MiddlewareMixin):
|
||||
def process_request(self, request):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -809,7 +809,6 @@ class TestRawHTMLBlock(unittest.TestCase):
|
|||
self.assertEqual(result, '<blink>BÖÖM</blink>')
|
||||
self.assertIsInstance(result, SafeData)
|
||||
|
||||
@unittest.skipIf(django.VERSION < (1, 10, 2), "value_omitted_from_data is not available")
|
||||
def test_value_omitted_from_data(self):
|
||||
block = blocks.RawHTMLBlock()
|
||||
self.assertFalse(block.value_omitted_from_data({'rawhtml': 'ohai'}, {}, 'rawhtml'))
|
||||
|
|
@ -1253,7 +1252,6 @@ class TestStructBlock(SimpleTestCase):
|
|||
self.assertTrue(isinstance(struct_val, blocks.StructValue))
|
||||
self.assertTrue(isinstance(struct_val.bound_blocks['link'].block, blocks.URLBlock))
|
||||
|
||||
@unittest.skipIf(django.VERSION < (1, 10, 2), "value_omitted_from_data is not available")
|
||||
def test_value_omitted_from_data(self):
|
||||
block = blocks.StructBlock([
|
||||
('title', blocks.CharBlock()),
|
||||
|
|
@ -1598,7 +1596,6 @@ class TestListBlock(WagtailTestUtils, SimpleTestCase):
|
|||
|
||||
self.assertEqual(content, ["Wagtail", "Django"])
|
||||
|
||||
@unittest.skipIf(django.VERSION < (1, 10, 2), "value_omitted_from_data is not available")
|
||||
def test_value_omitted_from_data(self):
|
||||
block = blocks.ListBlock(blocks.CharBlock())
|
||||
|
||||
|
|
@ -2024,7 +2021,6 @@ class TestStreamBlock(WagtailTestUtils, SimpleTestCase):
|
|||
html
|
||||
)
|
||||
|
||||
@unittest.skipIf(django.VERSION < (1, 10, 2), "value_omitted_from_data is not available")
|
||||
def test_value_omitted_from_data(self):
|
||||
block = blocks.StreamBlock([
|
||||
('heading', blocks.CharBlock()),
|
||||
|
|
|
|||
|
|
@ -159,9 +159,6 @@ class TestServeViewWithSendfile(TestCase):
|
|||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(response['X-Sendfile'], self.document.file.path)
|
||||
|
||||
@unittest.skipIf(
|
||||
django.VERSION < (1, 9), "Fails on Django 1.8"
|
||||
) # Under Django 1.8. It adds "http://" to beginning of Location when it shouldn't
|
||||
@override_settings(
|
||||
SENDFILE_BACKEND='sendfile.backends.mod_wsgi',
|
||||
SENDFILE_ROOT=settings.MEDIA_ROOT,
|
||||
|
|
|
|||
|
|
@ -249,10 +249,7 @@ class AbstractImage(CollectionMember, index.Indexed, models.Model):
|
|||
@classmethod
|
||||
def get_rendition_model(cls):
|
||||
""" Get the Rendition model for this Image model """
|
||||
if django.VERSION >= (1, 9):
|
||||
return cls.renditions.rel.related_model
|
||||
else:
|
||||
return cls.renditions.related.related_model
|
||||
return cls.renditions.rel.related_model
|
||||
|
||||
def get_rendition(self, filter):
|
||||
if isinstance(filter, string_types):
|
||||
|
|
|
|||
|
|
@ -2,18 +2,13 @@ from __future__ import absolute_import, unicode_literals
|
|||
|
||||
import django
|
||||
from django import http
|
||||
from django.utils.deprecation import MiddlewareMixin
|
||||
from django.utils.encoding import uri_to_iri
|
||||
from django.utils.six.moves.urllib.parse import urlparse
|
||||
|
||||
from wagtail.wagtailredirects import models
|
||||
|
||||
|
||||
if django.VERSION >= (1, 10):
|
||||
from django.utils.deprecation import MiddlewareMixin
|
||||
else:
|
||||
MiddlewareMixin = object
|
||||
|
||||
|
||||
def _get_redirect(request, path):
|
||||
try:
|
||||
return models.Redirect.get_for_site(request.site).get(old_path=path)
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@ from django import forms
|
|||
from django.conf import settings
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.contrib.auth.models import Group, Permission
|
||||
from django.contrib.auth.password_validation import (
|
||||
password_validators_help_text_html, validate_password
|
||||
)
|
||||
from django.db import transaction
|
||||
from django.db.models.fields import BLANK_CHOICE_DASH
|
||||
from django.template.loader import render_to_string
|
||||
|
|
@ -22,11 +25,6 @@ from wagtail.wagtailcore.models import (
|
|||
from wagtail.wagtailusers.models import UserProfile
|
||||
|
||||
|
||||
if django.VERSION >= (1, 9):
|
||||
from django.contrib.auth.password_validation import (
|
||||
password_validators_help_text_html, validate_password
|
||||
)
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
# The standard fields each user model is expected to have, as a minimum.
|
||||
|
|
@ -103,9 +101,7 @@ class UserForm(UsernameForm):
|
|||
|
||||
if self.password_enabled:
|
||||
if self.password_required:
|
||||
self.fields['password1'].help_text = (
|
||||
mark_safe(password_validators_help_text_html())
|
||||
if django.VERSION >= (1, 9) else '')
|
||||
self.fields['password1'].help_text = mark_safe(password_validators_help_text_html())
|
||||
self.fields['password1'].required = True
|
||||
self.fields['password2'].required = True
|
||||
else:
|
||||
|
|
@ -142,7 +138,7 @@ class UserForm(UsernameForm):
|
|||
code='password_mismatch',
|
||||
))
|
||||
|
||||
if django.VERSION >= (1, 9) and password1:
|
||||
if password1:
|
||||
validate_password(password1, user=self.instance)
|
||||
|
||||
return password2
|
||||
|
|
|
|||
|
|
@ -43,20 +43,10 @@ def format_permissions(permission_bound_field):
|
|||
|
||||
# iterate over permission_bound_field to build a lookup of individual renderable
|
||||
# checkbox objects
|
||||
if django.VERSION < (1, 11):
|
||||
# On Django <1.11, iterating over the BoundField returns a sequence of CheckboxChoiceInput objects,
|
||||
# whose ID is available as .choice_value
|
||||
checkboxes_by_id = {
|
||||
int(checkbox.choice_value): checkbox
|
||||
for checkbox in permission_bound_field
|
||||
}
|
||||
else:
|
||||
# On Django >=1.11, iterating over the BoundField returns a sequence of BoundWidget objects,
|
||||
# whose ID is available as .data['value']
|
||||
checkboxes_by_id = {
|
||||
int(checkbox.data['value']): checkbox
|
||||
for checkbox in permission_bound_field
|
||||
}
|
||||
checkboxes_by_id = {
|
||||
int(checkbox.data['value']): checkbox
|
||||
for checkbox in permission_bound_field
|
||||
}
|
||||
|
||||
object_perms = []
|
||||
other_perms = []
|
||||
|
|
|
|||
Loading…
Reference in a new issue