tools (xml_tools): split dataFormResult2AdvancedList in dataFormResult2XMLUIData and XMLUIData2AdvancedList
This commit is contained in:
parent
bdd5648509
commit
9dad292328
1 changed files with 37 additions and 9 deletions
|
|
@ -135,13 +135,14 @@ def dataForm2XMLUI(form, submit_id, session_id=None, read_only=False):
|
|||
return dataForm2Widgets(form_ui, form, read_only=read_only)
|
||||
|
||||
|
||||
def dataFormResult2AdvancedList(xmlui, form_xml):
|
||||
"""Take a raw data form result (not parsed by Wokkel's XEP-0004 implementation) and convert it to an advanced list.
|
||||
def dataFormResult2XMLUIData(form_xml):
|
||||
"""Parse a data form result (not parsed by Wokkel's XEP-0004 implementation).
|
||||
|
||||
The raw data form is used because Wokkel doesn't manage result items parsing yet.
|
||||
@param xmlui (XMLUI): the XMLUI where the AdvancedList will be added
|
||||
@param form_xml (domish.Element): element of the data form
|
||||
@return: the completed XMLUI instance
|
||||
@return: a couple (headers, result_list):
|
||||
- headers (dict{unicode: unicode}): form headers (field labels and types)
|
||||
- xmlui_data (list[tuple]): list of (widget_type, widget_args, widget_kwargs)
|
||||
"""
|
||||
headers = OrderedDict()
|
||||
try:
|
||||
|
|
@ -160,9 +161,7 @@ def dataFormResult2AdvancedList(xmlui, form_xml):
|
|||
if not headers:
|
||||
raise exceptions.DataError("No reported fields (see XEP-0004 §3.4)")
|
||||
|
||||
adv_list = AdvancedListContainer(xmlui, headers=headers, columns=len(headers), parent=xmlui.current_container)
|
||||
xmlui.changeContainer(adv_list)
|
||||
|
||||
xmlui_data = []
|
||||
item_elts = form_xml.elements('jabber:x:data', 'item')
|
||||
|
||||
for item_elt in item_elts:
|
||||
|
|
@ -172,12 +171,41 @@ def dataFormResult2AdvancedList(xmlui, form_xml):
|
|||
continue
|
||||
field = data_form.Field.fromElement(elt)
|
||||
|
||||
widget_type, widget_args, widget_kwargs = _dataFormField2XMLUIData(field)
|
||||
xmlui.addWidget(widget_type, *widget_args, **widget_kwargs)
|
||||
xmlui_data.append(_dataFormField2XMLUIData(field))
|
||||
|
||||
return headers, xmlui_data
|
||||
|
||||
|
||||
def XMLUIData2AdvancedList(xmlui, headers, xmlui_data):
|
||||
"""Take a raw data form result (not parsed by Wokkel's XEP-0004 implementation) and convert it to an advanced list.
|
||||
|
||||
The raw data form is used because Wokkel doesn't manage result items parsing yet.
|
||||
@param xmlui (XMLUI): the XMLUI where the AdvancedList will be added
|
||||
@param headers (dict{unicode: unicode}): form headers (field labels and types)
|
||||
@param xmlui_data (list[tuple]): list of (widget_type, widget_args, widget_kwargs)
|
||||
@return: the completed XMLUI instance
|
||||
"""
|
||||
adv_list = AdvancedListContainer(xmlui, headers=headers, columns=len(headers), parent=xmlui.current_container)
|
||||
xmlui.changeContainer(adv_list)
|
||||
|
||||
for widget_type, widget_args, widget_kwargs in xmlui_data:
|
||||
xmlui.addWidget(widget_type, *widget_args, **widget_kwargs)
|
||||
|
||||
return xmlui
|
||||
|
||||
|
||||
def dataFormResult2AdvancedList(xmlui, form_xml):
|
||||
"""Take a raw data form result (not parsed by Wokkel's XEP-0004 implementation) and convert it to an advanced list.
|
||||
|
||||
The raw data form is used because Wokkel doesn't manage result items parsing yet.
|
||||
@param xmlui (XMLUI): the XMLUI where the AdvancedList will be added
|
||||
@param form_xml (domish.Element): element of the data form
|
||||
@return: the completed XMLUI instance
|
||||
"""
|
||||
headers, xmlui_data = dataFormResult2XMLUIData(form_xml)
|
||||
XMLUIData2AdvancedList(xmlui, headers, xmlui_data)
|
||||
|
||||
|
||||
def dataFormResult2XMLUI(form_elt, session_id=None):
|
||||
"""Take a raw data form (not parsed by XEP-0004) and convert it to a SàT XMLUI.
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue