misc: remove backward compatibility with django < 1.11 (#36430)

This commit is contained in:
Frédéric Péters 2019-09-23 23:03:33 +02:00
parent 083658ee5a
commit 90f44a85eb
6 changed files with 7 additions and 55 deletions

View File

@ -1,4 +1,3 @@
import django
from django.apps import AppConfig, apps
from . import settings, threads
@ -22,25 +21,3 @@ class MultitenantAppConfig(AppConfig):
# https://code.djangoproject.com/ticket/27625.
conf.LazySettings.__getattr__ = lambda self, name: getattr(self._wrapped, name)
threads.install_tenant_aware_threads()
if (1, 7) <= django.VERSION < (1, 8):
class RunPythonOverride(operations.RunPython):
def can_migrate(self, app_label, schema_editor):
app = apps.get_app_config(app_label)
for model in app.get_models():
if self.allowed_to_migrate(schema_editor.connection.alias, model):
return True
return False
def database_forwards(self, app_label, schema_editor, *args, **kwargs):
if not self.can_migrate(app_label, schema_editor):
return
super(RunPythonOverride, self).database_forwards(app_label, schema_editor, *args, **kwargs)
def database_backwards(self, app_label, schema_editor, *args, **kwargs):
if not self.can_migrate(app_label, schema_editor):
return
super(RunPythonOverride, self).database_backwards(app_label, schema_editor, *args, **kwargs)
operations.RunPython = RunPythonOverride
migrations.RunPython = RunPythonOverride

View File

@ -131,8 +131,6 @@ class TenantWrappedCommand(InteractiveTenantOption, BaseCommand):
def __new__(cls, *args, **kwargs):
obj = super(TenantWrappedCommand, cls).__new__(cls, *args, **kwargs)
obj.command_instance = obj.COMMAND()
if django.VERSION <= (1,10,0):
obj.option_list = obj.command_instance.option_list
return obj
def add_arguments(self, parser):

View File

@ -8,15 +8,7 @@ from django.conf import settings
from django.core.management.base import CommandError, BaseCommand
from tenant_schemas.utils import django_is_in_test_mode
if django.VERSION < (1, 7, 0):
try:
from south.management.commands.migrate import Command as MigrateCommand
except ImportError:
MigrateCommand = BaseCommand
else:
MigrateCommand = BaseCommand
class Command(MigrateCommand):
class Command(BaseCommand):
def handle(self, *args, **options):
database = options.get('database', 'default')
@ -27,6 +19,6 @@ class Command(MigrateCommand):
"shouldn't call migrate directly!".format(database))
super(Command, self).handle(*args, **options)
if django.VERSION >= (1, 7, 0) and django_is_in_test_mode():
if django_is_in_test_mode():
from .migrate_schemas import MigrateSchemasCommand
Command = MigrateSchemasCommand

View File

@ -31,14 +31,6 @@ from hobo.multitenant.management.commands import SyncCommon
class MigrateSchemasCommand(SyncCommon):
help = "Updates database schema. Manages both apps with migrations and those without."
def __init__(self, stdout=None, stderr=None, no_color=False):
"""
Changes the option_list to use the options from the wrapped migrate command.
"""
if django.VERSION <= (1, 10, 0):
self.option_list += MigrateCommand.option_list
super(Command, self).__init__(stdout, stderr, no_color)
def add_arguments(self, parser):
super(MigrateSchemasCommand, self).add_arguments(parser)
command = MigrateCommand()

View File

@ -47,14 +47,10 @@ def run_command_from_argv(command, argv):
command._called_from_command_line = True
parser = command.create_parser(argv[0], argv[1])
if django.VERSION >= (1, 10, 0) or command.use_argparse:
options = parser.parse_args(argv[2:])
cmd_options = vars(options)
# Move positional args out of options to mimic legacy optparse
args = cmd_options.pop('args', ())
else:
options, args = parser.parse_args(argv[2:])
cmd_options = vars(options)
options = parser.parse_args(argv[2:])
cmd_options = vars(options)
# Move positional args out of options to mimic legacy optparse
args = cmd_options.pop('args', ())
handle_default_options(options)
try:
command.execute(*args, **cmd_options)

View File

@ -36,10 +36,7 @@ def test_theme_base(settings, rf):
cache.clear()
def check(context, value):
if django.VERSION >= (1, 10, 0):
assert context['theme_base']().source == value
else:
assert context['theme_base']().origin.source == value
assert context['theme_base']().source == value
with HTTMock(combo_mock), override_settings(INSTALLED_APPS=[]):
context = theme_base(rf.get('/'))