API¶
djconfig module¶
-
djconfig.
config
djconfig.conf.Config object (singleton)¶ Contain registry of config forms and cache of key-value matching the forms field-value.
All methods are private to avoid clashing with the dynamic attributes.
This should be usually accessed through
config
-
djconfig.
register
djconfig.conf.Config._register attribute¶ Register a config form into the registry
Parameters: - form_class (object) – The form class to register. Must be an instance of
djconfig.forms.ConfigForm
- check_middleware (bool) – Check
djconfig.middleware.DjConfigMiddleware
is registered intosettings.MIDDLEWARE_CLASSES
. Default True
- form_class (object) – The form class to register. Must be an instance of
-
djconfig.
reload_maybe
djconfig.conf.Config._reload_maybe attribute¶ Reload the config if the config model has been updated. This is called once on every request by the middleware. Should not be called directly.
Config Object¶
ConfigForm Object¶
-
class
djconfig.forms.
ConfigForm
(*args, **kwargs)[source]¶ Base class for every registered config form. It behaves like a regular form.
Inherits from
django.forms.Form
. Theinitial
attr will be updated with the config values if any.All form fields implementing this, should have a unique name to avoid clashing with other registered forms, prefixing them with the app name is a good practice.
Parameters: - args – Positional parameters passed to parent class
- kwargs – Keyword parameters passed to parent class
Template Context Processors¶
Middlewares¶
Test Helpers¶
-
djconfig.utils.
override_djconfig
(**new_cache_values)[source]¶ Temporarily override config values.
This is similar to
django.test.override_settings()
, use it in testing.Parameters: new_cache_values – Keyword arguments, the key should match one in the config, a new one is created otherwise, the value is overridden within the decorated function
Admin¶
This module allows to register a config into django’s admin.
Usage:
class FooConfigAdmin(djconfig.admin.ConfigAdmin):
change_list_form = FooConfigForm
class FooConfig(djconfig.admin.Config):
app_label = 'djconfig'
verbose_name_plural = 'foo config'
name = 'fooconfig'
djconfig.admin.register(FooConfig, FooConfigAdmin)
-
djconfig.admin.
register
(conf, conf_admin, **options)[source]¶ Register a new admin section.
Parameters: - conf – A subclass of
djconfig.admin.Config
- conf_admin – A subclass of
djconfig.admin.ConfigAdmin
- options – Extra options passed to
django.contrib.admin.site.register
- conf – A subclass of
-
class
djconfig.admin.
ConfigAdmin
(model, admin_site)[source]¶ A
ConfigAdmin
is subclass ofdjango.contrib.admin.ModelAdmin
.change_list_form
class var must be set to a validdjconfig.forms.ConfigForm
subclass
-
class
djconfig.admin.
Config
[source]¶ A
Config
is akin to django’s modelMeta
class.app_label
must be a valid installed app,'djconfig'
may be used for every registered form, if they don’t belong in a particular app.verbose_name_plural
is the title of the admin’s section link, it can be anything. The (app_label
,verbose_name_plural
,name
) must be unique together across registered forms.name
is used as the link slug, and it might be used in other places, valid chars are[a-zA-Z_]