浏览代码

Fixed #27305 -- Removed BaseCommand.can_import_settings unused attribute

Thanks Tim Graham for the review.
Claude Paroz 8 年之前
父节点
当前提交
122c90a43b

+ 0 - 20
django/core/management/base.py

@@ -151,12 +151,6 @@ class BaseCommand(object):
 
     Several attributes affect behavior at various steps along the way:
 
-    ``can_import_settings``
-        A boolean indicating whether the command needs to be able to
-        import Django settings; if ``True``, ``execute()`` will verify
-        that this is possible before proceeding. Default value is
-        ``True``.
-
     ``help``
         A short description of the command, which will be printed in
         help messages.
@@ -192,17 +186,12 @@ class BaseCommand(object):
         that is locale-sensitive and such content shouldn't contain any
         translations (like it happens e.g. with django.contrib.auth
         permissions) as activating any locale might cause unintended effects.
-
-        This option can't be False when the can_import_settings option is set
-        to False too because attempting to deactivate translations needs access
-        to settings. This condition will generate a CommandError.
     """
     # Metadata about this command.
     help = ''
 
     # Configuration shortcuts that alter various logic.
     _called_from_command_line = False
-    can_import_settings = True
     output_transaction = False  # Whether to wrap the output in a "BEGIN; COMMIT;"
     leave_locale_alone = False
     requires_migrations_checks = False
@@ -326,15 +315,6 @@ class BaseCommand(object):
 
         saved_locale = None
         if not self.leave_locale_alone:
-            # Only mess with locales if we can assume we have a working
-            # settings file, because django.utils.translation requires settings
-            # (The final saying about whether the i18n machinery is active will be
-            # found in the value of the USE_I18N setting)
-            if not self.can_import_settings:
-                raise CommandError("Incompatible values of 'leave_locale_alone' "
-                                   "(%s) and 'can_import_settings' (%s) command "
-                                   "options." % (self.leave_locale_alone,
-                                                 self.can_import_settings))
             # Deactivate translations, because django-admin creates database
             # content like permissions, and those shouldn't contain any
             # translations.

+ 0 - 3
django/core/management/templates.py

@@ -35,9 +35,6 @@ class TemplateCommand(BaseCommand):
     :param options: The additional variables passed to project or app templates
     """
     requires_system_checks = False
-    # Can't import settings during this command, because they haven't
-    # necessarily been created.
-    can_import_settings = False
     # The supported URL schemes
     url_schemes = ['http', 'https', 'ftp']
     # Can't perform any active locale changes during this command, because

+ 0 - 13
docs/howto/custom-management-commands.txt

@@ -148,7 +148,6 @@ support code::
 
     class Command(BaseCommand):
         ...
-        can_import_settings = True
 
         def handle(self, *args, **options):
 
@@ -208,13 +207,6 @@ Attributes
 All attributes can be set in your derived class and can be used in
 :class:`BaseCommand`’s :ref:`subclasses<ref-basecommand-subclasses>`.
 
-.. attribute:: BaseCommand.can_import_settings
-
-    A boolean indicating whether the command needs to be able to
-    import Django settings; if ``True``, ``execute()`` will verify
-    that this is possible before proceeding. Default value is
-    ``True``.
-
 .. attribute:: BaseCommand.help
 
     A short description of the command, which will be printed in the
@@ -261,11 +253,6 @@ All attributes can be set in your derived class and can be used in
     effects. Seethe `Management commands and locales`_ section above for
     further details.
 
-    This option can't be ``False`` when the
-    :data:`~BaseCommand.can_import_settings` option is set to ``False`` too
-    because attempting to set the locale needs access to settings. This
-    condition will generate a :exc:`CommandError`.
-
 .. attribute:: BaseCommand.style
 
     An instance attribute that helps create colored output when writing to

+ 2 - 0
docs/releases/1.11.txt

@@ -278,6 +278,8 @@ Management Commands
 * The new :option:`loaddata --exclude` option allows excluding models and apps
   while loading data from fixtures.
 
+* The unused ``BaseCommand.can_import_settings`` attribute is removed.
+
 Migrations
 ~~~~~~~~~~
 

+ 1 - 1
docs/releases/1.6.txt

@@ -189,7 +189,7 @@ Minor features
 
 * For custom management commands: Verification of the presence of valid
   settings in commands that ask for it by using the
-  :attr:`~django.core.management.BaseCommand.can_import_settings` internal
+  ``BaseCommand.can_import_settings`` internal
   option is now performed independently from handling of the locale that
   should be active during the execution of the command. The latter can now be
   influenced by the new

+ 0 - 1
tests/user_commands/management/commands/leave_locale_alone_false.py

@@ -4,7 +4,6 @@ from django.utils import translation
 
 class Command(BaseCommand):
 
-    can_import_settings = True
     leave_locale_alone = False
 
     def handle(self, *args, **options):

+ 0 - 1
tests/user_commands/management/commands/leave_locale_alone_true.py

@@ -4,7 +4,6 @@ from django.utils import translation
 
 class Command(BaseCommand):
 
-    can_import_settings = True
     leave_locale_alone = True
 
     def handle(self, *args, **options):