HOW TO set up a Configuration form

Eric BREHAULT edited this page Sep 23, 2016 · 1 revision

Configuration forms allows managing parameters or lists both outside as well as part of the database design.

This is an alternative approach to Configuration documents.

Create a configuration form, e.g. frmConfiguration.

This form contains fields for all the parameters you want it to manage. For simple text fields, fill in a default value. For selection fields or datagrid fields, supply a Selection list formula, e.g. for an owner_type field, you may have:

return ['Owner|owner',"Owner's agent|owners_agent"]

and a default value, e.g.

return ['owner','owners_agent']

The title formula of the configuration form should be a fixed value, e.g.

return 'configuration'

When you browse to the configuration form, it should send you to the configuration document, if it exists. You can manage that in an event:

db = plominoContext.getParentDatabase()
req = getattr(plominoContext, 'REQUEST', None)

config = db.getDocument('configuration')
if config:
    req.RESPONSE.redirect(config.doc_url())

return False

Now site editors can change the available owner types by editing the 'configuration' document, and formulas can get the available owner types by looking at that document:

db = plominoDocument.getParentDatabase()
config = db.getDocument('configuration')
available_types = config.getItem('owner_types')
In order to format such a list with labels, you need to get the selection list from the form. To do that, create a script library called e.g. libConfig:

db = plominoContext.getParentDatabase()

config = db.getDocument('configuration')
frmConfig = db.getForm('frmConfiguration')
separator = '|'

def libConfig_getSelectionList(key):
    """ Get the selection list directly.
    """
    return frmConfig.getFormField(key).getSettings().getSelectionList(config)

def libConfig_getValuesAsDict(key):
    """ Look up a config value by name, return the value as a dictionary, splitting each line on `separator`.
    """
    selection_list = libConfig_getSelectionList(key)
    d = {}
    for row in selection_list:
        (label, key) = row.split(separator)
        d[key] = label
    return d

Now, if you want to present a selection based on the default list, use this as selection formula:

#Plomino import libConfig
return libConfig_getSelectionList('owner_types')

Since configuration values are often quite intertwined with the application, i.e. field formulas may expect to find certain configuration values in place, it makes sense to define them as part of the design.