Package: django-constance-trbs
ForkThis is a fork of the original django-constance project which can be found at:https://github.com/comoga/django-constanceMain reason for the fork is to have django-constance pip installable with
Django 1.4+ compatibility fixes.Hopefully we can have this fork merged back into the official repository as
soon as possible.It also adds the option to use a cached version of the config object.
If constance is used in a situation where there are very frequent lookups
(many per second) it is more preferable to use a cached version of the values
that is refreshed ever so often.FeaturesEasily migrate your static settings to dynamic settings.Admin interface to edit the dynamic settings.InstallationInstall from PyPI the backend specific variant of django-constance:For the (default) Redis backend:pip install django-constance[redis]For the database backend:pip install django-constance[database]Alternatively – if you’re sure that the dependencies are already
installed – you can also run:pip install django-constance-trbsOr install the git development version usingpip:pip install -e git+git://github.com/trbs/django-constance-trbs#egg=django-constance-trbsConfigurationModify yoursettings.py. Add'constance'to yourINSTALLED_APPS,
and move each key you want to turn dynamic into theCONSTANCE_CONFIGsection, like this:INSTALLED_APPS = (
    ...
    'constance',
)

CONSTANCE_CONFIG = {
    'MY_SETTINGS_KEY': {
        'default': 42,
        'help_text': 'the answer to everything'
    },
}Here,42is the default value for the keyMY_SETTINGS_KEYif it is
not found in the backend. The help text will be shown in the admin.You can usedjango.utils.datastructures.SortedDictorcollections.OrderedDictforCONSTANCE_CONFIGif you don’t want to
have your settings sorted alphabetically in the admin.See theBackendssection how to setup the backend.BackendsConstance ships with a bunch of backends that are used to store the
configuration values. By default it uses the Redis backend. To override
the default please set theCONSTANCE_BACKENDsetting to the appropriate
dotted path.Redis (default)CONSTANCE_BACKEND = 'constance.backends.redisd.RedisBackend'The is the default backend and has a couple of options:CONSTANCE_REDIS_CONNECTIONA dictionary of parameters to pass to the to Redis client, e.g.:CONSTANCE_REDIS_CONNECTION = {
    'host': 'localhost',
    'port': 6379,
    'db': 0,
}Alternatively you can use a URL to do the same:CONSTANCE_REDIS_CONNECTION = 'redis://username:password@localhost:6379/0'CONSTANCE_REDIS_CONNECTION_CLASSAn (optional) dotted import path to a connection to use, e.g.:CONSTANCE_REDIS_CONNECTION_CLASS = 'myproject.myapp.mockup.Connection'CONSTANCE_REDIS_PREFIXThe (optional) prefix to be used for the key when storing in the Redis
database. Defaults to'constance:'. E.g.:CONSTANCE_REDIS_PREFIX = 'constance:myproject:'DatabaseCONSTANCE_BACKEND = 'constance.backends.database.DatabaseBackend'If you want to use this backend you also need to add the databse backend
to yourINSTALLED_APPSsetting to make sure the data model is correctly
created:INSTALLED_APPS = (
    # other apps
    'constance.backends.database',
)It also usesdjango-picklefieldto store the values in the database, so
you need to install this library, too. E.g.:pip install django-picklefieldAlternatively follow the backend specific installation instructions above.The database backend has the ability to automatically cache the config
values and clear them when saving. You need to set the following setting
to enable this feature:CONSTANCE_DATABASE_CACHE_BACKEND = 'memcached://127.0.0.1:11211/'NoteThis won’t work with a cache backend that doesn’t support
cross-process caching, because correct cache invalidation
can’t be guaranteed.Starting in Django 1.3 you can alternatively use the name of an entry of
theCACHESsetting. E.g.:CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': '127.0.0.1:11211',
    }
}
CONSTANCE_DATABASE_CACHE_BACKEND = 'default'Just like the Redis backend you can set an optional prefix that is used during
database interactions. To keep backward compatibility it defaults to''(an empty string). To use something else do this:CONSTANCE_DATABASE_PREFIX = 'constance:myproject:'UsageConstance can be used from your Python code and from your Django templates.PythonAccessing the config variables is as easy as importing the config
object and accessing the variables with attribute lookups:from constance import config

# ...

if config.MY_SETTINGS_KEY == 42:
    answer_the_question()Django templatesTo access the config object from your template, you can either
pass the object to the template context:from django.shortcuts import render
from constance import config

def myview(request):
    return render(request, 'my_template.html', {'config': config})Or you can use the included config context processor.:TEMPLATE_CONTEXT_PROCESSORS = (
    # ...
    'constance.context_processors.config',
)This will add the config instance to the context of any template
rendered with aRequestContext.Then, in your template you can refer to the config values just as
any other variable, e.g.:<h1>Welcome on {{ config.SITE_NAME }}</h1>
{% if config.BETA_LAUNCHED %}
    Woohoo! Head over <a href="/sekrit/">here</a> to use the beta.
{% else %}
    Sadly we haven't launched yet, click <a href="/newsletter/">here</a>
    to signup for our newletter.
{% endif %}EditingFire up youradminand you should see a new app calledConstancewithMY_SETTINGS_KEYin theConfigpseudo model.By default changing the settings via the admin is only allowed for super users.
But in case you want to use the admin’s ability to implement custom
authorization checks, feel free to set theCONSTANCE_SUPERUSER_ONLYsetting
toFalseand give the users or user groups access to theconstance.change_configpermission.ScreenshotsThe standard edit screen.The virtual applicationConstanceamong your regular applications.Changelogv0.6 (2013/04/12)Added Python 3 support. Supported versions: 2.6, 2.7, 3.2 and 3.3.
For Python 3.x the use of Django > 1.5.x is required.Fixed a serious issue with ordering in the admin when using the database
backend. Thanks, Bouke Haarsma.Switch to django-discover-runner as test runner to be able to run on
Python 3.Fixed an issue with refering to static files in the admin interface
when using Django < 1.4.v0.5 (2013/03/02)Fixed compatibility with Django 1.5’s swappable model backends.Converted thekeyfield of the database backend to use aCharFieldwith uniqueness instead of justTextField.For South users we provide a migration for that change. First you
have to “fake” the initial migration we’ve also added to this release:django-admin.py migrate database --fake 0001After that you can run the rest of the migrations:django-admin.py migrate databaseFixed compatibility with Django>1.4’s way of refering to static files in
the admin.Added ability to add custom authorization checks via the newCONSTANCE_SUPERUSER_ONLYsetting.Added Polish translation. Thanks, Janusz Harkot.AllowCONSTANCE_REDIS_CONNECTIONbeing an URL instead of a dict.AddedCONSTANCE_DATABASE_PREFIXsetting allow setting a key prefix.Switched test runner to use django-nose.