hi andrew:

thx for your help. i dont want to call the method from the PT ... infact I
dont want to modify the PT at all ... i just need to figure out a
ZopePageTemplate.py method which I can patch so I can do the redirect even
before the PT is rendered.

any ideas??

regards,
A

On Tue, Mar 10, 2009 at 11:59 AM, Andrew Milton <a...@theinternet.com.au>wrote:

> +-------[ Analog Kid ]----------------------
> | Hi All:
> |
> | I have a customized page template product which subclasses from
> | ZopePageTemplate. In this product class, I have a method that redirects
> to a
> | certain fixed page that I have created in the ZMI. One of the objects of
> this
> | type makes calls to this method and also has some conditional redirects
> (based
> | on certain request variables). Here is a representation
> |
> | In my Product class, I have a method which conditionally redirects ...
> |
> | def check_and_redirect(self):
> |     request = self.REQUEST
> |     if request.get('redirect_to_fixed_page', False):
> |         request.RESPONSE.redirect('http://somefixedurl_in_my_domain')
> |
> | def getValue(self):
> |     self.check_and_redirect()
> |     # do some more stuff
> |     ....
> |     ....
> |     return 'some value'
> |
> | My ZPT looks like this ...
> | ...
> | <tal:call tal:define="data python:mytemplate.getValue()"/>
> | ...
> | ...
> | ...
> | ...
> | <tal:redir tal:condition="python:here.REQUEST.has_key('var')">
> | <tal:dummy tal:define="test
> python:here.REQUEST.RESPONSE.redirect('http://
> | someotherurl")"/>
> | </tal:redir>
> | ...
> | ...
> | ...
> |
> |
> | What is happeninig is that the redirect in the PT is taking precedence
> over my
> | redirect (which Im doing in the method). My question is: Can I make sure
> that
> | my redirect takes precedence without modifying the PT itself. Is there
> any
> | other ZopePageTemplate method which I can patch so that my own redirect
> kicks
> | in first??
>
> add a flag to getValue that says don't redirect
>
> def getValue(self, redirect = False):
>   if(redirect):
>       self.check_and_redirect()
>
> or pass it up to check_and_redirect
>
> Which means you have to change other calls that aren't in the ZPT
> If you're happy to change the one ZPT, you can reverse the flag to be
> True and pass False in from the ZPT.
>
> It depends which way is more work.
>
> You'll also find that doing a redirect and then adding more stuff to the
> response will cause the redirect to "not work" under certain browsers
> under certain conditions. It's best to terminate processing as soon as
> possible when you decide to redirect, so it's probably unwise to
> redirect without returning some status to the caller than indicates the
> rest of the processing is redundant.
>
> --
> Andrew Milton
> a...@theinternet.com.au
>
_______________________________________________
Zope maillist  -  Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://mail.zope.org/mailman/listinfo/zope-announce
 http://mail.zope.org/mailman/listinfo/zope-dev )

Reply via email to