comparison 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
comparison
equal deleted inserted replaced
3070:1370323e8f6c 3071:68d423f4fb55
403 if not values_list: 403 if not values_list:
404 # if values don't map to allowed values, we use default ones 404 # if values don't map to allowed values, we use default ones
405 values_list = field.values 405 values_list = field.values
406 elif field.ext_type == 'xml': 406 elif field.ext_type == 'xml':
407 # FIXME: XML elements are not handled correctly, we need to know if we 407 # FIXME: XML elements are not handled correctly, we need to know if we
408 # actual XML/XHTML, or text to escape 408 # have actual XML/XHTML, or text to escape
409 for idx, value in enumerate(values_list[:]): 409 for idx, value in enumerate(values_list[:]):
410 if not isinstance(value, domish.Element): 410 if isinstance(value, domish.Element):
411 if (field.value and (value.name != field.value.name
412 or value.uri != field.value.uri)):
413 # the element is not the one expected in form, so we create the right element
414 # to wrap the current value
415 wrapper_elt = domish.Element((field.value.uri, field.value.name))
416 wrapper_elt.addChild(value)
417 values_list[idx] = wrapper_elt
418 else:
419 # we have to convert the value to a domish.Element
411 if field.value and field.value.uri == C.NS_XHTML: 420 if field.value and field.value.uri == C.NS_XHTML:
412 div_elt = domish.Element((C.NS_XHTML, 'div')) 421 div_elt = domish.Element((C.NS_XHTML, 'div'))
413 div_elt.addContent(str(value)) 422 div_elt.addContent(str(value))
414 values_list[idx] = div_elt 423 values_list[idx] = div_elt
415 else: 424 else:
416 raise NotImplementedError 425 # only XHTML fields are handled for now
426 raise NotImplementedError
417 427
418 field.values = values_list 428 field.values = values_list
419 429
420 yield self._p.sendItem( 430 yield self._p.sendItem(
421 client, service, nodeIdentifier, form.toElement(), item_id, extra 431 client, service, nodeIdentifier, form.toElement(), item_id, extra