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
This commit is contained in:
parent
80a7423f02
commit
4d15d4a4eb
4 changed files with 15 additions and 15 deletions
|
|
@ -22,7 +22,7 @@ from twisted.words.xish import domish
|
|||
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 @@ class Tarot(object):
|
|||
|
||||
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 @@ class Tarot(object):
|
|||
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':
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ from twisted.words.protocols.jabber.xmlstream import IQ
|
|||
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 @@ class XEP_0055(object):
|
|||
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 @@ class XEP_0055(object):
|
|||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -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 @@ class XEP_0077(object):
|
|||
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):
|
||||
|
|
|
|||
|
|
@ -26,10 +26,10 @@ from sat.core import exceptions
|
|||
"""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 @@ def dataForm2XML(form):
|
|||
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 @@ def dataFormResult2AdvancedList(form_ui, form_xml):
|
|||
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"""
|
||||
|
|
|
|||
Loading…
Reference in a new issue