tools (xml_tools): new dataForm2dataDict and dataDict2dataForm:
those methods convert a serialisable dict format to `wokkel.data_form.Form` and vice versa
This commit is contained in:
parent
e60d563d27
commit
026ac9db13
1 changed files with 94 additions and 33 deletions
|
|
@ -20,10 +20,10 @@ from typing import List, Tuple, Optional
|
|||
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 @@ class PubsubLists:
|
|||
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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue