delete some django < 1.8 compatiblity code (#25097)

This commit is contained in:
Emmanuel Cazenave 2018-07-13 10:16:46 +02:00
parent 5afd362bc3
commit 7d53bfcb3c
9 changed files with 24 additions and 92 deletions

View File

@ -1,6 +1,5 @@
from datetime import datetime
import django
from django.conf import settings
try:
@ -20,22 +19,5 @@ from . import app_settings, utils
user_model_label = getattr(settings, 'AUTH_USER_MODEL', 'auth.User')
from django.contrib.auth.tokens import PasswordResetTokenGenerator
if django.VERSION < (1, 8):
class PasswordResetTokenGenerator(PasswordResetTokenGenerator):
def check_token(self, user, token):
if not user.last_login:
new_user = user.__class__()
new_user.__dict__ = user.__dict__
new_user.last_login = new_user.last_login or datetime(1970, 1, 1)
user = new_user
return super(PasswordResetTokenGenerator, self).check_token(user, token)
def make_token(self, user):
if not user.last_login:
new_user = user.__class__()
new_user.__dict__ = user.__dict__
new_user.last_login = new_user.last_login or datetime(1970, 1, 1)
user = new_user
return super(PasswordResetTokenGenerator, self).make_token(user)
default_token_generator = PasswordResetTokenGenerator()

View File

@ -1,4 +1,3 @@
import django
from django.conf import settings
from django.utils.translation import ugettext_lazy as _
from django.core.checks import register, Warning, Tags
@ -58,8 +57,5 @@ def check_authentic2_config(app_configs, **kwargs):
)
return errors
if django.VERSION >= (1, 8):
check_authentic2_config = register(Tags.security,
deploy=True)(check_authentic2_config)
else:
check_authentic2_config = register()(check_authentic2_config)
check_authentic2_config = register(Tags.security,
deploy=True)(check_authentic2_config)

View File

@ -1,6 +1,5 @@
import itertools
import django
from django.db.migrations.operations.base import Operation
@ -24,14 +23,9 @@ class CreatePartialIndexes(Operation):
self.where.add('"%s" IS NULL' % column)
def allowed(self, app_label, schema_editor, to_state):
if django.VERSION < (1, 8, 0):
to_model = to_state.render().get_model(app_label, self.model_name)
if not self.allowed_to_migrate(schema_editor.connection.alias, to_model):
return False
else:
to_model = to_state.apps.get_model(app_label, self.model_name)
if not self.allow_migrate_model(schema_editor.connection.alias, to_model):
return False
to_model = to_state.apps.get_model(app_label, self.model_name)
if not self.allow_migrate_model(schema_editor.connection.alias, to_model):
return False
if schema_editor.connection.vendor == 'postgresql':
return True
return False

View File

@ -1,4 +1,3 @@
import django
import collections
import logging
import random
@ -96,8 +95,7 @@ class BaseRegistrationView(FormView):
ctx = super(BaseRegistrationView, self).get_context_data(**kwargs)
request_context = RequestContext(self.request)
request_context.push(ctx)
if django.VERSION >= (1, 8, 0):
request_context['add_to_blocks'] = collections.defaultdict(lambda: [])
request_context['add_to_blocks'] = collections.defaultdict(lambda: [])
parameters = {'request': self.request,
'context_instance': request_context}
blocks = [utils.get_backend_method(backend, 'registration', parameters)

View File

@ -4,7 +4,6 @@ import logging.config
from django.conf import global_settings
import os
import django
from gadjo.templatetags.gadjo import xstatic
from . import plugins, logger
@ -277,8 +276,7 @@ MIGRATION_MODULES = {
'menu': 'authentic2.menu_migrations',
'dashboard': 'authentic2.dashboard_migrations',
}
if django.VERSION >= (1,8):
MIGRATION_MODULES['auth'] = 'authentic2.auth_migrations_18'
MIGRATION_MODULES['auth'] = 'authentic2.auth_migrations_18'
# Django REST Framework
REST_FRAMEWORK = {

View File

@ -14,7 +14,6 @@ from itertools import islice, chain, count
from importlib import import_module
import django
from django.conf import settings
from django.http import HttpResponseRedirect, HttpResponse
from django.core.exceptions import ImproperlyConfigured, PermissionDenied
@ -620,29 +619,15 @@ def send_templated_mail(user_or_email, template_names, context=None, with_html=T
html_message=html_body, **kwargs)
if django.VERSION < (1, 8, 0):
from django.db.models import ForeignKey
def get_fk_model(model, fieldname):
'''returns None if not foreignkey, otherswise the relevant model'''
try:
field_object = model._meta.get_field(fieldname)
direct = not field_object.auto_created or field_object.concrete
except FieldDoesNotExist:
return None
if not field_object.m2m and direct and isinstance(field_object, ForeignKey):
return field_object.rel.to
def get_fk_model(model, fieldname):
try:
field = model._meta.get_field('ou')
except FieldDoesNotExist:
return None
else:
def get_fk_model(model, fieldname):
try:
field = model._meta.get_field('ou')
except FieldDoesNotExist:
else:
if not field.is_relation or not field.many_to_one:
return None
else:
if not field.is_relation or not field.many_to_one:
return None
return field.related_model
return field.related_model
def get_registration_url(request, service_slug=None):

View File

@ -7,7 +7,6 @@ import re
import collections
import django
from django.conf import settings
from django.shortcuts import render_to_response, render
from django.template import RequestContext
@ -297,8 +296,7 @@ def login(request, template_name='authentic2/login.html',
'registration_authorized': getattr(settings, 'REGISTRATION_OPEN', True),
'registration_url': registration_url,
})
if django.VERSION >= (1, 8, 0):
context_instance['add_to_blocks'] = collections.defaultdict(lambda: [])
context_instance['add_to_blocks'] = collections.defaultdict(lambda: [])
# Cancel button
if request.method == "POST" \
@ -413,8 +411,7 @@ class ProfileView(cbv.TemplateNamesMixin, TemplateView):
request = self.request
context_instance = RequestContext(request, ctx)
if django.VERSION >= (1, 8, 0):
context_instance['add_to_blocks'] = collections.defaultdict(lambda: [])
context_instance['add_to_blocks'] = collections.defaultdict(lambda: [])
if request.method == "POST":
for frontend in frontends:
if 'submit-%s' % frontend.id in request.POST:

View File

@ -1,6 +1,5 @@
import copy
import django
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.db.models.query import Q
@ -13,29 +12,15 @@ except ImportError:
from . import utils
if django.VERSION < (1, 8, 0):
from django.db.models import ForeignKey
def get_fk_model(model, fieldname):
'''returns None if not foreignkey, otherswise the relevant model'''
try:
field_object = model._meta.get_field(fieldname)
direct = not field_object.auto_created or field_object.concrete
except FieldDoesNotExist:
return None
if not field_object.m2m and direct and isinstance(field_object, ForeignKey):
return field_object.rel.to
def get_fk_model(model, fieldname):
try:
field = model._meta.get_field('ou')
except FieldDoesNotExist:
return None
else:
def get_fk_model(model, fieldname):
try:
field = model._meta.get_field('ou')
except FieldDoesNotExist:
else:
if not field.is_relation or not field.many_to_one:
return None
else:
if not field.is_relation or not field.many_to_one:
return None
return field.related_model
return field.related_model
class DjangoRBACBackend(object):

View File

@ -1,5 +1,3 @@
import django
from authentic2.utils import good_next_url, same_origin, select_next_url
@ -8,8 +6,7 @@ def test_good_next_url(rf, settings):
assert good_next_url(request, '/admin/')
assert good_next_url(request, '/')
assert good_next_url(request, 'https://example.net/')
if django.VERSION >= (1, 8):
assert good_next_url(request, 'https://example.net:443/')
assert good_next_url(request, 'https://example.net:443/')
assert not good_next_url(request, 'https://example.net:4443/')
assert not good_next_url(request, 'http://example.net/')
assert not good_next_url(request, 'https://google.com/')