memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes

This commit is contained in:
souliane 2014-10-03 12:27:43 +02:00
commit ac59d061f4

View file

@ -70,6 +70,9 @@ def _dataFormField2XMLUIData(field, read_only=False):
if widget_args[0] is None:
widget_args[0] = 'false'
widget_kwargs['read_only'] = read_only
elif field.fieldType == 'integer':
widget_type = "integer"
widget_kwargs['read_only'] = read_only
elif field.fieldType == 'list-single':
widget_type = "list"
widget_kwargs["options"] = [(option.value, option.label or option.value) for option in field.options]
@ -696,6 +699,18 @@ class JidInputWidget(StringWidget):
type = 'jid_input'
# TODO handle min and max values
class IntWidget(StringWidget):
type = 'int'
def __init__(self, xmlui, value=0, name=None, parent=None, read_only=False):
try:
int(value)
except ValueError:
raise exceptions.DataError(_("Value must be an integer"))
super(IntWidget, self).__init__(xmlui, value, name, parent, read_only=read_only)
class BoolWidget(InputWidget):
type = 'bool'
@ -703,10 +718,10 @@ class BoolWidget(InputWidget):
if isinstance(value, bool):
value = 'true' if value else 'false'
elif value == '0':
value='false'
value = 'false'
elif value == '1':
value='true'
if not value in ('true', 'false'):
value = 'true'
if value not in ('true', 'false'):
raise exceptions.DataError(_("Value must be 0, 1, false or true"))
super(BoolWidget, self).__init__(xmlui, name, parent, read_only=read_only)
self.elem.setAttribute('value', value)