Mercurial > libervia-backend
comparison src/tools/xml_tools.py @ 761:2f8d72226bc0
core (xml_tools): dataForm*2XML renamed to dataForm*2XMLUI and now return XMLUI instead of raw XML + submit_id is managed, and session_id is returned if present
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 24 Dec 2013 15:43:22 +0100 |
parents | 73a0077f80cc |
children | aed7d99276b8 |
comparison
equal
deleted
inserted
replaced
760:73a0077f80cc | 761:2f8d72226bc0 |
---|---|
24 from sat.core import exceptions | 24 from sat.core import exceptions |
25 | 25 |
26 """This library help manage XML used in SàT (parameters, registration, etc) """ | 26 """This library help manage XML used in SàT (parameters, registration, etc) """ |
27 | 27 |
28 | 28 |
29 def dataForm2XML(form): | 29 def dataForm2XMLUI(form, submit_id, session_id=None): |
30 """Take a data form (xep-0004, Wokkel's implementation) and convert it to a SàT xml""" | 30 """Take a data form (xep-0004, Wokkel's implementation) and convert it to a SàT xml""" |
31 | 31 |
32 form_ui = XMLUI("form", "vertical") | 32 form_ui = XMLUI("form", "vertical", submit_id=submit_id, session_id=session_id) |
33 | 33 |
34 if form.instructions: | 34 if form.instructions: |
35 form_ui.addText('\n'.join(form.instructions), 'instructions') | 35 form_ui.addText('\n'.join(form.instructions), 'instructions') |
36 | 36 |
37 labels = [field for field in form.fieldList if field.label] | 37 labels = [field for field in form.fieldList if field.label] |
57 form_ui.addLabel(field.label) | 57 form_ui.addLabel(field.label) |
58 else: | 58 else: |
59 form_ui.addEmpty() | 59 form_ui.addEmpty() |
60 | 60 |
61 form_ui.addElement(__field_type, field.var, field.value, [option.value for option in field.options]) | 61 form_ui.addElement(__field_type, field.var, field.value, [option.value for option in field.options]) |
62 return form_ui.toXml() | 62 return form_ui |
63 | 63 |
64 def dataFormResult2AdvancedList(form_ui, form_xml): | 64 def dataFormResult2AdvancedList(form_ui, form_xml): |
65 """Take a raw data form (not parsed by XEP-0004) and convert it to an advanced list | 65 """Take a raw data form (not parsed by XEP-0004) and convert it to an advanced list |
66 raw data form is used because Wokkel doesn't manage result items parsing yet | 66 raw data form is used because Wokkel doesn't manage result items parsing yet |
67 @param form_ui: the XMLUI where the AdvancedList will be added² | 67 @param form_ui: the XMLUI where the AdvancedList will be added |
68 @param form_xml: domish.Element of the data form | 68 @param form_xml: domish.Element of the data form |
69 @return: AdvancedList element | 69 @return: AdvancedList element |
70 """ | 70 """ |
71 headers = [] | 71 headers = [] |
72 items = [] | 72 items = [] |
103 items.append(Item(' | '.join((field.value for field in fields if field)), fields)) | 103 items.append(Item(' | '.join((field.value for field in fields if field)), fields)) |
104 | 104 |
105 return form_ui.addAdvancedList(None, headers, items) | 105 return form_ui.addAdvancedList(None, headers, items) |
106 | 106 |
107 | 107 |
108 def dataFormResult2XML(form_xml): | 108 def dataFormResult2XMLUI(form_xml, session_id=None): |
109 """Take a raw data form (not parsed by XEP-0004) and convert it to a SàT XMLUI | 109 """Take a raw data form (not parsed by XEP-0004) and convert it to a SàT XMLUI |
110 raw data form is used because Wokkel doesn't manage result items parsing yet | 110 raw data form is used because Wokkel doesn't manage result items parsing yet |
111 @param form_xml: domish.Element of the data form | 111 @param form_xml: domish.Element of the data form |
112 @return: XMLUI interface | 112 @return: XMLUI interface |
113 """ | 113 """ |
114 | 114 |
115 form_ui = XMLUI("window", "vertical") | 115 form_ui = XMLUI("window", "vertical", session_id=session_id) |
116 dataFormResult2AdvancedList(form_ui, form_xml) | 116 dataFormResult2AdvancedList(form_ui, form_xml) |
117 return form_ui.toXml() | 117 return form_ui |
118 | 118 |
119 def tupleList2dataForm(values): | 119 def tupleList2dataForm(values): |
120 """convert a list of tuples (name,value) to a wokkel submit data form""" | 120 """convert a list of tuples (name,value) to a wokkel submit data form""" |
121 form = data_form.Form('submit') | 121 form = data_form.Form('submit') |
122 for value in values: | 122 for value in values: |