Back to index

plone3  3.1.7
RedirectTo.py
Go to the documentation of this file.
00001 from BaseFormAction import BaseFormAction
00002 from Products.CMFFormController.FormController import registerFormAction
00003 from urlparse import urlparse, urljoin
00004 
00005 def factory(arg):
00006     """Create a new redirect-to action"""
00007     return RedirectTo(arg)
00008 
00009 
00010 class RedirectTo(BaseFormAction):
00011     def __call__(self, controller_state):
00012         url = self.getArg(controller_state)
00013         context = controller_state.getContext()
00014         # see if this is a relative url or an absolute
00015         if len(urlparse(url)[1]) == 0:
00016             # No host specified, so url is relative.  Get an absolute url.
00017             url = urljoin(context.absolute_url()+'/', url)
00018         url = self.updateQuery(url, controller_state.kwargs)
00019         return context.REQUEST.RESPONSE.redirect(url)
00020 
00021 
00022 registerFormAction('redirect_to',
00023                    factory,
00024                    'Redirect to the URL specified in the argument (a TALES expression).  The URL can either be absolute or relative.')