Created
November 18, 2013 13:09
-
-
Save jean/7527482 to your computer and use it in GitHub Desktop.
Get label from selection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <plominodatabase id="pooldb"> | |
| <design> | |
| <resource id="libConfig" title="" type="Script (Python)"><![CDATA[## Script (Python) "libConfig" | |
| ##bind container=container | |
| ##bind context=context | |
| ##bind namespace= | |
| ##bind script=script | |
| ##bind subpath=traverse_subpath | |
| ##parameters= | |
| ##title= | |
| ## | |
| db = plominoContext.getParentDatabase() | |
| config = db.getDocument('configuration') | |
| frmConfig = db.getForm('frmConfiguration') | |
| separator = '|' | |
| def libConfig_getSelectionList(key): | |
| """ Get the selection list for this field. | |
| """ | |
| selection_list = [] | |
| form_field = frmConfig.getFormField(key) | |
| if form_field: | |
| selection_list = form_field.getSettings().getSelectionList(config) | |
| return selection_list | |
| 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, selection_key) = row.split(separator) | |
| d[selection_key] = label | |
| return d | |
| def libConfig_getLabelFromDict(key, value): | |
| """ Look up a config value by name, return the label by given value searched in the dictionary. | |
| """ | |
| selection_list = libConfig_getSelectionList(key) | |
| empty_label = '' | |
| for row in selection_list: | |
| (label, selection_key) = row.split(separator) | |
| if selection_key == value: | |
| return label | |
| return empty_label | |
| ]]></resource> | |
| </design> | |
| </plominodatabase> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment