diff src/tools/xml_tools.py @ 796:46aa5ada61bf

core, frontends: XMLUI refactoring: - now there is a base XMLUI class. Frontends inherits from this class, and add their specific widgets/containers/behaviour - wix: param.py has been removed, as the same behaviour has been reimplemented through XMLUI - removed "misc" argument in XMLUI.__init__ - severals things are broken (gateway, directory search), following patches will fix them - core: elements names in xml_tools.dataForm2XMLUI now use a construction with category_name/param_name to avoid name conflicts (could happen with 2 parameters of the same name in differents categories).
author Goffi <goffi@goffi.org>
date Tue, 04 Feb 2014 18:02:35 +0100
parents bfabeedbf32e
children 8f5479f8709a
line wrap: on
line diff
--- a/src/tools/xml_tools.py	Fri Jan 10 18:20:30 2014 +0100
+++ b/src/tools/xml_tools.py	Tue Feb 04 18:02:35 2014 +0100
@@ -26,8 +26,8 @@
 
 """This library help manage XML used in SàT (parameters, registration, etc) """
 
-SAT_FORM_PREFIX ="SAT_FORM_"
-
+SAT_FORM_PREFIX = "SAT_FORM_"
+SAT_PARAM_SEPARATOR = "_XMLUI_PARAM_" # used to have unique elements names
 
 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"""
@@ -152,16 +152,16 @@
         assert(False)
     param_ui = XMLUI("param", "tabs")
     for category in top.getElementsByTagName("category"):
-        name = category.getAttribute('name')
+        category_name = category.getAttribute('name')
         label = category.getAttribute('label')
-        if not name:
+        if not category_name:
             error(_('INTERNAL ERROR: params categories must have a name'))
             assert(False)
-        param_ui.addCategory(name, 'pairs', label=label)
+        param_ui.addCategory(category_name, 'pairs', label=label)
         for param in category.getElementsByTagName("param"):
-            name = param.getAttribute('name')
+            param_name = param.getAttribute('name')
             label = param.getAttribute('label')
-            if not name:
+            if not param_name:
                 error(_('INTERNAL ERROR: params must have a name'))
                 assert(False)
             type_ = param.getAttribute('type')
@@ -171,8 +171,8 @@
             if type_ == "button":
                 param_ui.addEmpty()
             else:
-                param_ui.addLabel(label or name)
-            param_ui.addElement(name=name, type_=type_, value=value, options=options, callback_id=callback_id)
+                param_ui.addLabel(label or param_name)
+            param_ui.addElement(name="%s%s%s" % (category_name, SAT_PARAM_SEPARATOR, param_name), type_=type_, value=value, options=options, callback_id=callback_id)
 
     return param_ui.toXml()