Booktype is a typical Django application and uses standard way to set default configuration. This document describes two additional methods that are used for configuration.
This is the workflow if new configuration API is used for accessing variables:
- First check the dynamic configuration
- Then look in the settings.py file
- Still can't find it? Then look at the constants.
- If it is not defined anywhere then just return predefined value provided with API call (default it is None)
Not every access to variables defined in settings should use this new API.
Because of this new API we will not have to handle configuration variables like this:
but rather like this:
Constants are default values provided with Booktype source. Thy are defined inside of file booki/constants.py. Constants help us provide predefined values for variables but also help us during the upgrade process. If user does not upgrade settings.py file with new configuration options Booktype will still be aware of the new configuration options because they will be defined as constants.
This is a default configuration file and is placed inside of Booktype project. Dynamic configuration is loaded from this file. If it is not loaded (for instance, user did not upgrade his settings.py with provided function calls) API will still work for accessing the configuration (but it will not be able to work with dynamic configuration).
Content of dynamic configuration is saved as JSON encoded file "configuration.json" in Booktype project directory. Dynamic configuration will help us configure Booktype from external scripts of from Booktype Control Center (web interface for administrators). Content of variable can be any value that can be serialized as JSON string.
List of functions:
- getConfiguration(name, default_value)
- setConfiguration(name, value)
When using "getConfiguration" function it will look inside of "dynamic configuration", "constants values" and settings.py but when using "setConfiguration" it will only change values in "dynamic configuration". We can have easily the same configuration variables in "dynamic configuration" and settings.py but content of "dynamic configuration" will always have higher priority.
Part of the settings.py file:
Used in the code: