Stay informed of it
Project description
Django Dynamic Settings
Django Dynamic Settings allows you to create & use dynamic settings backed by a database.
Installation
Installation using pip:
pip install dj-dynamic-settings
dj_dynamic_settings
app has to be added to INSTALLED_APPS
and migrate
command has to be run.
INSTALLED_APPS = (
# other apps here...
"dj_dynamic_settings",
)
dj_dynamic_settings.urls
must be included to a desired url path.
urlpatterns = [
...,
url(r"^api/v1/", include("dj_dynamic_settings.urls")),
]
Setting class must be defined & registered. Please make sure that this class' module runs whenever the application runs.
from dj_dynamic_settings.registry import BaseSetting, registry
from dj_dynamic_settings.validators import TypeValidator
@registry.register
class FeatureActive(BaseSetting):
key = "FEATURE_ACTIVE"
validators = [TypeValidator(bool)]
default = False
description = "Flag for Feature X"
Create Setting
instance using view.
import requests
requests.post(
url="https://your-app.com/api/v1/dynamic_settings/",
headers={
"Authorization": "Token <secret-login-token>",
},
json={
"key": "FEATURE_ACTIVE",
"value": True,
"is_active": True,
}
)
Access this setting as in django.conf.settings
from dj_dynamic_settings.conf import settings
settings.FEATURE_ACTIVE # True
Create / Update Triggers
To fire a callback method when a specific setting value updated or created, you can implement post_save_actions
in BaseSetting
inherited class
Following example shows how to implement post_save_actions
method.
The callback method will be called with following kwargs:
key=instance.key
value=instance.value
created=created # is create operation
Note: post_save_actions
returns an array, so you can add multiple callback methods. These callback methods will be called synchronously.
class PostUpdateTestConfiguration(BaseSetting):
key = "X_FEATURE_POST_UPDATE"
validators = [...]
@classmethod
def post_save_actions(cls):
return [
on_data_updated,
]
def on_data_updated(*args, **kwargs):
pass
Testing Tools
override_settings()
You can override a setting for a test method or test class.
from dj_dynamic_settings.utils import override_settings
from django.test import TestCase
@override_settings(SOME_SETTING="some_setting")
class FeatureTestCase(TestCase):
@override_settings(SOME_OTHER_SETTING="SOME_OTHER_SETTING")
def test_feature(self):
# Some stuff
pass
def test_feature_x(self):
with override_settings(SOME_OTHER_SETTING="SOME_OTHER_SETTING"):
# Some stuff
pass
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
Built Distribution
Hashes for dj-dynamic-settings-0.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8aa7db37798c173e2813dd5eca7029dfec5759307264184171c73f7a04eb1817 |
|
MD5 | f3d280eea83ea537a04ec844337a4488 |
|
BLAKE2b-256 | 5b54f07a36137f85858d80891201fd14099d1788e1eeabd98cf73dca762ce669 |
Hashes for dj_dynamic_settings-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6693bd4b836e061c57965d45d52eca300aa32901f700b9b49651ce6e590ed53c |
|
MD5 | a28dd053cdb9ba4f00d96d273d5ca8ae |
|
BLAKE2b-256 | 82d89f4b955aac9f8b37ab69bc3a30ca3ef6f95058c7560f36244c230f6a4635 |