Skip to end of metadata
Go to start of metadata


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 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:

    OBJAVI_URL = settings.OBJAVI_URL
except AttributeError:
    OBJAVI_URL = constants.OBJAVI_URL

but rather like this:

  OBJAVI_URL = config.getConfiguration("OBJAVI_URL")


Constants are default values provided with Booktype source. Thy are defined inside of file booki/ Constants help us provide predefined values for variables but also help us during the upgrade process. If user does not upgrade 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 with provided function calls) API will still work for accessing the configuration (but it will not be able to work with dynamic configuration).

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:

  • loadConfiguration()
  • getConfiguration(name, default_value)
  • setConfiguration(name, value)
  • saveConfiguration()

When using "getConfiguration" function it will look inside of "dynamic configuration", "constants values" and but when using "setConfiguration" it will only change values in "dynamic configuration". We can have easily the same configuration variables in "dynamic configuration" and but content of "dynamic configuration" will always have higher priority.

Part of the file:

 from booki.utils import config

    BOOKTYPE_CONFIG = config.loadConfiguration()
 except config.ConfigurationError:

Used in the code:

 from booki.utils import config

 name = config.getConfiguration('BOOKTYPE_SITE_NAME', None)
 if name:
    config.setConfiguration('BOOKTYPE_SITE_NAME', 'My site')


Command line tools

List all configuration values  conflist  conflist --values
Set variable value  confset  BOOKTYPE_SITE_NAME "This is my site"  confset --append --as_json MY_LIST "[2, 3, 1]"  confset --remove --integer MY_LIST 2  confset --integer BOOKTYPE_NUMBER 21  confset --float BOOKTYPE_NUMBER 21.2
Get variable value  confget BOOKTYPE_NUMBER  confget --as_json BOOKTYPE_NUMBER
Delete variable  confdel BOOKTYPE_NUMBER
  • No labels