memory (params): forbid to pass a value to a parameter of type "list" with <param value...>

This commit is contained in:
souliane 2015-12-15 13:33:35 +01:00
commit a29630c3b6

View file

@ -358,21 +358,21 @@ class Params(object):
if node.getAttribute('type') == 'int': if node.getAttribute('type') == 'int':
return int(value_to_use) return int(value_to_use)
elif node.getAttribute('type') == 'list': elif node.getAttribute('type') == 'list':
assert not value_to_use # only accept <option selected...> and not <param value...>
options = [option for option in node.childNodes if option.nodeName == 'option'] options = [option for option in node.childNodes if option.nodeName == 'option']
values = [option.getAttribute('value') for option in options] 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']
selected = [option for option in options if option.getAttribute('selected') == 'true'] cat, param = node.parentNode.getAttribute('name'), node.getAttribute('name')
cat, param = node.parentNode.getAttribute('name'), node.getAttribute('name') if len(selected) == 1:
if len(selected) == 1: value_to_use = selected[0].getAttribute('value')
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'") %
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})
{'cat': cat, 'param': param, 'value': value_to_use}) return value_to_use
return value_to_use if len(selected) == 0:
if len(selected) == 0: log.error(_(u'Parameter (%(cat)s, %(param)s) of type list has no default option!') % {'cat': cat, 'param': param})
log.error(_(u'Parameter (%(cat)s, %(param)s) of type list has no default option!') % {'cat': cat, 'param': param}) else:
else: log.error(_(u'Parameter (%(cat)s, %(param)s) of type list has more than one default option!') % {'cat': cat, 'param': param})
log.error(_(u'Parameter (%(cat)s, %(param)s) of type list has more than one default option!') % {'cat': cat, 'param': param}) raise exceptions.DataError
raise exceptions.DataError
elif node.getAttribute('type') == 'jids_list': elif node.getAttribute('type') == 'jids_list':
if not value_to_use: if not value_to_use:
log.debug(u"jids list value is empty") log.debug(u"jids list value is empty")