comparison src/tools/xml_tools.py @ 1069:8e1f30aa3975

core (XMLUI): data form result now manage generic data set
author Goffi <goffi@goffi.org>
date Sat, 14 Jun 2014 17:24:16 +0200
parents f7f15d44fdfa
children ad023e60da8c
comparison
equal deleted inserted replaced
1068:1513511a0586 1069:8e1f30aa3975
73 if field.var: 73 if field.var:
74 widget_kwargs["name"] = field.var 74 widget_kwargs["name"] = field.var
75 75
76 return widget_type, widget_args, widget_kwargs 76 return widget_type, widget_args, widget_kwargs
77 77
78 78 def dataForm2Widgets(form_ui, form):
79 def dataForm2XMLUI(form, submit_id, session_id=None): 79 """Complete an existing XMLUI with widget converted frot XEP-0004 data forms
80 """Take a data form (xep-0004, Wokkel's implementation) and convert it to a SàT XML 80
81 @param submit_id: callback id to call when submitting form 81 @param form_ui: XMLUI instance
82 @param session_id: id to return with the data 82 @param form: Wokkel's implementation of data form
83 83 @return: completed xml_ui
84 """ 84 """
85 form_ui = XMLUI("form", "vertical", submit_id=submit_id, session_id=session_id)
86
87 if form.instructions: 85 if form.instructions:
88 form_ui.addText('\n'.join(form.instructions), 'instructions') 86 form_ui.addText('\n'.join(form.instructions), 'instructions')
89 87
90 form_ui.changeContainer("pairs") 88 form_ui.changeContainer("pairs")
91 89
98 form_ui.addEmpty() 96 form_ui.addEmpty()
99 97
100 form_ui.addWidget(widget_type, *widget_args, **widget_kwargs) 98 form_ui.addWidget(widget_type, *widget_args, **widget_kwargs)
101 99
102 return form_ui 100 return form_ui
101
102 def dataForm2XMLUI(form, submit_id, session_id=None):
103 """Take a data form (xep-0004, Wokkel's implementation) and convert it to a SàT XML
104
105 @param submit_id: callback id to call when submitting form
106 @param session_id: id to return with the data
107 """
108 form_ui = XMLUI("form", "vertical", submit_id=submit_id, session_id=session_id)
109 return dataForm2Widgets(form_ui, form)
103 110
104 def dataFormResult2AdvancedList(xmlui, form_xml): 111 def dataFormResult2AdvancedList(xmlui, form_xml):
105 """Take a raw data form (not parsed by XEP-0004) and convert it to an advanced list 112 """Take a raw data form (not parsed by XEP-0004) and convert it to an advanced list
106 raw data form is used because Wokkel doesn't manage result items parsing yet 113 raw data form is used because Wokkel doesn't manage result items parsing yet
107 @param xmlui: the XMLUI where the AdvancedList will be added 114 @param xmlui: the XMLUI where the AdvancedList will be added
140 widget_type, widget_args, widget_kwargs = _dataFormField2XMLUIData(field) 147 widget_type, widget_args, widget_kwargs = _dataFormField2XMLUIData(field)
141 xmlui.addWidget(widget_type, *widget_args, **widget_kwargs) 148 xmlui.addWidget(widget_type, *widget_args, **widget_kwargs)
142 149
143 return xmlui 150 return xmlui
144 151
145 def dataFormResult2XMLUI(form_xml, session_id=None): 152 def dataFormResult2XMLUI(form_elt, session_id=None):
146 """Take a raw data form (not parsed by XEP-0004) and convert it to a SàT XMLUI 153 """Take a raw data form (not parsed by XEP-0004) and convert it to a SàT XMLUI
147 raw data form is used because Wokkel doesn't manage result items parsing yet 154 raw data form is used because Wokkel doesn't manage result items parsing yet
148 @param form_xml: domish.Element of the data form 155 @param form_elt: domish.Element of the data form
149 @return: XMLUI interface 156 @return: XMLUI interface
150 """ 157 """
151 158
152 xmlui = XMLUI("window", "vertical", session_id=session_id) 159 xml_ui = XMLUI("window", "vertical", session_id=session_id)
153 dataFormResult2AdvancedList(xmlui, form_xml) 160 try:
154 return xmlui 161 dataFormResult2AdvancedList(xml_ui, form_elt)
162 except exceptions.DataError:
163 parsed_form = data_form.Form.fromElement(form_elt)
164 dataForm2Widgets(xml_ui, parsed_form)
165 return xml_ui
155 166
156 def _cleanValue(value): 167 def _cleanValue(value):
157 """Workaround method to avoid DBus types with D-Bus bridge 168 """Workaround method to avoid DBus types with D-Bus bridge
158 169
159 @param value: value to clean 170 @param value: value to clean