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:
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

class djconfig.conf.Config[source]

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

_register(form_class, check_middleware=True)[source]

Register a config form into the registry

Parameters:
_reload_maybe()[source]

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.

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. The initial 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
save()[source]

Save the config with the cleaned data, update the last modified date so the config is reloaded on other process/nodes. Reload the config so it can be called right away.

Template Context Processors

djconfig.context_processors.config(request)[source]

Simple context processor that puts the config into every RequestContext. Just make sure you have a setting like this:

TEMPLATE_CONTEXT_PROCESSORS = (
    # ...
    'djconfig.context_processors.config',
)

Middlewares

class djconfig.middleware.DjConfigMiddleware(get_response=None)[source]

Populate the cache using the database. Reload the cache only if it is not up to date with the config model

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