web/controller.py
changeset 4897 e402e0b32075
parent 4884 f175997057b5
child 5040 00782905b720
equal deleted inserted replaced
4896:45a1c3f0d0d9 4897:e402e0b32075
     5 :copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
     5 :copyright: 2001-2010 LOGILAB S.A. (Paris, FRANCE), license is LGPL v2.
     6 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     6 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
     7 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
     7 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
     8 """
     8 """
     9 __docformat__ = "restructuredtext en"
     9 __docformat__ = "restructuredtext en"
       
    10 
       
    11 from logilab.mtconverter import xml_escape
    10 
    12 
    11 from cubicweb.selectors import yes
    13 from cubicweb.selectors import yes
    12 from cubicweb.appobject import AppObject
    14 from cubicweb.appobject import AppObject
    13 from cubicweb.web import LOGGER, Redirect, RequestError
    15 from cubicweb.web import LOGGER, Redirect, RequestError
    14 
    16 
    96         parameters
    98         parameters
    97         """
    99         """
    98         newparams = {}
   100         newparams = {}
    99         # sets message if needed
   101         # sets message if needed
   100         if self._cw.message:
   102         if self._cw.message:
   101             newparams['__message'] = self._cw.message
   103             newparams['_cwmsgid'] = self._cw.set_redirect_message(self._cw.message)
   102         if self._cw.form.has_key('__action_apply'):
   104         if self._cw.form.has_key('__action_apply'):
   103             self._return_to_edition_view(newparams)
   105             self._return_to_edition_view(newparams)
   104         if self._cw.form.has_key('__action_cancel'):
   106         if self._cw.form.has_key('__action_cancel'):
   105             self._return_to_lastpage(newparams)
   107             self._return_to_lastpage(newparams)
   106         else:
   108         else:
   118             path = 'view'
   120             path = 'view'
   119             newparams['rql'] = rql
   121             newparams['rql'] = rql
   120         elif '__redirectpath' in self._cw.form:
   122         elif '__redirectpath' in self._cw.form:
   121             # if redirect path was explicitly specified in the form, use it
   123             # if redirect path was explicitly specified in the form, use it
   122             path = self._cw.form['__redirectpath']
   124             path = self._cw.form['__redirectpath']
   123             if self._edited_entity and path != self._edited_entity.rest_path():
   125             if (self._edited_entity and path != self._edited_entity.rest_path()
   124                 # XXX may be here on modification? if yes the message should be
   126                 and '_cwmsgid' in newparams):
   125                 # modified where __createdpath is detected (cw.web.request)
   127                 # XXX may be here on modification?
   126                 newparams['__createdpath'] = self._edited_entity.rest_path()
   128                 msg = u'(<a href="%s">%s</a>)' % (
       
   129                     xml_escape(self._edited_entity.absolute_url()),
       
   130                     self._cw._('click here to see created entity'))
       
   131                 self._cw.append_to_redirect_message(msg)
   127         elif self._after_deletion_path:
   132         elif self._after_deletion_path:
   128             # else it should have been set during form processing
   133             # else it should have been set during form processing
   129             path, params = self._after_deletion_path
   134             path, params = self._after_deletion_path
   130             params = dict(params) # params given as tuple
   135             params = dict(params) # params given as tuple
   131             params.update(newparams)
   136             params.update(newparams)
   147         # else, fallback on the old `view?rql=...` url form
   152         # else, fallback on the old `view?rql=...` url form
   148         elif 'rql' in self._cw.form:
   153         elif 'rql' in self._cw.form:
   149             path = 'view'
   154             path = 'view'
   150             newparams['rql'] = form['rql']
   155             newparams['rql'] = form['rql']
   151         else:
   156         else:
   152             self.warning("the edited data seems inconsistent")
   157             self.warning('the edited data seems inconsistent')
   153             path = 'view'
   158             path = 'view'
   154         # pick up the correction edition view
   159         # pick up the correction edition view
   155         if form.get('__form_id'):
   160         if form.get('__form_id'):
   156             newparams['vid'] = form['__form_id']
   161             newparams['vid'] = form['__form_id']
   157         # re-insert copy redirection parameters
   162         # re-insert copy redirection parameters