Opened 9 years ago

Closed 9 years ago

#1549 closed enhancement (fixed)

[patch] django-admin.py diffsettings: display differences between project settings and default settings

Reported by: pb@… Owned by: adrian
Component: Core (Management commands) Version: magic-removal
Severity: minor Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Per Adrian's encouragement (http://groups.google.com/group/django-developers/msg/069f6ed196c7c771), here's some code that does a diff-like operation between the current project's settings.py and Django's default settings.

Example usage: manage.py diffsettings (also works with django-admin.py)

This produces a clean, sorted, comment-free list of the settings that diverge from the defaults. Settings with no corresponding default values are followed by '###'; it seemed like a good idea to highlight "new" settings (including user-created ones), but I also wanted the output of this command to be usable as a settings file -- in theory, you could clean up your settings file by replacing it with the output of this command.

It's modeled after Postfix's "postconf -n", which is often used on the Postfix mailing for troubleshooting.

If this isn't deemed useful, no problem, but I wanted to contribute it just in case. Suggestions for a better command name than "diffsettings" are especially welcome.

Attachments (2)

diffsettings.patch (2.5 KB) - added by pb@… 9 years ago.
patch to core/management.py
diffsettings2.patch (837 bytes) - added by pb@… 9 years ago.
Python 2.3 compatible version

Download all attachments as: .zip

Change History (10)

Changed 9 years ago by pb@…

patch to core/management.py

comment:1 Changed 9 years ago by pb@…

  • Version set to magic-removal

(Set version to magic-removal)

comment:2 Changed 9 years ago by pb@…

  • Summary changed from [patch] Display differences between project settings and default settings to [patch] django-admin.py diffsettings: display differences between project settings and default settings

(clarification)

comment:3 Changed 9 years ago by adrian

Thanks very much for this awesome patch!

comment:4 Changed 9 years ago by adrian

  • Resolution set to fixed
  • Status changed from new to closed

(In [2671]) magic-removal: Fixed #1549 -- Added 'manage.py diffsettings', which displays differences between project settings and default settings. Thanks, Paul B.

comment:5 Changed 9 years ago by Petar Marić <petar.maric@…>

  • Resolution fixed deleted
  • Status changed from closed to reopened

Doesn't work for me.

$ python manage.py diffsettings
Traceback (most recent call last):
  File "manage.py", line 11, in ?
    execute_manager(settings)
  File "/home/userX/django_src/django/core/management.py", line 1212, in execute_manager
    execute_from_command_line(action_mapping)
  File "/home/userX/django_src/django/core/management.py", line 1134, in execute_from_command_line
    action_mapping[action]()
  File "/home/userX/django_src/django/core/management.py", line 535, in diffsettings
    for key in sorted(user_settings):
NameError: global name 'sorted' is not defined

comment:6 Changed 9 years ago by hugo

Hmm. sounds like some python2.4-ism

Changed 9 years ago by pb@…

Python 2.3 compatible version

comment:7 Changed 9 years ago by pb@…

Hugo's correct, sorry about that. Uploaded a fix (and made the imports a one-liner).

Also, it's note that django.conf.init changes the INSTALLED_APPS tuple to a list -- that's bound to confuse someone. Maybe add a note to the docstring?

comment:8 Changed 9 years ago by adrian

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [2674]) magic-removal: Fixed #1549 -- Removed Python 2.4ism introduced in [2671]

Note: See TracTickets for help on using tickets.
Back to Top