comparison src/tools/xml_tools.py @ 796:46aa5ada61bf

core, frontends: XMLUI refactoring: - now there is a base XMLUI class. Frontends inherits from this class, and add their specific widgets/containers/behaviour - wix: param.py has been removed, as the same behaviour has been reimplemented through XMLUI - removed "misc" argument in XMLUI.__init__ - severals things are broken (gateway, directory search), following patches will fix them - core: elements names in xml_tools.dataForm2XMLUI now use a construction with category_name/param_name to avoid name conflicts (could happen with 2 parameters of the same name in differents categories).
author Goffi <goffi@goffi.org>
date Tue, 04 Feb 2014 18:02:35 +0100
parents bfabeedbf32e
children 8f5479f8709a
comparison
equal deleted inserted replaced
795:6625558371db 796:46aa5ada61bf
24 from twisted.words.xish import domish 24 from twisted.words.xish import domish
25 from sat.core import exceptions 25 from sat.core import exceptions
26 26
27 """This library help manage XML used in SàT (parameters, registration, etc) """ 27 """This library help manage XML used in SàT (parameters, registration, etc) """
28 28
29 SAT_FORM_PREFIX ="SAT_FORM_" 29 SAT_FORM_PREFIX = "SAT_FORM_"
30 30 SAT_PARAM_SEPARATOR = "_XMLUI_PARAM_" # used to have unique elements names
31 31
32 def dataForm2XMLUI(form, submit_id, session_id=None): 32 def dataForm2XMLUI(form, submit_id, session_id=None):
33 """Take a data form (xep-0004, Wokkel's implementation) and convert it to a SàT xml""" 33 """Take a data form (xep-0004, Wokkel's implementation) and convert it to a SàT xml"""
34 34
35 form_ui = XMLUI("form", "vertical", submit_id=submit_id, session_id=session_id) 35 form_ui = XMLUI("form", "vertical", submit_id=submit_id, session_id=session_id)
150 if top.nodeName != 'params': 150 if top.nodeName != 'params':
151 error(_('INTERNAL ERROR: parameters xml not valid')) 151 error(_('INTERNAL ERROR: parameters xml not valid'))
152 assert(False) 152 assert(False)
153 param_ui = XMLUI("param", "tabs") 153 param_ui = XMLUI("param", "tabs")
154 for category in top.getElementsByTagName("category"): 154 for category in top.getElementsByTagName("category"):
155 name = category.getAttribute('name') 155 category_name = category.getAttribute('name')
156 label = category.getAttribute('label') 156 label = category.getAttribute('label')
157 if not name: 157 if not category_name:
158 error(_('INTERNAL ERROR: params categories must have a name')) 158 error(_('INTERNAL ERROR: params categories must have a name'))
159 assert(False) 159 assert(False)
160 param_ui.addCategory(name, 'pairs', label=label) 160 param_ui.addCategory(category_name, 'pairs', label=label)
161 for param in category.getElementsByTagName("param"): 161 for param in category.getElementsByTagName("param"):
162 name = param.getAttribute('name') 162 param_name = param.getAttribute('name')
163 label = param.getAttribute('label') 163 label = param.getAttribute('label')
164 if not name: 164 if not param_name:
165 error(_('INTERNAL ERROR: params must have a name')) 165 error(_('INTERNAL ERROR: params must have a name'))
166 assert(False) 166 assert(False)
167 type_ = param.getAttribute('type') 167 type_ = param.getAttribute('type')
168 value = param.getAttribute('value') or None 168 value = param.getAttribute('value') or None
169 options = getOptions(param) 169 options = getOptions(param)
170 callback_id = param.getAttribute('callback_id') or None 170 callback_id = param.getAttribute('callback_id') or None
171 if type_ == "button": 171 if type_ == "button":
172 param_ui.addEmpty() 172 param_ui.addEmpty()
173 else: 173 else:
174 param_ui.addLabel(label or name) 174 param_ui.addLabel(label or param_name)
175 param_ui.addElement(name=name, type_=type_, value=value, options=options, callback_id=callback_id) 175 param_ui.addElement(name="%s%s%s" % (category_name, SAT_PARAM_SEPARATOR, param_name), type_=type_, value=value, options=options, callback_id=callback_id)
176 176
177 return param_ui.toXml() 177 return param_ui.toXml()
178 178
179 179
180 def getOptions(param): 180 def getOptions(param):