memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
This commit is contained in:
parent
20c94f1fbc
commit
ac59d061f4
1 changed files with 80 additions and 11 deletions
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue