README.rst

Django appsettings

finally, a unified system for pluggable apps to have configurable settings.
the django-appsettings app provides a clean api for keeping track of settings,
and, most importantly, having settings that are configurable for a user that
does not have write access to your server :) appsettings also provides an
interface (similar to the admin interface for models) for editing these
settings.

Features

an organized system for managing settings

degrades gracefully when there's no database (settings will just be read-only)

Todo

improve the web interface

add import/export via conf files

Usage

So you want to use this in your app? Well, just create a settings.py for your
app (which will be auto-loaded by appsettings in the same way contrib.admin
loads your admin.py) and register your settings. Example:

To enable users to edit the settings from the front end, add the following line to urls.py:

url(r'^appsettings/', include('appsettings.urls')),

If a user change the settings (from the front end) then they will be saved to the database. The settings will then be retrieved from the database whenever they are used. Retrieving the settings from the database in this way could be time / resource expensive so there are two options to speed this up:

Enable caching.

If caching is enabled the settings will be stored in the cache at initialisation time then retrieved and set to the cache whenever the settings are accessed or changed. As long as the cache backend supports cross-process caching then all threads will share the same settings.

To enable caching, add the following line to your main settings.py:

APPSETTINGS_USE_CACHE = True

and set CACHE_BACKEND to something that supports cross-process caching (i.e.: NOT 'locmem://')

Use the SettingsMiddleware

The SettingsMiddleware will copy all the settings stored in the database into the current request (thread) at the start of the request so that they do not need to be retrieved eache time they are accessed (during the request).

To use the middleware add ''appsettings.middleware.SettingsMiddleware' to the MIDDLEWARE_CLASSES in your project's setttings.py

As you can see, group names are converted to lowercase when accessing.
This is to follow the django convention set in models and other areas, and
because I think it looks better. If you have a good argument either way,
feel free to make an issue.

Special Flags

appsettings also supports a few special flags, to make settings management
easier. Currently readonly and main are supported. readonly makes
a settings group, as you can imagine, read-only; they never interact with the
database. main makes the settings accessible outside of their group.
See example: