2007-08-16 22:34:01 +08:00
|
|
|
from django.core.management.base import NoArgsCommand
|
2007-08-16 14:06:55 +08:00
|
|
|
|
|
|
|
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)])
|
|
|
|
|
2007-08-16 22:34:01 +08:00
|
|
|
class Command(NoArgsCommand):
|
2007-08-16 14:06:55 +08:00
|
|
|
help = """Displays differences between the current settings.py and Django's
|
|
|
|
default settings. Settings that don't appear in the defaults are
|
|
|
|
followed by "###"."""
|
|
|
|
|
|
|
|
requires_model_validation = False
|
|
|
|
|
2007-08-16 22:34:01 +08:00
|
|
|
def handle_noargs(self, **options):
|
2007-08-16 14:06:55 +08:00
|
|
|
# Inspired by Postfix's "postconf -n".
|
|
|
|
from django.conf import settings, global_settings
|
|
|
|
|
|
|
|
# Because settings are imported lazily, we need to explicitly load them.
|
2009-03-03 10:48:02 +08:00
|
|
|
settings._setup()
|
2007-08-16 14:06:55 +08:00
|
|
|
|
2009-03-03 10:48:02 +08:00
|
|
|
user_settings = module_to_dict(settings._wrapped)
|
2007-08-16 14:06:55 +08:00
|
|
|
default_settings = module_to_dict(global_settings)
|
|
|
|
|
|
|
|
output = []
|
2012-07-21 03:14:27 +08:00
|
|
|
for key in sorted(user_settings.keys()):
|
2007-08-16 14:06:55 +08:00
|
|
|
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]))
|
2010-02-22 07:39:27 +08:00
|
|
|
return '\n'.join(output)
|