Mercurial > libervia-backend
comparison src/tools/xml_tools.py @ 1067:f7f15d44fdfa
tools (xml_tools): dataForm2XMLUI handles the default value for "list-single" fields
author | souliane <souliane@mailoo.org> |
---|---|
date | Thu, 12 Jun 2014 18:19:55 +0200 |
parents | 35048cafb18d |
children | 8e1f30aa3975 |
comparison
equal
deleted
inserted
replaced
1066:cbf917a90784 | 1067:f7f15d44fdfa |
---|---|
61 widget_type = "bool" | 61 widget_type = "bool" |
62 if widget_args[0] is None: | 62 if widget_args[0] is None: |
63 widget_args[0] = 'false' | 63 widget_args[0] = 'false' |
64 elif field.fieldType == 'list-single': | 64 elif field.fieldType == 'list-single': |
65 widget_type = "list" | 65 widget_type = "list" |
66 del widget_args[0] | |
67 widget_kwargs["options"] = [(option.value, option.label or option.value) for option in field.options] | 66 widget_kwargs["options"] = [(option.value, option.label or option.value) for option in field.options] |
67 widget_kwargs["selected"] = widget_args | |
68 widget_args = [] | |
68 else: | 69 else: |
69 log.error(u"FIXME FIXME FIXME: Type [%s] is not managed yet by SàT" % field.fieldType) | 70 log.error(u"FIXME FIXME FIXME: Type [%s] is not managed yet by SàT" % field.fieldType) |
70 widget_type = "string" | 71 widget_type = "string" |
71 | 72 |
72 if field.var: | 73 if field.var: |
352 super(OptionElement, self).__init__(parent.xmlui, parent) | 353 super(OptionElement, self).__init__(parent.xmlui, parent) |
353 if isinstance(option, basestring): | 354 if isinstance(option, basestring): |
354 value, label = option, option | 355 value, label = option, option |
355 elif isinstance(option, tuple): | 356 elif isinstance(option, tuple): |
356 value, label = option | 357 value, label = option |
358 else: | |
359 raise NotImplementedError | |
357 self.elem.setAttribute('value', value) | 360 self.elem.setAttribute('value', value) |
358 self.elem.setAttribute('label', label) | 361 self.elem.setAttribute('label', label) |
359 if selected: | 362 if selected: |
360 self.elem.setAttribute('selected', 'true') | 363 self.elem.setAttribute('selected', 'true') |
361 | 364 |
718 if isinstance(selected, basestring): | 721 if isinstance(selected, basestring): |
719 selected = [selected] | 722 selected = [selected] |
720 else: | 723 else: |
721 selected = [] | 724 selected = [] |
722 for option in options: | 725 for option in options: |
723 OptionElement(self, option, option in selected) | 726 assert(isinstance(option, basestring) or isinstance(option, tuple)) |
727 value = option if isinstance(option, basestring) else option[0] | |
728 OptionElement(self, option, value in selected) | |
724 | 729 |
725 | 730 |
726 ## XMLUI main class | 731 ## XMLUI main class |
727 | 732 |
728 | 733 |