Application configuration with aldryn_config.py¶
Divio Cloud provides for such configuration through an addon’s file. This file needs to be in the root directory of theAddon.
Through this mechanism you can also allow the user to provide configuration ina simple web form that will be available in the Control Panel.
When the user saves the web form, the data will be stored in the addon’s settings.json
file inthe project repository.
An example from a django CMS addon instance:
See the Application configuration with aldryn_config.py reference for more detail.
This file contain a class named Form
that sub-classesaldryn_client.forms.BaseForm
:
A method on the Form
class will be called. Use this toreturn a dictionary of settings.
It takes two arguments:
- the cleaned_data from the form
- a dictionary containing the existing settings
Add or manipulate the settings in the dictionary as required, and return it.
If you wish to accept user-supplied configuration, you will need to add someform fields to the form (see below).
ADDON_URLS
(and related settings) to help manage URLconfigurations via settings.
We can define them in the to_settings()
method of an application to do this.
Here’s an example of that inserts URL configurations intoa project:
The Form
class may contain any number of form fields.
Available fields are:
- aldryn_client.forms.CheckboxField
- aldryn_client.forms.SelectField (required second argument: a list oftuples)
- aldryn_client.forms.NumberField (optional arguments: min_value andmax_value )
Here’s an example:
For custom field validation, sub-class a field and overwrite its clean()
method. The method takes a single argument (the value to be cleaned) and should either return a cleaned value or raise a aldryn_client
with a useful message about why the validation failed.
.forms.ValidationError
Example: