core: XMLUI now use @property for session_id and submit

This commit is contained in:
Goffi 2014-02-04 18:02:40 +01:00
commit 67df03f7bf
2 changed files with 37 additions and 9 deletions

View file

@ -277,7 +277,7 @@ class XEP_0050(object):
d = self.requestCommandsList(entity, profile)
def sendItems(xmlui):
xmlui.setSessionId(session_id) # we need to keep track of the session
xmlui.session_id = session_id # we need to keep track of the session
return {'xmlui': xmlui.toXml()}
d.addCallback(sendItems)

View file

@ -19,7 +19,7 @@
from sat.core.i18n import _
from logging import debug, info, error, warning
from xml.dom import minidom
from xml.dom import minidom, NotFoundErr
from wokkel import data_form
from twisted.words.xish import domish
from sat.core import exceptions
@ -264,10 +264,8 @@ class XMLUI(object):
top_element.setAttribute("type", panel_type)
if title:
top_element.setAttribute("title", title)
if submit_id:
top_element.setAttribute("submit", submit_id)
if session_id is not None:
top_element.setAttribute("session_id", session_id)
self.submit_id = submit_id
self.session_id = session_id
self.parentTabsLayout = None # used only we have 'tabs' layout
self.currentCategory = None # used only we have 'tabs' layout
self.currentLayout = None
@ -276,11 +274,41 @@ class XMLUI(object):
def __del__(self):
self.doc.unlink()
def setSessionId(self, session_id):
assert(session_id)
@property
def submit_id(self):
top_element = self.doc.documentElement
top_element.setAttribute("session_id", session_id)
value = top_element.getAttribute("submit")
return value or None
@submit_id.setter
def submit_id(self, value):
top_element = self.doc.documentElement
if value is None:
try:
top_element.removeAttribute("submit")
except NotFoundErr:
pass
elif value: # submit_id can be the empty string to bypass form restriction
top_element.setAttribute("submit", value)
@property
def session_id(self):
top_element = self.doc.documentElement
value = top_element.getAttribute("session_id")
return value or None
@session_id.setter
def session_id(self, value):
top_element = self.doc.documentElement
if value is None:
try:
top_element.removeAttribute("session_id")
except NotFoundErr:
pass
elif value:
top_element.setAttribute("session_id", value)
else:
raise exceptions.DataError("session_id can't be empty")
def _createLayout(self, layout, parent=None):
"""Create a layout element