diff 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
line wrap: on
line diff
--- a/src/tools/xml_tools.py	Thu Jun 12 15:57:22 2014 +0200
+++ b/src/tools/xml_tools.py	Thu Jun 12 18:19:55 2014 +0200
@@ -63,8 +63,9 @@
             widget_args[0] = 'false'
     elif field.fieldType == 'list-single':
         widget_type = "list"
-        del widget_args[0]
         widget_kwargs["options"] = [(option.value, option.label or option.value) for option in field.options]
+        widget_kwargs["selected"] = widget_args
+        widget_args = []
     else:
         log.error(u"FIXME FIXME FIXME: Type [%s] is not managed yet by SàT" % field.fieldType)
         widget_type = "string"
@@ -354,6 +355,8 @@
             value, label = option, option
         elif isinstance(option, tuple):
             value, label = option
+        else:
+            raise NotImplementedError
         self.elem.setAttribute('value', value)
         self.elem.setAttribute('label', label)
         if selected:
@@ -720,7 +723,9 @@
         else:
             selected = []
         for option in options:
-            OptionElement(self, option, option in selected)
+            assert(isinstance(option, basestring) or isinstance(option, tuple))
+            value = option if isinstance(option, basestring) else option[0]
+            OptionElement(self, option, value in selected)
 
 
 ## XMLUI main class