Mercurial > libervia-backend
diff sat/plugins/plugin_misc_lists.py @ 3472:e12e9e1535d3
tools (xml_tools): new `dataForm2dataDict` and `dataDict2dataForm`:
those methods convert a serialisable dict format to `wokkel.data_form.Form` and vice versa
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 27 Feb 2021 18:36:38 +0100 |
parents | d897597cfa94 |
children | be6d91572633 |
line wrap: on
line diff
--- a/sat/plugins/plugin_misc_lists.py Sat Feb 27 18:33:53 2021 +0100 +++ b/sat/plugins/plugin_misc_lists.py Sat Feb 27 18:36:38 2021 +0100 @@ -20,10 +20,10 @@ from twisted.internet import defer from twisted.words.xish import domish from twisted.words.protocols.jabber import jid -from wokkel import data_form from sat.core.i18n import _, D_ from sat.core.xmpp import SatXMPPEntity from sat.core.constants import Const as C +from sat.tools import xml_tools from sat.tools.common import uri from sat.tools.common import data_format from sat.core.log import getLogger @@ -455,38 +455,13 @@ name = name.strip() if not name: name = shortuuid.uuid() - template = TEMPLATES[template_id] - - fields = [ - data_form.Field(fieldType="hidden", var=NS_TICKETS_TYPE, value=template_id) - ] - for field_data in template['fields']: - field_type = field_data.get('type', 'text-single') - kwargs = { - "fieldType": field_type, - "var": field_data["name"], - "label": field_data.get('label'), - "value": field_data.get("value"), - } - if field_type == "xhtml": - kwargs.update({ - "fieldType": None, - "ext_type": "xml", - }) - if kwargs["value"] is None: - kwargs["value"] = domish.Element((C.NS_XHTML, "div")) - elif "options" in field_data: - kwargs["options"] = [ - data_form.Option(o["value"], o.get("label")) - for o in field_data["options"] - ] - field = data_form.Field(**kwargs) - fields.append(field) - - schema = data_form.Form( - "form", - formNamespace=APP_NS_TICKETS, - fields=fields + fields = TEMPLATES[template_id]["fields"].copy() + fields.insert( + 0, + {"type": "hidden", "name": NS_TICKETS_TYPE, "value": template_id} + ) + schema = xml_tools.dataDict2dataForm( + {"namespace": APP_NS_TICKETS, "fields": fields} ).toElement() service = client.jid.userhostJID()