From: Benoît Pin Date: Wed, 11 Dec 2013 21:23:20 +0000 (+0100) Subject: Patch de Products.CMFDefault.formlib.form._EditFormMixin._setRedirect Plinn implement... X-Git-Url: https://scm.cri.mines-paristech.fr/git/Plinn.git/commitdiff_plain/e1156e7b33a4336d4cc6f7dea46a335c8277d65b?ds=sidebyside Patch de Products.CMFDefault.formlib.form._EditFormMixin._setRedirect Plinn implementation pour prendre en compte le drapeau « ajax » lors de la redirection après traitement du formulaire. --- diff --git a/patch.py b/patch.py index fe60513..5f99887 100644 --- a/patch.py +++ b/patch.py @@ -25,4 +25,9 @@ CMFPortalFolder.listCatalogedContents = PlinnFolder.listCatalogedContents.im_fun cmfPortalFolderSecurity.declareProtected(AddPortalContent, 'put_upload') CMFPortalFolder.put_upload = PlinnFolder.put_upload.im_func -cmfPortalFolderSecurity.apply(CMFPortalFolder) \ No newline at end of file +cmfPortalFolderSecurity.apply(CMFPortalFolder) + + +from Products.CMFDefault.formlib.form import _EditFormMixin +from patch_impl import _setRedirect +_EditFormMixin._setRedirect = _setRedirect \ No newline at end of file diff --git a/patch_impl.py b/patch_impl.py new file mode 100644 index 0000000..32b0500 --- /dev/null +++ b/patch_impl.py @@ -0,0 +1,32 @@ +from ZTUtils import make_query +from Products.CMFCore.utils import getToolByName +from Products.CMFDefault.exceptions import zExceptions_Unauthorized +from Products.CMFDefault.utils import translate + +def _setRedirect(self, provider_id, action_path, keys=''): + # Products.CMFDefault.formlib.form._EditFormMixin._setRedirect Plinn implementation + provider = getToolByName(self.context, provider_id) + try: + target = provider.getActionInfo(action_path, self.context, + check_condition=1)['url'] + except (ValueError, zExceptions_Unauthorized): + target = self._getPortalURL() + + kw = {} + if self.status: + message = translate(self.status, self.context) + if isinstance(message, unicode): + message = message.encode(self._getBrowserCharset()) + kw['portal_status_message'] = message + for k in keys.split(','): + k = k.strip() + v = self.request.form.get(k, None) + if v: + kw[k] = v + + if self.request.form.has_key('ajax') : + kw['ajax'] = self.request.form['ajax'] + query = kw and ('?%s' % make_query(kw)) or '' + self.request.RESPONSE.redirect('%s%s' % (target, query)) + + return ''