mirror of
https://github.com/django/django.git
synced 2025-07-04 17:59:13 +00:00
magic-removal: Fixed #1549 -- Added 'manage.py diffsettings', which displays differences between project settings and default settings. Thanks, Paul B.
git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2671 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
a3f8ab3368
commit
d6863bede6
@ -514,6 +514,32 @@ def get_admin_index(app):
|
||||
get_admin_index.help_doc = "Prints the admin-index template snippet for the given app name(s)."
|
||||
get_admin_index.args = APP_ARGS
|
||||
|
||||
def _module_to_dict(module, omittable=lambda k: k.startswith('_')):
|
||||
"Converts a module namespace to a Python dictionary. Used by get_settings_diff."
|
||||
return dict([(k, repr(v)) for k, v in module.__dict__.items() if not omittable(k)])
|
||||
|
||||
def diffsettings():
|
||||
"""
|
||||
Displays differences between the current settings.py and Django's
|
||||
default settings. Settings that don't appear in the defaults are
|
||||
followed by "###".
|
||||
"""
|
||||
# Inspired by Postfix's "postconf -n".
|
||||
from django.conf import settings
|
||||
from django.conf import global_settings
|
||||
|
||||
user_settings = _module_to_dict(settings)
|
||||
default_settings = _module_to_dict(global_settings)
|
||||
|
||||
output = []
|
||||
for key in sorted(user_settings):
|
||||
if key not in default_settings:
|
||||
output.append("%s = %s ###" % (key, user_settings[key]))
|
||||
elif user_settings[key] != default_settings[key]:
|
||||
output.append("%s = %s" % (key, user_settings[key]))
|
||||
print '\n'.join(output)
|
||||
diffsettings.args = ""
|
||||
|
||||
def install(app):
|
||||
"Executes the equivalent of 'get_sql_all' in the current database."
|
||||
from django.db import connection, transaction
|
||||
@ -1016,6 +1042,7 @@ run_shell.args = '[--plain]'
|
||||
DEFAULT_ACTION_MAPPING = {
|
||||
'adminindex': get_admin_index,
|
||||
'createcachetable' : createcachetable,
|
||||
'diffsettings': diffsettings,
|
||||
'inspectdb': inspectdb,
|
||||
'install': install,
|
||||
'reset': reset,
|
||||
@ -1037,6 +1064,7 @@ DEFAULT_ACTION_MAPPING = {
|
||||
NO_SQL_TRANSACTION = (
|
||||
'adminindex',
|
||||
'createcachetable',
|
||||
'diffsettings',
|
||||
'install',
|
||||
'reset',
|
||||
'sqlindexes',
|
||||
@ -1059,7 +1087,7 @@ def get_usage(action_mapping):
|
||||
for a in available_actions:
|
||||
func = action_mapping[a]
|
||||
usage.append(" %s %s" % (a, func.args))
|
||||
usage.extend(textwrap.wrap(getattr(func, 'help_doc', func.__doc__), initial_indent=' ', subsequent_indent=' '))
|
||||
usage.extend(textwrap.wrap(getattr(func, 'help_doc', textwrap.dedent(func.__doc__.strip())), initial_indent=' ', subsequent_indent=' '))
|
||||
usage.append("")
|
||||
return '\n'.join(usage[:-1]) # Cut off last list element, an empty space.
|
||||
|
||||
@ -1102,7 +1130,7 @@ def execute_from_command_line(action_mapping=DEFAULT_ACTION_MAPPING):
|
||||
|
||||
if action == 'shell':
|
||||
action_mapping[action](options.plain is True)
|
||||
elif action in ('syncdb', 'validate'):
|
||||
elif action in ('syncdb', 'validate', 'diffsettings'):
|
||||
action_mapping[action]()
|
||||
elif action == 'inspectdb':
|
||||
try:
|
||||
|
@ -64,6 +64,18 @@ backend. See the `cache documentation`_ for more information.
|
||||
|
||||
.. _cache documentation: http://www.djangoproject.com/documentation/cache/
|
||||
|
||||
diffsettings
|
||||
------------
|
||||
|
||||
Displays differences between the current settings file and Django's default
|
||||
settings.
|
||||
|
||||
Settings that don't appear in the defaults are followed by ``"###"``. For
|
||||
example, the default settings don't define ``ROOT_URLCONF``, so
|
||||
``ROOT_URLCONF`` is followed by ``"###"`` in the output of ``diffsettings``.
|
||||
|
||||
Note that Django's default settings live in ``django/conf/global_settings.py``.
|
||||
|
||||
inspectdb [dbname]
|
||||
------------------
|
||||
|
||||
|
@ -93,6 +93,17 @@ Here's the algorithm Django uses in compiling settings:
|
||||
Note that a settings file should *not* import from ``global_settings``, because
|
||||
that's redundant.
|
||||
|
||||
Seeing which settings you've changed
|
||||
------------------------------------
|
||||
|
||||
There's an easy way to view which of your settings deviate from the default
|
||||
settings. The command ``python manage.py diffsettings`` displays differences
|
||||
between the current settings file and Django's default settings.
|
||||
|
||||
For more, see the `diffsettings documentation`_.
|
||||
|
||||
.. _diffsettings documentation: http://www.djangoproject.com/documentation/django_admin/#diffsettings
|
||||
|
||||
Using settings in Python code
|
||||
=============================
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user