diff sat/plugins/plugin_exp_pubsub_schema.py @ 3071:68d423f4fb55

plugin pubsub schema: fixed XML field handling in `sendDataFormItem`
author Goffi <goffi@goffi.org>
date Fri, 08 Nov 2019 12:51:03 +0100
parents fee60f17ebac
children 9d0df638c8b4
line wrap: on
line diff
--- a/sat/plugins/plugin_exp_pubsub_schema.py	Fri Nov 08 11:56:21 2019 +0100
+++ b/sat/plugins/plugin_exp_pubsub_schema.py	Fri Nov 08 12:51:03 2019 +0100
@@ -405,15 +405,25 @@
                     values_list = field.values
             elif field.ext_type == 'xml':
                 # FIXME: XML elements are not handled correctly, we need to know if we
-                #        actual XML/XHTML, or text to escape
+                #        have actual XML/XHTML, or text to escape
                 for idx, value in enumerate(values_list[:]):
-                    if not isinstance(value, domish.Element):
+                    if isinstance(value, domish.Element):
+                        if (field.value and (value.name != field.value.name
+                                             or value.uri != field.value.uri)):
+                            # the element is not the one expected in form, so we create the right element
+                            # to wrap the current value
+                            wrapper_elt = domish.Element((field.value.uri, field.value.name))
+                            wrapper_elt.addChild(value)
+                            values_list[idx] = wrapper_elt
+                    else:
+                        # we have to convert the value to a domish.Element
                         if field.value and field.value.uri == C.NS_XHTML:
                             div_elt = domish.Element((C.NS_XHTML, 'div'))
                             div_elt.addContent(str(value))
                             values_list[idx] = div_elt
-                    else:
-                        raise NotImplementedError
+                        else:
+                            # only XHTML fields are handled for now
+                            raise NotImplementedError
 
             field.values = values_list