Mercurial > libervia-backend
changeset 1039:902c764a0d2b
memory (params): fix parameters of type "list" to use the default option when no individual value is set
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 20 May 2014 09:34:02 +0200 |
parents | d732bb68b326 |
children | 76ad41b708e1 |
files | src/memory/params.py |
diffstat | 1 files changed, 16 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/memory/params.py Fri May 16 11:26:46 2014 +0200 +++ b/src/memory/params.py Tue May 20 09:34:02 2014 +0200 @@ -329,6 +329,22 @@ value_to_use = value if value is not None else node.getAttribute(attr) # we use value (user defined) if it exist, else we use node's default value if node.getAttribute('type') == 'bool': return value_to_use.lower() not in ('false', '0', 'no') + elif node.getAttribute('type') == 'list': + options = [option for option in node.childNodes if option.nodeName == 'option'] + values = [option.getAttribute('value') for option in options] + if value_to_use not in values: # value_to_use is probably empty + selected = [option for option in options if option.getAttribute('selected') == 'true'] + cat, param = node.parentNode.getAttribute('name'), node.getAttribute('name') + if len(selected) == 1: + value_to_use = selected[0].getAttribute('value') + log.info(_("Unset parameter (%(cat)s, %(param)s) of type list will use the default option '%(value)s'") % + {'cat': cat, 'param': param, 'value': value_to_use}) + return value_to_use + if len(selected) == 0: + log.error(_('Parameter (%(cat)s, %(param)s) of type list has no default option!') % {'cat': cat, 'param': param}) + else: + log.error(_('Parameter (%(cat)s, %(param)s) of type list has more than one default option!') % {'cat': cat, 'param': param}) + raise exceptions.DataError return value_to_use return node.getAttribute(attr)