comparison sat/tools/xml_tools.py @ 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 a8259a1f89b2
children 0fac164ff2d8
comparison
equal deleted inserted replaced
3715:b9718216a1c0 3716:d33da3fe34a5
58 @param field (data_form.Field): a field with attributes "value", "fieldType", 58 @param field (data_form.Field): a field with attributes "value", "fieldType",
59 "label" and "var" 59 "label" and "var"
60 @param read_only (bool): if True and it makes sense, create a read only input widget 60 @param read_only (bool): if True and it makes sense, create a read only input widget
61 @return: a tuple (widget_type, widget_args, widget_kwargs) 61 @return: a tuple (widget_type, widget_args, widget_kwargs)
62 """ 62 """
63 widget_args = [field.value] 63 widget_args = field.values or [None]
64 widget_kwargs = {} 64 widget_kwargs = {}
65 if field.fieldType is None and field.ext_type is not None: 65 if field.fieldType is None and field.ext_type is not None:
66 # we have an extended field 66 # we have an extended field
67 if field.ext_type == "xml": 67 if field.ext_type == "xml":
68 element = field.value 68 element = field.value
74 log.warning("unknown XML element, falling back to textbox") 74 log.warning("unknown XML element, falling back to textbox")
75 widget_type = "textbox" 75 widget_type = "textbox"
76 widget_args[0] = element.toXml() 76 widget_args[0] = element.toXml()
77 widget_kwargs["read_only"] = read_only 77 widget_kwargs["read_only"] = read_only
78 else: 78 else:
79
79 raise exceptions.DataError("unknown extended type {ext_type}".format( 80 raise exceptions.DataError("unknown extended type {ext_type}".format(
80 ext_type = field.ext_type)) 81 ext_type = field.ext_type))
81 82
82 elif field.fieldType == "fixed" or field.fieldType is None: 83 elif field.fieldType == "fixed" or field.fieldType is None:
83 widget_type = "text" 84 widget_type = "text"
117 widget_kwargs["options"] = [ 118 widget_kwargs["options"] = [
118 (option.value, option.label or option.value) for option in field.options 119 (option.value, option.label or option.value) for option in field.options
119 ] 120 ]
120 widget_kwargs["selected"] = widget_args 121 widget_kwargs["selected"] = widget_args
121 widget_args = [] 122 widget_args = []
123 elif field.fieldType == "list-multi":
124 widget_type = "list"
125 widget_kwargs["options"] = [
126 (option.value, option.label or option.value) for option in field.options
127 ]
128 widget_kwargs["selected"] = widget_args
129 widget_kwargs["styles"] = ["multi"]
130 widget_args = []
122 else: 131 else:
123 log.error( 132 log.error(
124 "FIXME FIXME FIXME: Type [%s] is not managed yet by SàT" % field.fieldType 133 "FIXME FIXME FIXME: Type [%s] is not managed yet by SàT" % field.fieldType
125 ) 134 )
126 widget_type = "string" 135 widget_type = "string"
424 """ 433 """
425 ret = {} 434 ret = {}
426 for key, value in xmlui_data.items(): 435 for key, value in xmlui_data.items():
427 if not key.startswith(SAT_FORM_PREFIX): 436 if not key.startswith(SAT_FORM_PREFIX):
428 continue 437 continue
429 if isinstance(value, str) and '\n' in value: 438 if isinstance(value, str):
430 # data form expects multi-lines text to be in separated values 439 if "\n" in value:
431 value = value.split('\n') 440 # data form expects multi-lines text to be in separated values
441 value = value.split('\n')
442 elif "\t" in value:
443 # FIXME: workaround to handle multiple values. Proper serialisation must
444 # be done in XMLUI
445 value = value.split("\t")
432 ret[key[len(SAT_FORM_PREFIX) :]] = _cleanValue(value) 446 ret[key[len(SAT_FORM_PREFIX) :]] = _cleanValue(value)
433 return ret 447 return ret
434 448
435 449
436 def formEscape(name): 450 def formEscape(name):