changeset 3716:d33da3fe34a5

tools (xml_tools): implement `list-multi` in `_dataFormField2XMLUIData`: `list-multi` was missing and thus these data form field type was not supported, resulting in those fields shown as a text field. Due to legacy, current implementation use a hack to split values, this should be fixed later by using proper serialisation.
author Goffi <goffi@goffi.org>
date Wed, 08 Dec 2021 15:45:57 +0100
parents b9718216a1c0
children 11f7ca8afd15
files sat/tools/xml_tools.py
diffstat 1 files changed, 18 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/sat/tools/xml_tools.py	Wed Dec 01 16:13:31 2021 +0100
+++ b/sat/tools/xml_tools.py	Wed Dec 08 15:45:57 2021 +0100
@@ -60,7 +60,7 @@
     @param read_only (bool): if True and it makes sense, create a read only input widget
     @return: a tuple (widget_type, widget_args, widget_kwargs)
     """
-    widget_args = [field.value]
+    widget_args = field.values or [None]
     widget_kwargs = {}
     if field.fieldType is None and field.ext_type is not None:
         # we have an extended field
@@ -76,6 +76,7 @@
                 widget_args[0] = element.toXml()
                 widget_kwargs["read_only"] = read_only
         else:
+
             raise exceptions.DataError("unknown extended type {ext_type}".format(
                 ext_type = field.ext_type))
 
@@ -119,6 +120,14 @@
         ]
         widget_kwargs["selected"] = widget_args
         widget_args = []
+    elif field.fieldType == "list-multi":
+        widget_type = "list"
+        widget_kwargs["options"] = [
+            (option.value, option.label or option.value) for option in field.options
+        ]
+        widget_kwargs["selected"] = widget_args
+        widget_kwargs["styles"] =  ["multi"]
+        widget_args = []
     else:
         log.error(
             "FIXME FIXME FIXME: Type [%s] is not managed yet by SàT" % field.fieldType
@@ -426,9 +435,14 @@
     for key, value in xmlui_data.items():
         if not key.startswith(SAT_FORM_PREFIX):
             continue
-        if isinstance(value, str) and '\n' in value:
-            # data form expects multi-lines text to be in separated values
-            value = value.split('\n')
+        if isinstance(value, str):
+            if "\n" in value:
+                # data form expects multi-lines text to be in separated values
+                value = value.split('\n')
+            elif "\t" in value:
+                # FIXME: workaround to handle multiple values. Proper serialisation must
+                #   be done in XMLUI
+                value = value.split("\t")
         ret[key[len(SAT_FORM_PREFIX) :]] = _cleanValue(value)
     return ret