diff src/tools/xml_tools.py @ 1069:8e1f30aa3975

core (XMLUI): data form result now manage generic data set
author Goffi <goffi@goffi.org>
date Sat, 14 Jun 2014 17:24:16 +0200
parents f7f15d44fdfa
children ad023e60da8c
line wrap: on
line diff
--- a/src/tools/xml_tools.py	Thu Jun 12 18:56:08 2014 +0200
+++ b/src/tools/xml_tools.py	Sat Jun 14 17:24:16 2014 +0200
@@ -75,15 +75,13 @@
 
     return widget_type, widget_args, widget_kwargs
 
+def dataForm2Widgets(form_ui, form):
+    """Complete an existing XMLUI with widget converted frot XEP-0004 data forms
 
-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
-    @param submit_id: callback id to call when submitting form
-    @param session_id: id to return with the data
-
+    @param form_ui: XMLUI instance
+    @param form: Wokkel's implementation of data form
+    @return: completed xml_ui
     """
-    form_ui = XMLUI("form", "vertical", submit_id=submit_id, session_id=session_id)
-
     if form.instructions:
         form_ui.addText('\n'.join(form.instructions), 'instructions')
 
@@ -101,6 +99,15 @@
 
     return form_ui
 
+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
+
+    @param submit_id: callback id to call when submitting form
+    @param session_id: id to return with the data
+    """
+    form_ui = XMLUI("form", "vertical", submit_id=submit_id, session_id=session_id)
+    return dataForm2Widgets(form_ui, form)
+
 def dataFormResult2AdvancedList(xmlui, form_xml):
     """Take a raw data form (not parsed by XEP-0004) and convert it to an advanced list
     raw data form is used because Wokkel doesn't manage result items parsing yet
@@ -142,16 +149,20 @@
 
     return xmlui
 
-def dataFormResult2XMLUI(form_xml, session_id=None):
+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
     raw data form is used because Wokkel doesn't manage result items parsing yet
-    @param form_xml: domish.Element of the data form
+    @param form_elt: domish.Element of the data form
     @return: XMLUI interface
     """
 
-    xmlui = XMLUI("window", "vertical", session_id=session_id)
-    dataFormResult2AdvancedList(xmlui, form_xml)
-    return xmlui
+    xml_ui = XMLUI("window", "vertical", session_id=session_id)
+    try:
+        dataFormResult2AdvancedList(xml_ui, form_elt)
+    except exceptions.DataError:
+        parsed_form = data_form.Form.fromElement(form_elt)
+        dataForm2Widgets(xml_ui, parsed_form)
+    return xml_ui
 
 def _cleanValue(value):
     """Workaround method to avoid DBus types with D-Bus bridge