memory (params): fix parameters of type "list" to use the default option when no individual value is set
This commit is contained in:
parent
c6e66eda24
commit
8eddcc4ec9
1 changed files with 16 additions and 0 deletions
|
|
@ -329,6 +329,22 @@ class Params(object):
|
|||
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)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue