changeset 761:2f8d72226bc0

core (xml_tools): dataForm*2XML renamed to dataForm*2XMLUI and now return XMLUI instead of raw XML + submit_id is managed, and session_id is returned if present
author Goffi <goffi@goffi.org>
date Tue, 24 Dec 2013 15:43:22 +0100
parents 73a0077f80cc
children aed7d99276b8
files src/plugins/plugin_misc_tarot.py src/plugins/plugin_xep_0055.py src/plugins/plugin_xep_0077.py src/tools/xml_tools.py
diffstat 4 files changed, 15 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/plugin_misc_tarot.py	Tue Dec 24 15:19:18 2013 +0100
+++ b/src/plugins/plugin_misc_tarot.py	Tue Dec 24 15:43:22 2013 +0100
@@ -22,7 +22,7 @@
 from twisted.words.protocols.jabber import jid
 from wokkel import data_form
 
-from sat.tools.xml_tools import dataForm2XML
+from sat.tools.xml_tools import dataForm2XMLUI
 from sat_frontends.tools.games import TarotCard
 from time import time
 import random
@@ -474,7 +474,7 @@
 
             elif elt.name == 'contrat':  # it's time to choose contrat
                 form = data_form.Form.fromElement(elt.firstChildElement())
-                xml_data = dataForm2XML(form)
+                xml_data = dataForm2XMLUI(form, "").toXml()
                 self.host.bridge.tarotGameChooseContrat(room_jid.userhost(), xml_data, profile)
 
             elif elt.name == 'contrat_choosed':
@@ -613,7 +613,7 @@
                 for looser in elt.elements(name='looser', uri=NS_CG):
                     loosers.append(unicode(looser))
                 form = data_form.Form.fromElement(form_elt)
-                xml_data = dataForm2XML(form)
+                xml_data = dataForm2XMLUI(form, "").toXml()
                 self.host.bridge.tarotGameScore(room_jid.userhost(), xml_data, winners, loosers, profile)
             elif elt.name == 'error':
                 if elt['type'] == 'invalid_cards':
--- a/src/plugins/plugin_xep_0055.py	Tue Dec 24 15:19:18 2013 +0100
+++ b/src/plugins/plugin_xep_0055.py	Tue Dec 24 15:43:22 2013 +0100
@@ -22,7 +22,7 @@
 from twisted.words.protocols.jabber import jid
 from wokkel import data_form
 from sat.core.exceptions import DataError
-from sat.tools.xml_tools import dataForm2XML, dataFormResult2XML
+from sat.tools.xml_tools import dataForm2XMLUI, dataFormResult2XMLUI
 
 NS_SEARCH = 'jabber:iq:search'
 
@@ -79,7 +79,7 @@
             info(_("No data form found"))
             raise NotImplementedError("Only search through data form is implemented so far")
         parsed_form = data_form.Form.fromElement(form_elt)
-        return dataForm2XML(parsed_form)
+        return dataForm2XMLUI(parsed_form, "").toXml()
 
     def _fieldsErr(self, failure, profile):
         """ Called when something is wrong with fields request """
@@ -119,7 +119,7 @@
         except StopIteration:
             info(_("No data form found"))
             raise NotImplementedError("Only search through data form is implemented so far")
-        xmlui = dataFormResult2XML(form_elt)
+        xmlui = dataFormResult2XMLUI(form_elt).toXml()
         print "=== XMLUI ===\n%s\n\n" %  xmlui
         return xmlui
 
--- a/src/plugins/plugin_xep_0077.py	Tue Dec 24 15:19:18 2013 +0100
+++ b/src/plugins/plugin_xep_0077.py	Tue Dec 24 15:43:22 2013 +0100
@@ -20,7 +20,7 @@
 from logging import debug, info, error
 from twisted.words.protocols.jabber import jid
 from twisted.words.protocols.jabber.xmlstream import IQ
-from sat.tools.xml_tools import dataForm2XML
+from sat.tools.xml_tools import dataForm2XMLUI
 
 from wokkel import data_form
 
@@ -63,7 +63,7 @@
             return
 
         form = data_form.Form.fromElement(x_elem)
-        xml_data = dataForm2XML(form)
+        xml_data = dataForm2XMLUI(form, "").toXml()
         self.host.bridge.actionResult("XMLUI", answer['id'], {"target": answer["from"], "type": "registration", "xml": xml_data}, profile)
 
     def reg_err(self, failure, profile):
--- a/src/tools/xml_tools.py	Tue Dec 24 15:19:18 2013 +0100
+++ b/src/tools/xml_tools.py	Tue Dec 24 15:43:22 2013 +0100
@@ -26,10 +26,10 @@
 """This library help manage XML used in SàT (parameters, registration, etc) """
 
 
-def dataForm2XML(form):
+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"""
 
-    form_ui = XMLUI("form", "vertical")
+    form_ui = XMLUI("form", "vertical", submit_id=submit_id, session_id=session_id)
 
     if form.instructions:
         form_ui.addText('\n'.join(form.instructions), 'instructions')
@@ -59,12 +59,12 @@
                 form_ui.addEmpty()
 
         form_ui.addElement(__field_type, field.var, field.value, [option.value for option in field.options])
-    return form_ui.toXml()
+    return form_ui
 
 def dataFormResult2AdvancedList(form_ui, 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
-    @param form_ui: the XMLUI where the AdvancedList will be added²
+    @param form_ui: the XMLUI where the AdvancedList will be added
     @param form_xml: domish.Element of the data form
     @return: AdvancedList element
     """
@@ -105,16 +105,16 @@
     return form_ui.addAdvancedList(None, headers, items)
 
 
-def dataFormResult2XML(form_xml):
+def dataFormResult2XMLUI(form_xml, 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
     @return: XMLUI interface
     """
 
-    form_ui = XMLUI("window", "vertical")
+    form_ui = XMLUI("window", "vertical", session_id=session_id)
     dataFormResult2AdvancedList(form_ui, form_xml)
-    return form_ui.toXml()
+    return form_ui
 
 def tupleList2dataForm(values):
     """convert a list of tuples (name,value) to a wokkel submit data form"""