Package: django-pluggableappsettings
django-pluggableappsettingsThis 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.pyRequirements:Django >= 2.0Quick startInstall django-pluggableappsettingsFrom the pip repository:pip install django-pluggableappsettingsor directly from github:pip install git+git://github.com/NB-Dev/django-pluggableappsettings.gitCreate your AppSettings class in any of your project's files. E.g. in 'app_settings.py'.Define your settings by setting the class attributes as one of the provided settings typesfrom django_pluggableappsettings import AppSettings, Setting

class MyAppSettings(AppSettings):
	MY_SETTING = Setting('DEFAULT_VALUE')Access the setting from anywhere:from app_settings import MyAppSettings
setting = MyAppSettings.MY_SETTINGProvided Setting TypesDifferent setting types are provided with the package:Setting(default_value, setting_name, aliases)The most basic setting that looks up the setting's value from thesettings.pyusually the attribute name is used for
the detection. If, however, thesettings_nameparameter is given, this name is used instead for the lookup in thesettings.py. It simply returns the value from the settings.py or, if that is not set, the default value.
If no default value is provided and the setting is not set in your settings.py, anAttributeErroris thrown.
Also a list of aliases can be passed to allow for multiple names of one setting (e.g. for backwards compatibility)CalledOnceSetting(default_value, setting_name, aliases, force_callable=False)Checks whether the value is callable and calls it once before returning. Subsequent accesses to this setting return the
cached return value of the first call. Ifforce_callableisTrue, the setting throws aValueErrorif the value of
the setting is not callable.CalledEachTimeSetting(default_value, setting_name, aliases, force_callable=False)Checks whether the value is callable. If so, the callable is called each time when the setting is
accessed. Ifforce_callableisTrue, the setting throws aValueErrorif the value of the setting is not callable.ClassSetting(default_value, setting_name, aliases)Behaves as a Setting but accepts only Classes or dotted paths to classes as values. If the value is a dotted path, the
path is translated to a class before returning, so the returned value is always a class.IntSetting(default_value, setting_name, aliases)Accepts only values that are of type int or can be casted to type intFloatSetting(default_value, setting_name, aliases)Accepts only values of type float of values that can be casted to type floatStringSetting(default_value, setting_name, aliases)Accepts only strings as valueIterableSetting(default_value, setting_name, aliases)Makes sure that the value is an iterableTypedSetting(default_value, setting_name, aliases)A class that checks whether the given value is of a certain type and optionally allows casting the value to that type.
Used as a base class for all type checking classes and can be easily subclassed to allow checking of various
value types.To create your own type checking setting simply subclass this type and set the class attributes_setting_typeand_cast_valueaccording to your needs. The_setting_typeattribute specifies the desired type while the_cast_valueattribute specifies whether the value should be casted to the_setting_type. A_cast_valueofTrueessentially results in a call ofvalue = _setting_type(value).E.g. TheIntSettingis defined as follows:class IntSetting(TypedSetting):
    """
    An integer setting
    """
    _setting_type = int
    _cast_value = TrueIf you need more elaborate casting functions, you can overwrite thecast_value(self, value)function
of your type which should return the casted value.Accessing ValuesYou can access any setting by simply importing your AppSettings class and accessing the corresponding attribute.Tests with AppSettingsThe package provides a convenientoverride_appsettingsdecorator / context manager to allow for the temporary
override of AppSettings values. It is used just like Django'soverride_settingsdecorator but with an extra argument:
The AppSettings-Class that is to be altered has to be passed in as first argument. Following should be keyword, value
arguments where the keyword is the name of the setting to be overridden and the value is the desired return value.E.g.:from django_pluggableappsettings.test.utils import override_appsettings
from myapp.appsettings import MyAppSettings

class SomeTestCase(TestCase):
    @override_appsettings(MyAppSettings, SETTING='new_value')
    def test_decorated(self):
        MyAppSettings.SETTING # This returns 'new_value'

    def test_context_manager(self):
        with override_appsettings(MyAppSettings, SETTING='new_value'):
            MyAppSettings.SETTING # This returns 'new_value'Running the testsThe included tests can be run standalone by running thetests/runtests.pyscript. 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 testsCHANGELOGv. 2.1.0 (2022-01-20)Fixes deprectated location of "Iterable" in collections module to make this project Python 3.10 compatible. Thank you@kocunopfor the pull request.Move to github actions for testingRemoving support for old Python and Django Versions that are no longer officially supported. I did not actually change the codebase but removed the tests while moving to github actions.Added tests for deprecation warnings, to catch those problems ahead of time in the future.v. 2.0.3 (2020-02-14)If a setting is not defined on theAppSettingsobject, it is now retrieved fromdjango.conf.settingsif it is available there. This makes it possible to use theAppSettingsas a drop-in replacement fordjango.conf.settings. Thank you@mkay849for the pull request.v. 2.0.2 (2020-02-12)Moving to a Readme.md did not work for pypi... now it should be though.v. 2.0.0 (2020-02-12)Breaking Change: Dropping Support for Python 2. Results in a dropping of support for Django 1.x.Addings Upport for Django 2.1, 2.2 and 3.0v. 1.1.6 (2017-05-19)Fixing the README to be correctly displayed on pypiv. 1.1.5 (2017-05-19)Version bump as I forgot to convert the readme. Added a publish.py to automate publishing in future.v. 1.1.4 (2017-05-19)Adding tests for Django 1.10 and 1.11.v. 1.1.3 (2016-01-27)Adding the possibility to look for a settings value under a different name in thesettings.pyby usage of thesettings_nameparameterFixing a bug that caused allAppSettingsinstances to share the same cache of loaded settings. This could cause the
settings to be overridden by other settingsv. 1.1.2 (2016-01-15)Adding anoverride_appsettingsdecorator / context manager to allow the overriding of AppSettings values in testAdded the possibility to retrieve non-Settingattributes from theAppSettingsclass to allow for custom attributes
or custom functions.v.1.1.1I screwed up with pypi and need to bump the version number - Sorryv.1.1.0Changing structure of Setting class to being able to add repeatedly called functions as setting.Warning: This breaks compatibility of custom settings classes. To fix this, simply rename thegetmethod of
your custom classes to_getAdded aCalledEachTimeSettingthat takes a callable that is called each time the setting's value is accessedRenamed theCallableSettingtoCalledOnceSettingto make the differentiation to theCalledEachTimeSettingclearer. The old name will stay as an alias for now.TheCalledEachTimeSettingand theCalledOnceSettingtake anforce_callablekwarg to set whether the value of the
setting is enforced to be callable or not.v.1.0.0Releasing first stable versionv.0.2.3Added 'aliases' parameter toSettingto allow multiple names for one setting (e.g. for backwards compatibility)v.0.2.2Extended code to also work with Python 3v.0.2.1AddedTypedSettingSetting type which allows for the setting to be typecheckedAddedIntSetting,FloatSetting,StringSettingandÌterableSetting``` as subtypes of ```TypedSettingv.0.2.0Added the changelogRedesign of settings to allow different types of settings that can now also provide type checking.Settings are now explicitly defined and no_DEFAULT_prefix is needed anymoreAlso no staticmethod decorator is needed anymoreToDos:Allow the easy definition of multiple allowed setting types so that a setting could e.g. accept either string or an
IntegerAllow the chaining of callables with typed settings to check that the return value of a callable is of the correct
typeMaintainersThis Project is maintaned byPay-Per-X