Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
108 lines (86 sloc) 3.68 KB
This application provides a drop-in replacement for django settings.
It allows you to have different places where you put configuration bits.
By default, it supposes you will have conf/ directory, where you'll put
project-wide settings, and files like my_app/, where applications
will set their settings.
Let's look further into details.
Options can be global or belong to applications:
>>> from configurator import options
>>> options.KEY = 1
>>> options.apps['myapp'].KEY = 2
>>> type(options)
<class 'configurator.Config'>
>>> type(options.apps)
<class 'configurator.AppList'>
>>> type(options.apps['myapp'])
<class 'configurator.Config'>
If the key is missing, DictList is provided:
from configurator import options
>>> KEY = options.SOME_KEY
>>> type(KEY)
<class 'configurator.containers.DictList'>
>>> id(KEY) == id(options.SOME_KEY)
Next concept is DictList.
DictList is options holder and it allows one to set a global option in
advance, providing data from one module to another, not having to deal
with applications order in INSTALLED_APPS.
Can be used as an ordered set:
>>> KEY += 'xxx'
>>> KEY
>>> KEY -= 'yyy'
>>> KEY += 'yyy'
>>> KEY
['xxx', 'yyy']
>>> KEY -= 'xxx'
In Django, this can be used for AUTHENTICATION_BACKENDS,
LANGUAGES and other settings.
Or as an ordered dict:
>>> D = DictList()
>>> D['abc'] = 'def'
>>> D['key'] = 'value'
>>> D.default = '(default)'
>>> D
{default=(default), 'abc': 'def', 'key': 'value'}
In Django, this can be used for DATABASES setup, and, i hope, in 1.3,
for LOGGING setup and APP_MEDIA setup.
Currently Django's SortedDict is not used for DictList to not depend on
The next concept is autodiscover. It allows you to have different
configuration bits for every application or for different computers.
For basic use in django applications, you can put this call in the end
of the
It does the following:
1) puts all written in caps settings from into options,
wrapping lists, tuples and dicts into DictList
2) iterates over options.DISCOVERY_ORDER, defined by default as
the following:
ListFiles(options.lazy.CONF, 'global'),# conf/
ListFiles(options.lazy.CONF, options.lazy.SITE), # conf/<site>.py
ListFiles(options.lazy.INSTALLED_APPS, 'conf'), # app1/
ListFiles(options.lazy.APP_CONF, options.lazy.INSTALLED_APPS), # conf/
ListFiles(options.lazy.CONF, 'global', '_overrides'), # conf/
ListFiles(options.lazy.CONF, options.lazy.SITE, '_overrides'), # conf/<site>
You can set or update any option in those files, you can also modify the
order they are iterated.
Please note, that this DISCOVERY_ORDER is lazy, and you can set
options.CONF to your own folder in, or do any other thing
before DISCOVERY_ORDER will be evaluated.
3) writes updated settings back to
If you don't want to change anything in, you can do
autodiscover(), update_options() and update_back_settings() manually at
any moment of time.
Exceptions, raised in configuration modules, are isolated. If one of
your conf files failed to load, console message will appear, or, in
addition to the message, application will fail with traceback if console
is not a tty.
Known issues: since global django settings are read and set
independently from, they don't know anything about each
other. So if you do AUTHENTICATION_BACKENDS += 'logins.MyBackend', no
django.contrib.auth.backends.ModelBackend will be added.
Jump to Line
Something went wrong with that request. Please try again.