comparison 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
comparison
equal deleted inserted replaced
1486:a77217511afd 1487:0df627d0b4ca
119 119
120 return form_ui 120 return form_ui
121 121
122 122
123 def dataForm2XMLUI(form, submit_id, session_id=None, read_only=False): 123 def dataForm2XMLUI(form, submit_id, session_id=None, read_only=False):
124 """Take a data form (XEP-0004, Wokkel's implementation) and convert it to a SàT XMLUI. 124 """Take a data form (Wokkel's XEP-0004 implementation) and convert it to a SàT XMLUI.
125 125
126 @param form (data_form.Form): a Form instance 126 @param form (data_form.Form): a Form instance
127 @param submit_id (unicode): callback id to call when submitting form 127 @param submit_id (unicode): callback id to call when submitting form
128 @param session_id (unicode): session id to return with the data 128 @param session_id (unicode): session id to return with the data
129 @param read_only (bool): if True and it makes sense, create a read only input widget 129 @param read_only (bool): if True and it makes sense, create a read only input widget
132 form_ui = XMLUI("form", "vertical", submit_id=submit_id, session_id=session_id) 132 form_ui = XMLUI("form", "vertical", submit_id=submit_id, session_id=session_id)
133 return dataForm2Widgets(form_ui, form, read_only=read_only) 133 return dataForm2Widgets(form_ui, form, read_only=read_only)
134 134
135 135
136 def dataFormResult2AdvancedList(xmlui, form_xml): 136 def dataFormResult2AdvancedList(xmlui, form_xml):
137 """Take a raw data form (not parsed by XEP-0004) and convert it to an advanced list. 137 """Take a raw data form result (not parsed by Wokkel's XEP-0004 implementation) and convert it to an advanced list.
138 138
139 The raw data form is used because Wokkel doesn't manage result items parsing yet. 139 The raw data form is used because Wokkel doesn't manage result items parsing yet.
140 @param xmlui (XMLUI): the XMLUI where the AdvancedList will be added 140 @param xmlui (XMLUI): the XMLUI where the AdvancedList will be added
141 @param form_xml (domish.Element): element of the data form 141 @param form_xml (domish.Element): element of the data form
142 @return: AdvancedList element 142 @return: the completed XMLUI instance
143 """ 143 """
144 headers = {} 144 headers = {}
145 try: 145 try:
146 reported_elt = form_xml.elements('jabber:x:data', 'reported').next() 146 reported_elt = form_xml.elements('jabber:x:data', 'reported').next()
147 except StopIteration: 147 except StopIteration:
148 raise exceptions.DataError("Couldn't find expected <reported> tag") 148 raise exceptions.DataError("Couldn't find expected <reported> tag in %s" % form_xml.toXml())
149 149
150 for elt in reported_elt.elements(): 150 for elt in reported_elt.elements():
151 if elt.name != "field": 151 if elt.name != "field":
152 raise exceptions.DataError("Unexpected tag") 152 raise exceptions.DataError("Unexpected tag")
153 name = elt["var"] 153 name = elt["var"]
362 if parent is not None: 362 if parent is not None:
363 parent.append(self) 363 parent.append(self)
364 self.parent = parent 364 self.parent = parent
365 365
366 def append(self, child): 366 def append(self, child):
367 """Append a child to this element.
368
369 @param child (Element): child element
370 @return: the added child Element
371 """
367 self.elem.appendChild(child.elem) 372 self.elem.appendChild(child.elem)
368 child.parent = self 373 child.parent = self
374 return child
369 375
370 376
371 class TopElement(Element): 377 class TopElement(Element):
372 """ Main XML Element """ 378 """ Main XML Element """
373 type = 'top' 379 type = 'top'
845 def __init__(self, xmlui, callback_id, value=None, fields_back=None, name=None, parent=None): 851 def __init__(self, xmlui, callback_id, value=None, fields_back=None, name=None, parent=None):
846 """Add a button 852 """Add a button
847 853
848 @param callback_id: callback which will be called if button is pressed 854 @param callback_id: callback which will be called if button is pressed
849 @param value: label of the button 855 @param value: label of the button
850 @fields_back: list of names of field to give back when pushing the button 856 @param fields_back: list of names of field to give back when pushing the button
851 @param name: name 857 @param name: name
852 @param parent: parent container 858 @param parent: parent container
853 """ 859 """
854 if fields_back is None: 860 if fields_back is None:
855 fields_back = [] 861 fields_back = []
1164 """Change the current container 1170 """Change the current container
1165 1171
1166 @param container: either container type (container it then created), 1172 @param container: either container type (container it then created),
1167 or an Container instance""" 1173 or an Container instance"""
1168 if isinstance(container, basestring): 1174 if isinstance(container, basestring):
1169 self.current_container = self._createContainer(container, self.current_container.getParentContainer() or self.main_container, **kwargs) 1175 if not isinstance(self.current_container, self._containers[container]):
1176 self.current_container = self._createContainer(container, self.current_container.getParentContainer() or self.main_container, **kwargs)
1170 else: 1177 else:
1171 self.current_container = self.main_container if container is None else container 1178 self.current_container = self.main_container if container is None else container
1172 assert isinstance(self.current_container, Container) 1179 assert isinstance(self.current_container, Container)
1173 return self.current_container 1180 return self.current_container
1174 1181