changeset 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 a151f3a5a2d0
children 51dec65ec62c
files src/stdui/ui_profile_manager.py src/tools/xml_tools.py
diffstat 2 files changed, 10 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/stdui/ui_profile_manager.py	Sat Sep 26 14:24:33 2015 +0200
+++ b/src/stdui/ui_profile_manager.py	Sat Sep 26 15:00:27 2015 +0200
@@ -65,7 +65,7 @@
                     return self._verifyPassword(data_, profile)
 
                 callback_id = self.host.registerCallback(xmlui_cb, with_data=True, one_shot=True)
-                form_ui = xml_tools.XMLUI("form", title=D_('Profile password for %s') % profile, submit_id=callback_id)
+                form_ui = xml_tools.XMLUI("form", title=D_('Profile password for {}').format(profile), submit_id=callback_id)
                 form_ui.addPassword('profile_password', value='')
                 return {'xmlui': form_ui.toXml()}
 
--- a/src/tools/xml_tools.py	Sat Sep 26 14:24:33 2015 +0200
+++ b/src/tools/xml_tools.py	Sat Sep 26 15:00:27 2015 +0200
@@ -1065,7 +1065,7 @@
         @param submit_id: callback id to call for panel_type we can submit (form, param, dialog)
         @param session_id: use to keep a session attached to the dialog, must be returned by frontends
         """
-        self._introspect()
+        self._introspect() # FIXME: why doing that on each XMLUI ? should be done once
         if panel_type not in [C.XMLUI_WINDOW, C.XMLUI_FORM, C.XMLUI_PARAM, C.XMLUI_POPUP, C.XMLUI_DIALOG]:
             raise exceptions.DataError(_("Unknown panel type [%s]") % panel_type)
         if panel_type == C.XMLUI_FORM and submit_id is None:
@@ -1082,7 +1082,7 @@
         top_element.setAttribute("type", panel_type)
         if title:
             top_element.setAttribute("title", title)
-        self._submit_id = submit_id
+        self.submit_id = submit_id
         self.session_id = session_id
         if panel_type == C.XMLUI_DIALOG:
             if dialog_opt is None:
@@ -1133,8 +1133,12 @@
     @property
     def submit_id(self):
         top_element = self.doc.documentElement
+        if not top_element.hasAttribute("submit"):
+            # getAttribute never return None (it return empty string it attribute doesn't exists)
+            # so we have to manage None here
+            return None
         value = top_element.getAttribute("submit")
-        return value or None
+        return value
 
     @submit_id.setter
     def submit_id(self, value):
@@ -1168,7 +1172,7 @@
 
     def _createDialog(self, dialog_opt):
         dialog_type = dialog_opt.setdefault(C.XMLUI_DATA_TYPE, C.XMLUI_DIALOG_MESSAGE)
-        if dialog_type in [C.XMLUI_DIALOG_CONFIRM, C.XMLUI_DIALOG_FILE] and self._submit_id is None:
+        if dialog_type in [C.XMLUI_DIALOG_CONFIRM, C.XMLUI_DIALOG_FILE] and self.submit_id is None:
             raise exceptions.InternalError(_("Submit ID must be filled for this kind of dialog"))
         top_element = TopElement(self)
         level = dialog_opt.get(C.XMLUI_DATA_LVL)
@@ -1253,7 +1257,7 @@
     @param profile: %(doc_profile)s
     @return (data): a deferred which fire the data
     """
-    assert xmlui._submit_id == '' # xmlui.submit_id can't be the empty string, but xmlui._submit_id must here
+    assert xmlui.submit_id == ''
     xmlui_d = defer.Deferred()
 
     def onSubmit(data, profile):