comparison src/tools/xml_tools.py @ 798:8f5479f8709a

core: XMLUI now use @property for session_id and submit
author Goffi <goffi@goffi.org>
date Tue, 04 Feb 2014 18:02:40 +0100
parents 46aa5ada61bf
children e0770d977d58
comparison
equal deleted inserted replaced
797:84214df2d837 798:8f5479f8709a
17 # You should have received a copy of the GNU Affero General Public License 17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. 18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 19
20 from sat.core.i18n import _ 20 from sat.core.i18n import _
21 from logging import debug, info, error, warning 21 from logging import debug, info, error, warning
22 from xml.dom import minidom 22 from xml.dom import minidom, NotFoundErr
23 from wokkel import data_form 23 from wokkel import data_form
24 from twisted.words.xish import domish 24 from twisted.words.xish import domish
25 from sat.core import exceptions 25 from sat.core import exceptions
26 26
27 """This library help manage XML used in SàT (parameters, registration, etc) """ 27 """This library help manage XML used in SàT (parameters, registration, etc) """
262 self.doc = impl.createDocument(None, "sat_xmlui", None) 262 self.doc = impl.createDocument(None, "sat_xmlui", None)
263 top_element = self.doc.documentElement 263 top_element = self.doc.documentElement
264 top_element.setAttribute("type", panel_type) 264 top_element.setAttribute("type", panel_type)
265 if title: 265 if title:
266 top_element.setAttribute("title", title) 266 top_element.setAttribute("title", title)
267 if submit_id: 267 self.submit_id = submit_id
268 top_element.setAttribute("submit", submit_id) 268 self.session_id = session_id
269 if session_id is not None:
270 top_element.setAttribute("session_id", session_id)
271 self.parentTabsLayout = None # used only we have 'tabs' layout 269 self.parentTabsLayout = None # used only we have 'tabs' layout
272 self.currentCategory = None # used only we have 'tabs' layout 270 self.currentCategory = None # used only we have 'tabs' layout
273 self.currentLayout = None 271 self.currentLayout = None
274 self.changeLayout(layout) 272 self.changeLayout(layout)
275 273
276 def __del__(self): 274 def __del__(self):
277 self.doc.unlink() 275 self.doc.unlink()
278 276
279 def setSessionId(self, session_id): 277 @property
280 assert(session_id) 278 def submit_id(self):
281 top_element = self.doc.documentElement 279 top_element = self.doc.documentElement
282 top_element.setAttribute("session_id", session_id) 280 value = top_element.getAttribute("submit")
283 281 return value or None
282
283 @submit_id.setter
284 def submit_id(self, value):
285 top_element = self.doc.documentElement
286 if value is None:
287 try:
288 top_element.removeAttribute("submit")
289 except NotFoundErr:
290 pass
291 elif value: # submit_id can be the empty string to bypass form restriction
292 top_element.setAttribute("submit", value)
293
294 @property
295 def session_id(self):
296 top_element = self.doc.documentElement
297 value = top_element.getAttribute("session_id")
298 return value or None
299
300 @session_id.setter
301 def session_id(self, value):
302 top_element = self.doc.documentElement
303 if value is None:
304 try:
305 top_element.removeAttribute("session_id")
306 except NotFoundErr:
307 pass
308 elif value:
309 top_element.setAttribute("session_id", value)
310 else:
311 raise exceptions.DataError("session_id can't be empty")
284 312
285 def _createLayout(self, layout, parent=None): 313 def _createLayout(self, layout, parent=None):
286 """Create a layout element 314 """Create a layout element
287 @param type: layout type (cf init doc) 315 @param type: layout type (cf init doc)
288 @parent: parent element or None 316 @parent: parent element or None