comparison src/tools/xml_tools.py @ 1530:94cd4d242dc5

core (XMLUI): restorer submit_id: - submit_id was missing due to a previous change in commit a2e4b976e707 - XMLUI.submit_id can now be None (not set) or empty string in addition to normal values fix bug 102
author Goffi <goffi@goffi.org>
date Sat, 26 Sep 2015 15:00:27 +0200
parents d2ab9c62ac3a
children 51dec65ec62c
comparison
equal deleted inserted replaced
1529:a151f3a5a2d0 1530:94cd4d242dc5
1063 1063
1064 @param title: title or default if None 1064 @param title: title or default if None
1065 @param submit_id: callback id to call for panel_type we can submit (form, param, dialog) 1065 @param submit_id: callback id to call for panel_type we can submit (form, param, dialog)
1066 @param session_id: use to keep a session attached to the dialog, must be returned by frontends 1066 @param session_id: use to keep a session attached to the dialog, must be returned by frontends
1067 """ 1067 """
1068 self._introspect() 1068 self._introspect() # FIXME: why doing that on each XMLUI ? should be done once
1069 if panel_type not in [C.XMLUI_WINDOW, C.XMLUI_FORM, C.XMLUI_PARAM, C.XMLUI_POPUP, C.XMLUI_DIALOG]: 1069 if panel_type not in [C.XMLUI_WINDOW, C.XMLUI_FORM, C.XMLUI_PARAM, C.XMLUI_POPUP, C.XMLUI_DIALOG]:
1070 raise exceptions.DataError(_("Unknown panel type [%s]") % panel_type) 1070 raise exceptions.DataError(_("Unknown panel type [%s]") % panel_type)
1071 if panel_type == C.XMLUI_FORM and submit_id is None: 1071 if panel_type == C.XMLUI_FORM and submit_id is None:
1072 raise exceptions.DataError(_("form XMLUI need a submit_id")) 1072 raise exceptions.DataError(_("form XMLUI need a submit_id"))
1073 if not isinstance(container, basestring): 1073 if not isinstance(container, basestring):
1080 self.doc = impl.createDocument(None, "sat_xmlui", None) 1080 self.doc = impl.createDocument(None, "sat_xmlui", None)
1081 top_element = self.doc.documentElement 1081 top_element = self.doc.documentElement
1082 top_element.setAttribute("type", panel_type) 1082 top_element.setAttribute("type", panel_type)
1083 if title: 1083 if title:
1084 top_element.setAttribute("title", title) 1084 top_element.setAttribute("title", title)
1085 self._submit_id = submit_id 1085 self.submit_id = submit_id
1086 self.session_id = session_id 1086 self.session_id = session_id
1087 if panel_type == C.XMLUI_DIALOG: 1087 if panel_type == C.XMLUI_DIALOG:
1088 if dialog_opt is None: 1088 if dialog_opt is None:
1089 dialog_opt = {} 1089 dialog_opt = {}
1090 self._createDialog(dialog_opt) 1090 self._createDialog(dialog_opt)
1131 return object.__getattribute__(self, name) 1131 return object.__getattribute__(self, name)
1132 1132
1133 @property 1133 @property
1134 def submit_id(self): 1134 def submit_id(self):
1135 top_element = self.doc.documentElement 1135 top_element = self.doc.documentElement
1136 if not top_element.hasAttribute("submit"):
1137 # getAttribute never return None (it return empty string it attribute doesn't exists)
1138 # so we have to manage None here
1139 return None
1136 value = top_element.getAttribute("submit") 1140 value = top_element.getAttribute("submit")
1137 return value or None 1141 return value
1138 1142
1139 @submit_id.setter 1143 @submit_id.setter
1140 def submit_id(self, value): 1144 def submit_id(self, value):
1141 top_element = self.doc.documentElement 1145 top_element = self.doc.documentElement
1142 if value is None: 1146 if value is None:
1166 else: 1170 else:
1167 raise exceptions.DataError("session_id can't be empty") 1171 raise exceptions.DataError("session_id can't be empty")
1168 1172
1169 def _createDialog(self, dialog_opt): 1173 def _createDialog(self, dialog_opt):
1170 dialog_type = dialog_opt.setdefault(C.XMLUI_DATA_TYPE, C.XMLUI_DIALOG_MESSAGE) 1174 dialog_type = dialog_opt.setdefault(C.XMLUI_DATA_TYPE, C.XMLUI_DIALOG_MESSAGE)
1171 if dialog_type in [C.XMLUI_DIALOG_CONFIRM, C.XMLUI_DIALOG_FILE] and self._submit_id is None: 1175 if dialog_type in [C.XMLUI_DIALOG_CONFIRM, C.XMLUI_DIALOG_FILE] and self.submit_id is None:
1172 raise exceptions.InternalError(_("Submit ID must be filled for this kind of dialog")) 1176 raise exceptions.InternalError(_("Submit ID must be filled for this kind of dialog"))
1173 top_element = TopElement(self) 1177 top_element = TopElement(self)
1174 level = dialog_opt.get(C.XMLUI_DATA_LVL) 1178 level = dialog_opt.get(C.XMLUI_DATA_LVL)
1175 dialog_elt = DialogElement(top_element, dialog_type, level) 1179 dialog_elt = DialogElement(top_element, dialog_type, level)
1176 1180
1251 @param xmlui(XMLUI): instance of the XMLUI 1255 @param xmlui(XMLUI): instance of the XMLUI
1252 Must be an XMLUI that you can submit, with submit_id set to '' 1256 Must be an XMLUI that you can submit, with submit_id set to ''
1253 @param profile: %(doc_profile)s 1257 @param profile: %(doc_profile)s
1254 @return (data): a deferred which fire the data 1258 @return (data): a deferred which fire the data
1255 """ 1259 """
1256 assert xmlui._submit_id == '' # xmlui.submit_id can't be the empty string, but xmlui._submit_id must here 1260 assert xmlui.submit_id == ''
1257 xmlui_d = defer.Deferred() 1261 xmlui_d = defer.Deferred()
1258 1262
1259 def onSubmit(data, profile): 1263 def onSubmit(data, profile):
1260 xmlui_d.callback(data) 1264 xmlui_d.callback(data)
1261 return {} 1265 return {}