A convenience class for providing default values for a django app setting.
Project description
django-pluggableappsettings
This app provides a baseclass to easily realize AppSettings for any django project. The advantage of using an AppSettings class lies in the possibility for the programmer to assign default values for settings if the setting is not present in the main settings.py
Quick start
Install django-pluggableappsettings
From the pip repository: pip install django-pluggableappsettings
or directly from github: `pip install git+git://github.com/NB-Dev/django-pluggableappsettings.git
Create your AppSettings class in any of your project’s files. E.g. in ‘app_settings.py’.
Provide default values for any Setting you like by providing an attribute with the name ‘DEFAULT‘ in your AppSettings class
from django_pluggableappsettings import AppSettings class MyAppSettings(AppSettings): _DEFAULT_MY_SETTING = True
Access the setting from anywhere:
from app_settings import MyAppSettings setting = MyAppSettings.MY_SETTING
Default Values
Default values can either be fixed values or a callable function. If a callable function is provided, it will be called without any parameters. If you use a static function, that is not bound to a class, you have to set it using the staticmethod function as it would otherwise be bound to your MyAppSettings class and not work. e.g.:
``` from django_pluggableappsettings import AppSettings def function(): return 'Abc' class MyAppSettings(AppSettings): _DEFAULT_MY_SETTING = staticmethod(function) ```
Accessing Values
You can access any setting by simply importing your AppSettings class and accessing the corresponding attribute. If the corresponding setting is not set in the settings.py, it will fall back to the corresponding _DEFAULT_ value. If the __DEFAULT__ value is not set, an AttributeError is raised.
Running the tests
The included tests can be run standalone by running the tests/runtests.py script. You need to have Django and mock installed for them to run. If you also want to run coverage, you need to install it before running the tests
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for django-pluggableappsettings-0.1.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | e85c68bcd1426341a1f9dbbffcc2c7b7a0b35e37c6e8ed81d490e53defebfe79 |
|
MD5 | e57bd9b252e0e7b0b1e52c01432a946f |
|
BLAKE2b-256 | 0091f2df98a9e8e3d621a1c067cc866ca12af6e1a2f15b89175b91ba91f088cf |