| 486 | def _module_to_dict(module, omittable=lambda k: k.startswith('_')): |
| 487 | "Converts a module namespace to a Python dictionary -- used by get_settings_diff" |
| 488 | result = {} |
| 489 | keys = (k for k in dir(module) if not omittable(k)) |
| 490 | for key in keys: |
| 491 | # Use repr() so that strings are quoted etc., as in settings.py |
| 492 | result[key] = repr(getattr(module, key)) |
| 493 | return result |
| 494 | |
| 495 | def get_settings_diff(): |
| 496 | """ |
| 497 | Displays differences between the current project's settings.py |
| 498 | and Django's default settings. Setting names that do not appear |
| 499 | in the defaults are followed by "###". Inspired by Postfix's |
| 500 | "postconf -n". |
| 501 | """ |
| 502 | from django.conf import settings |
| 503 | from django.conf import global_settings |
| 504 | |
| 505 | user_settings = _module_to_dict(settings) |
| 506 | default_settings = _module_to_dict(global_settings) |
| 507 | |
| 508 | output = "" |
| 509 | for key in sorted(user_settings): |
| 510 | if key not in default_settings: |
| 511 | output += "%s = %s ###\n" % (key, user_settings[key]) |
| 512 | elif user_settings[key] != default_settings[key]: |
| 513 | output += "%s = %s\n" % (key, user_settings[key]) |
| 514 | print output |
| 515 | get_settings_diff.args = "" |
| 516 | get_settings_diff.help_doc = "Displays differences between the current project's settings.py and Django's default settings. Settings with no corresponding default values are followed by '###'." |
| 517 | |