mirror of
https://github.com/Hopiu/django-modeltranslation.git
synced 2026-03-16 22:10:31 +00:00
cleanup: Remove obsolete code for old django in loaddata command
This commit is contained in:
parent
fba75cca07
commit
a8e5d24b11
2 changed files with 16 additions and 60 deletions
|
|
@ -377,17 +377,3 @@ Default: ``True``
|
|||
.. versionadded:: 0.6
|
||||
|
||||
Control if :ref:`fallback <fallback>` (both language and value) will occur.
|
||||
|
||||
|
||||
.. _settings-modeltranslation_loaddata_retain_locale:
|
||||
|
||||
``MODELTRANSLATION_LOADDATA_RETAIN_LOCALE``
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Default: ``True``
|
||||
|
||||
.. versionadded:: 0.7
|
||||
|
||||
Control if the ``loaddata`` command should leave the settings-defined locale alone. Setting it
|
||||
to ``False`` will result in previous behaviour of ``loaddata``: inserting fixtures to database
|
||||
under ``en-us`` locale.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
from django import VERSION
|
||||
import argparse
|
||||
|
||||
from django.core.management.commands.loaddata import Command as LoadDataCommand
|
||||
|
||||
# Because this command is used (instead of default loaddata), then settings have been imported
|
||||
|
|
@ -6,7 +7,6 @@ from django.core.management.commands.loaddata import Command as LoadDataCommand
|
|||
from modeltranslation import settings as mt_settings
|
||||
from modeltranslation.utils import auto_populate
|
||||
|
||||
|
||||
ALLOWED = (None, False, 'all', 'default', 'required')
|
||||
ALLOWED_FOR_PRINT = ', '.join(str(i) for i in (0,) + ALLOWED[1:]) # For pretty-printing
|
||||
|
||||
|
|
@ -22,55 +22,25 @@ def check_mode(option, opt_str, value, parser, namespace=None):
|
|||
class Command(LoadDataCommand):
|
||||
leave_locale_alone = mt_settings.LOADDATA_RETAIN_LOCALE # Django 1.6
|
||||
|
||||
help = (
|
||||
'Using this option will cause fixtures to be loaded under auto-population MODE.'
|
||||
+ 'Allowed values are: %s' % ALLOWED_FOR_PRINT
|
||||
)
|
||||
if VERSION < (1, 8):
|
||||
from optparse import make_option
|
||||
class CheckAction(argparse.Action):
|
||||
def __call__(self, parser, namespace, value, option_string=None):
|
||||
check_mode(self, option_string, value, parser, namespace)
|
||||
|
||||
option_list = LoadDataCommand.option_list + (
|
||||
make_option(
|
||||
'--populate',
|
||||
action='callback',
|
||||
callback=check_mode,
|
||||
type='string',
|
||||
dest='populate',
|
||||
metavar='MODE',
|
||||
help=help,
|
||||
def add_arguments(self, parser):
|
||||
super(Command, self).add_arguments(parser)
|
||||
parser.add_argument(
|
||||
'--populate',
|
||||
action=self.CheckAction,
|
||||
type=str,
|
||||
dest='populate',
|
||||
metavar='MODE',
|
||||
help=(
|
||||
'Using this option will cause fixtures to be loaded under auto-population MODE. '
|
||||
+ 'Allowed values are: %s' % ALLOWED_FOR_PRINT
|
||||
),
|
||||
)
|
||||
else:
|
||||
import argparse
|
||||
|
||||
class CheckAction(argparse.Action):
|
||||
def __call__(self, parser, namespace, value, option_string=None):
|
||||
check_mode(self, option_string, value, parser, namespace)
|
||||
|
||||
def add_arguments(self, parser):
|
||||
super(Command, self).add_arguments(parser)
|
||||
parser.add_argument(
|
||||
'--populate',
|
||||
action=self.CheckAction,
|
||||
type=str,
|
||||
dest='populate',
|
||||
metavar='MODE',
|
||||
help=self.help,
|
||||
)
|
||||
|
||||
def __init__(self):
|
||||
super(Command, self).__init__()
|
||||
if mt_settings.LOADDATA_RETAIN_LOCALE and VERSION < (1, 6):
|
||||
from django.utils import translation
|
||||
|
||||
self.locale = translation.get_language()
|
||||
|
||||
def handle(self, *fixture_labels, **options):
|
||||
if hasattr(self, 'locale'):
|
||||
from django.utils import translation
|
||||
|
||||
translation.activate(self.locale)
|
||||
|
||||
mode = options.get('populate')
|
||||
if mode is not None:
|
||||
with auto_populate(mode):
|
||||
|
|
|
|||
Loading…
Reference in a new issue