Mercurial > libervia-backend
comparison src/memory/params.py @ 1739:a12e5e866d25
memory (params): forbid to pass a value to a parameter of type "list" with <param value...>
author | souliane <souliane@mailoo.org> |
---|---|
date | Tue, 15 Dec 2015 13:33:35 +0100 |
parents | 59a94105b138 |
children | 681fe91abcc0 |
comparison
equal
deleted
inserted
replaced
1738:baac0fc5e3ad | 1739:a12e5e866d25 |
---|---|
356 if node.getAttribute('type') == 'bool': | 356 if node.getAttribute('type') == 'bool': |
357 return C.bool(value_to_use) | 357 return C.bool(value_to_use) |
358 if node.getAttribute('type') == 'int': | 358 if node.getAttribute('type') == 'int': |
359 return int(value_to_use) | 359 return int(value_to_use) |
360 elif node.getAttribute('type') == 'list': | 360 elif node.getAttribute('type') == 'list': |
361 assert not value_to_use # only accept <option selected...> and not <param value...> | |
361 options = [option for option in node.childNodes if option.nodeName == 'option'] | 362 options = [option for option in node.childNodes if option.nodeName == 'option'] |
362 values = [option.getAttribute('value') for option in options] | 363 values = [option.getAttribute('value') for option in options] |
363 if value_to_use not in values: # value_to_use is probably empty | 364 selected = [option for option in options if option.getAttribute('selected') == 'true'] |
364 selected = [option for option in options if option.getAttribute('selected') == 'true'] | 365 cat, param = node.parentNode.getAttribute('name'), node.getAttribute('name') |
365 cat, param = node.parentNode.getAttribute('name'), node.getAttribute('name') | 366 if len(selected) == 1: |
366 if len(selected) == 1: | 367 value_to_use = selected[0].getAttribute('value') |
367 value_to_use = selected[0].getAttribute('value') | 368 log.info(_("Unset parameter (%(cat)s, %(param)s) of type list will use the default option '%(value)s'") % |
368 log.info(_("Unset parameter (%(cat)s, %(param)s) of type list will use the default option '%(value)s'") % | 369 {'cat': cat, 'param': param, 'value': value_to_use}) |
369 {'cat': cat, 'param': param, 'value': value_to_use}) | 370 return value_to_use |
370 return value_to_use | 371 if len(selected) == 0: |
371 if len(selected) == 0: | 372 log.error(_(u'Parameter (%(cat)s, %(param)s) of type list has no default option!') % {'cat': cat, 'param': param}) |
372 log.error(_(u'Parameter (%(cat)s, %(param)s) of type list has no default option!') % {'cat': cat, 'param': param}) | 373 else: |
373 else: | 374 log.error(_(u'Parameter (%(cat)s, %(param)s) of type list has more than one default option!') % {'cat': cat, 'param': param}) |
374 log.error(_(u'Parameter (%(cat)s, %(param)s) of type list has more than one default option!') % {'cat': cat, 'param': param}) | 375 raise exceptions.DataError |
375 raise exceptions.DataError | |
376 elif node.getAttribute('type') == 'jids_list': | 376 elif node.getAttribute('type') == 'jids_list': |
377 if not value_to_use: | 377 if not value_to_use: |
378 log.debug(u"jids list value is empty") | 378 log.debug(u"jids list value is empty") |
379 return [] | 379 return [] |
380 jids = value_to_use.split('\t') | 380 jids = value_to_use.split('\t') |