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.
This commit is contained in:
Goffi 2021-12-08 15:45:57 +01:00
commit 03ca0037f3

View file

@ -60,7 +60,7 @@ def _dataFormField2XMLUIData(field, read_only=False):
@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 @@ def _dataFormField2XMLUIData(field, read_only=False):
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 @@ def _dataFormField2XMLUIData(field, read_only=False):
]
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 @@ def XMLUIResult2DataFormResult(xmlui_data):
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