Mercurial > libervia-backend
comparison src/tools/xml_tools.py @ 1220:f91e7028e2c3
memory (params), tools (xml_tools), plugins, frontends: add "int" parameter type with "min" and "max" attributes
author | souliane <souliane@mailoo.org> |
---|---|
date | Fri, 03 Oct 2014 12:27:43 +0200 |
parents | 96fb74a4714d |
children | 069ad98b360d |
comparison
equal
deleted
inserted
replaced
1219:16484ebb695b | 1220:f91e7028e2c3 |
---|---|
68 elif field.fieldType == 'boolean': | 68 elif field.fieldType == 'boolean': |
69 widget_type = "bool" | 69 widget_type = "bool" |
70 if widget_args[0] is None: | 70 if widget_args[0] is None: |
71 widget_args[0] = 'false' | 71 widget_args[0] = 'false' |
72 widget_kwargs['read_only'] = read_only | 72 widget_kwargs['read_only'] = read_only |
73 elif field.fieldType == 'integer': | |
74 widget_type = "integer" | |
75 widget_kwargs['read_only'] = read_only | |
73 elif field.fieldType == 'list-single': | 76 elif field.fieldType == 'list-single': |
74 widget_type = "list" | 77 widget_type = "list" |
75 widget_kwargs["options"] = [(option.value, option.label or option.value) for option in field.options] | 78 widget_kwargs["options"] = [(option.value, option.label or option.value) for option in field.options] |
76 widget_kwargs["selected"] = widget_args | 79 widget_kwargs["selected"] = widget_args |
77 widget_args = [] | 80 widget_args = [] |
694 | 697 |
695 class JidInputWidget(StringWidget): | 698 class JidInputWidget(StringWidget): |
696 type = 'jid_input' | 699 type = 'jid_input' |
697 | 700 |
698 | 701 |
702 # TODO handle min and max values | |
703 class IntWidget(StringWidget): | |
704 type = 'int' | |
705 | |
706 def __init__(self, xmlui, value=0, name=None, parent=None, read_only=False): | |
707 try: | |
708 int(value) | |
709 except ValueError: | |
710 raise exceptions.DataError(_("Value must be an integer")) | |
711 super(IntWidget, self).__init__(xmlui, value, name, parent, read_only=read_only) | |
712 | |
713 | |
699 class BoolWidget(InputWidget): | 714 class BoolWidget(InputWidget): |
700 type = 'bool' | 715 type = 'bool' |
701 | 716 |
702 def __init__(self, xmlui, value='false', name=None, parent=None, read_only=False): | 717 def __init__(self, xmlui, value='false', name=None, parent=None, read_only=False): |
703 if isinstance(value, bool): | 718 if isinstance(value, bool): |
704 value = 'true' if value else 'false' | 719 value = 'true' if value else 'false' |
705 elif value == '0': | 720 elif value == '0': |
706 value='false' | 721 value = 'false' |
707 elif value == '1': | 722 elif value == '1': |
708 value='true' | 723 value = 'true' |
709 if not value in ('true', 'false'): | 724 if value not in ('true', 'false'): |
710 raise exceptions.DataError(_("Value must be 0, 1, false or true")) | 725 raise exceptions.DataError(_("Value must be 0, 1, false or true")) |
711 super(BoolWidget, self).__init__(xmlui, name, parent, read_only=read_only) | 726 super(BoolWidget, self).__init__(xmlui, name, parent, read_only=read_only) |
712 self.elem.setAttribute('value', value) | 727 self.elem.setAttribute('value', value) |
713 | 728 |
714 | 729 |