Removed unneeded no_settings_commands hardcoded list

Thanks Tim Graham for the review.
This commit is contained in:
Claude Paroz 2016-09-29 15:05:23 +02:00
parent 79c91070e5
commit fc92c6b500
3 changed files with 8 additions and 11 deletions

View File

@ -306,19 +306,10 @@ class ManagementUtility(object):
except CommandError:
pass # Ignore any option errors at this point.
no_settings_commands = [
'help', 'version', '--help', '--version', '-h',
'startapp', 'startproject', 'compilemessages',
]
try:
settings.INSTALLED_APPS
except ImproperlyConfigured as exc:
self.settings_exception = exc
# A handful of built-in management commands work without settings.
# Load the default settings -- where INSTALLED_APPS is empty.
if subcommand in no_settings_commands:
settings.configure()
if settings.configured:
# Start the auto-reloading dev server even if the code is broken.

View File

@ -303,7 +303,12 @@ class BaseCommand(object):
self.stderr.write('%s: %s' % (e.__class__.__name__, e))
sys.exit(1)
finally:
connections.close_all()
try:
connections.close_all()
except ImproperlyConfigured:
# Ignore if connections aren't setup at this point (e.g. no
# configured settings).
pass
def execute(self, *args, **options):
"""

View File

@ -11,6 +11,7 @@ import tempfile
from os import path
import django
from django.conf import settings
from django.core.management.base import BaseCommand, CommandError
from django.core.management.utils import handle_extensions
from django.template import Context, Engine
@ -119,9 +120,9 @@ class TemplateCommand(BaseCommand):
}), autoescape=False)
# Setup a stub settings environment for template rendering
from django.conf import settings
if not settings.configured:
settings.configure()
django.setup()
template_dir = self.handle_template(options['template'],
base_subdir)