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)
This commit is contained in:
parent
4d15d4a4eb
commit
3857fff974
3 changed files with 30 additions and 6 deletions
|
|
@ -22,6 +22,9 @@ from urwid_satext import sat_widgets
|
||||||
from logging import debug, info, warning, error
|
from logging import debug, info, warning, error
|
||||||
from xml.dom import minidom
|
from xml.dom import minidom
|
||||||
|
|
||||||
|
|
||||||
|
SAT_FORM_PREFIX = "SAT_FORM_"
|
||||||
|
|
||||||
def getText(node):
|
def getText(node):
|
||||||
"""Get child text nodes
|
"""Get child text nodes
|
||||||
@param node: dom Node
|
@param node: dom Node
|
||||||
|
|
@ -254,13 +257,14 @@ class XMLUI(urwid.WidgetWrap):
|
||||||
def onFormSubmitted(self, button):
|
def onFormSubmitted(self, button):
|
||||||
selected_values = []
|
selected_values = []
|
||||||
for ctrl_name in self.ctrl_list:
|
for ctrl_name in self.ctrl_list:
|
||||||
|
escaped = u"%s%s" % (SAT_FORM_PREFIX, ctrl_name)
|
||||||
ctrl = self.ctrl_list[ctrl_name]
|
ctrl = self.ctrl_list[ctrl_name]
|
||||||
if isinstance(ctrl['control'], sat_widgets.List):
|
if isinstance(ctrl['control'], sat_widgets.List):
|
||||||
selected_values.append((ctrl_name, u'\t'.join([option.value for option in ctrl['control'].getSelectedValues()])))
|
selected_values.append((escaped, u'\t'.join([option.value for option in ctrl['control'].getSelectedValues()])))
|
||||||
elif isinstance(ctrl['control'], urwid.CheckBox):
|
elif isinstance(ctrl['control'], urwid.CheckBox):
|
||||||
selected_values.append((ctrl_name, "true" if ctrl['control'].get_state() else "false"))
|
selected_values.append((escaped, "true" if ctrl['control'].get_state() else "false"))
|
||||||
else:
|
else:
|
||||||
selected_values.append((ctrl_name, ctrl['control'].get_edit_text()))
|
selected_values.append((escaped, ctrl['control'].get_edit_text()))
|
||||||
if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned
|
if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
elif 'callback' in self.misc: # FIXME: this part is not needed anymore
|
elif 'callback' in self.misc: # FIXME: this part is not needed anymore
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@ from xml.dom import minidom
|
||||||
from logging import debug, info, warning, error
|
from logging import debug, info, warning, error
|
||||||
from sat.tools.jid import JID
|
from sat.tools.jid import JID
|
||||||
|
|
||||||
|
SAT_FORM_PREFIX = "SAT_FORM_"
|
||||||
|
|
||||||
|
|
||||||
class XMLUI(wx.Frame):
|
class XMLUI(wx.Frame):
|
||||||
"""Create an user interface from a SàT xml"""
|
"""Create an user interface from a SàT xml"""
|
||||||
|
|
@ -216,15 +218,16 @@ class XMLUI(wx.Frame):
|
||||||
debug(_("Submitting form"))
|
debug(_("Submitting form"))
|
||||||
selected_values = []
|
selected_values = []
|
||||||
for ctrl_name in self.ctrl_list:
|
for ctrl_name in self.ctrl_list:
|
||||||
|
escaped = u"%s%s" % (SAT_FORM_PREFIX, ctrl_name)
|
||||||
ctrl = self.ctrl_list[ctrl_name]
|
ctrl = self.ctrl_list[ctrl_name]
|
||||||
if isinstance(ctrl['control'], wx.ListBox):
|
if isinstance(ctrl['control'], wx.ListBox):
|
||||||
label = ctrl['control'].GetStringSelection()
|
label = ctrl['control'].GetStringSelection()
|
||||||
value = ctrl['attr_map'][label]
|
value = ctrl['attr_map'][label]
|
||||||
selected_values.append((ctrl_name, value))
|
selected_values.append((escaped, value))
|
||||||
elif isinstance(ctrl['control'], wx.CheckBox):
|
elif isinstance(ctrl['control'], wx.CheckBox):
|
||||||
selected_values.append((ctrl_name, "true" if ctrl['control'].GetValue() else "false"))
|
selected_values.append((escaped, "true" if ctrl['control'].GetValue() else "false"))
|
||||||
else:
|
else:
|
||||||
selected_values.append((ctrl_name, ctrl['control'].GetValue()))
|
selected_values.append((escaped, ctrl['control'].GetValue()))
|
||||||
if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned
|
if self.misc.has_key('action_back'): #FIXME FIXME FIXME: WTF ! Must be cleaned
|
||||||
id = self.misc['action_back']("SUBMIT",self.misc['target'], selected_values)
|
id = self.misc['action_back']("SUBMIT",self.misc['target'], selected_values)
|
||||||
self.host.current_action_ids.add(id)
|
self.host.current_action_ids.add(id)
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,8 @@ from sat.core import exceptions
|
||||||
|
|
||||||
"""This library help manage XML used in SàT (parameters, registration, etc) """
|
"""This library help manage XML used in SàT (parameters, registration, etc) """
|
||||||
|
|
||||||
|
SAT_FORM_PREFIX ="SAT_FORM_"
|
||||||
|
|
||||||
|
|
||||||
def dataForm2XMLUI(form, submit_id, session_id=None):
|
def dataForm2XMLUI(form, submit_id, session_id=None):
|
||||||
"""Take a data form (xep-0004, Wokkel's implementation) and convert it to a SàT xml"""
|
"""Take a data form (xep-0004, Wokkel's implementation) and convert it to a SàT xml"""
|
||||||
|
|
@ -116,6 +118,21 @@ def dataFormResult2XMLUI(form_xml, session_id=None):
|
||||||
dataFormResult2AdvancedList(form_ui, form_xml)
|
dataFormResult2AdvancedList(form_ui, form_xml)
|
||||||
return form_ui
|
return form_ui
|
||||||
|
|
||||||
|
def XMLUIResult2DataFormResult(xmlui_data):
|
||||||
|
""" Extract form data from a XMLUI return
|
||||||
|
@xmlui_data: data returned by frontends for XMLUI form
|
||||||
|
@return: dict of data usable by Wokkel's dataform
|
||||||
|
"""
|
||||||
|
return {key[len(SAT_FORM_PREFIX):]: value for key, value in xmlui_data.iteritems() if key.startswith(SAT_FORM_PREFIX)}
|
||||||
|
|
||||||
|
def XMLUIResultToElt(xmlui_data):
|
||||||
|
""" Construct result domish.Element from XMLUI result
|
||||||
|
@xmlui_data: data returned by frontends for XMLUI form
|
||||||
|
"""
|
||||||
|
form = data_form.Form('result')
|
||||||
|
form.makeFields(XMLUIResult2DataFormResult(xmlui_data))
|
||||||
|
return form.toElement()
|
||||||
|
|
||||||
def tupleList2dataForm(values):
|
def tupleList2dataForm(values):
|
||||||
"""convert a list of tuples (name,value) to a wokkel submit data form"""
|
"""convert a list of tuples (name,value) to a wokkel submit data form"""
|
||||||
form = data_form.Form('submit')
|
form = data_form.Form('submit')
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue