comparison src/tools/xml_tools.py @ 762:aed7d99276b8

core (xml_tools), frontends: added a prefix to XMLUI form names in result data, to avoid name conflicts (e.g.: if a form has name "submit", and this name is also used internally by SàT)
author Goffi <goffi@goffi.org>
date Tue, 24 Dec 2013 15:43:22 +0100
parents 2f8d72226bc0
children bfabeedbf32e
comparison
equal deleted inserted replaced
761:2f8d72226bc0 762:aed7d99276b8
22 from wokkel import data_form 22 from wokkel import data_form
23 from twisted.words.xish import domish 23 from twisted.words.xish import domish
24 from sat.core import exceptions 24 from sat.core import exceptions
25 25
26 """This library help manage XML used in SàT (parameters, registration, etc) """ 26 """This library help manage XML used in SàT (parameters, registration, etc) """
27
28 SAT_FORM_PREFIX ="SAT_FORM_"
27 29
28 30
29 def dataForm2XMLUI(form, submit_id, session_id=None): 31 def dataForm2XMLUI(form, submit_id, session_id=None):
30 """Take a data form (xep-0004, Wokkel's implementation) and convert it to a SàT xml""" 32 """Take a data form (xep-0004, Wokkel's implementation) and convert it to a SàT xml"""
31 33
113 """ 115 """
114 116
115 form_ui = XMLUI("window", "vertical", session_id=session_id) 117 form_ui = XMLUI("window", "vertical", session_id=session_id)
116 dataFormResult2AdvancedList(form_ui, form_xml) 118 dataFormResult2AdvancedList(form_ui, form_xml)
117 return form_ui 119 return form_ui
120
121 def XMLUIResult2DataFormResult(xmlui_data):
122 """ Extract form data from a XMLUI return
123 @xmlui_data: data returned by frontends for XMLUI form
124 @return: dict of data usable by Wokkel's dataform
125 """
126 return {key[len(SAT_FORM_PREFIX):]: value for key, value in xmlui_data.iteritems() if key.startswith(SAT_FORM_PREFIX)}
127
128 def XMLUIResultToElt(xmlui_data):
129 """ Construct result domish.Element from XMLUI result
130 @xmlui_data: data returned by frontends for XMLUI form
131 """
132 form = data_form.Form('result')
133 form.makeFields(XMLUIResult2DataFormResult(xmlui_data))
134 return form.toElement()
118 135
119 def tupleList2dataForm(values): 136 def tupleList2dataForm(values):
120 """convert a list of tuples (name,value) to a wokkel submit data form""" 137 """convert a list of tuples (name,value) to a wokkel submit data form"""
121 form = data_form.Form('submit') 138 form = data_form.Form('submit')
122 for value in values: 139 for value in values: