diff src/tools/xml_tools.py @ 1487:0df627d0b4ca

tools (xmlui): changeContainer do not create a new one when the current one already fits
author souliane <souliane@mailoo.org>
date Fri, 21 Aug 2015 14:58:42 +0200
parents a77217511afd
children 55cff13b1f10
line wrap: on
line diff
--- a/src/tools/xml_tools.py	Fri Aug 21 14:17:41 2015 +0200
+++ b/src/tools/xml_tools.py	Fri Aug 21 14:58:42 2015 +0200
@@ -121,7 +121,7 @@
 
 
 def dataForm2XMLUI(form, submit_id, session_id=None, read_only=False):
-    """Take a data form (XEP-0004, Wokkel's implementation) and convert it to a SàT XMLUI.
+    """Take a data form (Wokkel's XEP-0004 implementation) and convert it to a SàT XMLUI.
 
     @param form (data_form.Form): a Form instance
     @param submit_id (unicode): callback id to call when submitting form
@@ -134,18 +134,18 @@
 
 
 def dataFormResult2AdvancedList(xmlui, form_xml):
-    """Take a raw data form (not parsed by XEP-0004) and convert it to an advanced list.
+    """Take a raw data form result (not parsed by Wokkel's XEP-0004 implementation) and convert it to an advanced list.
 
     The raw data form is used because Wokkel doesn't manage result items parsing yet.
     @param xmlui (XMLUI): the XMLUI where the AdvancedList will be added
     @param form_xml (domish.Element): element of the data form
-    @return: AdvancedList element
+    @return: the completed XMLUI instance
     """
     headers = {}
     try:
         reported_elt = form_xml.elements('jabber:x:data', 'reported').next()
     except StopIteration:
-        raise exceptions.DataError("Couldn't find expected <reported> tag")
+        raise exceptions.DataError("Couldn't find expected <reported> tag in %s" % form_xml.toXml())
 
     for elt in reported_elt.elements():
         if elt.name != "field":
@@ -364,8 +364,14 @@
         self.parent = parent
 
     def append(self, child):
+        """Append a child to this element.
+        
+        @param child (Element): child element
+        @return: the added child Element
+        """
         self.elem.appendChild(child.elem)
         child.parent = self
+        return child
 
 
 class TopElement(Element):
@@ -847,7 +853,7 @@
 
         @param callback_id: callback which will be called if button is pressed
         @param value: label of the button
-        @fields_back: list of names of field to give back when pushing the button
+        @param fields_back: list of names of field to give back when pushing the button
         @param name: name
         @param parent: parent container
         """
@@ -1166,7 +1172,8 @@
         @param container: either container type (container it then created),
                           or an Container instance"""
         if isinstance(container, basestring):
-            self.current_container = self._createContainer(container, self.current_container.getParentContainer() or self.main_container, **kwargs)
+            if not isinstance(self.current_container, self._containers[container]):
+                self.current_container = self._createContainer(container, self.current_container.getParentContainer() or self.main_container, **kwargs)
         else:
             self.current_container = self.main_container if container is None else container
         assert isinstance(self.current_container, Container)