hi andrew:<br><br>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.<br>
<br>any ideas??<br><br>regards,<br>A<br><br><div class="gmail_quote">On Tue, Mar 10, 2009 at 11:59 AM, Andrew Milton <span dir="ltr"><<a href="mailto:akm@theinternet.com.au">akm@theinternet.com.au</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">+-------[ Analog Kid ]----------------------<br>
<div><div></div><div class="h5">| Hi All:<br>
|<br>
| I have a customized page template product which subclasses from<br>
| ZopePageTemplate. In this product class, I have a method that redirects to a<br>
| certain fixed page that I have created in the ZMI. One of the objects of this<br>
| type makes calls to this method and also has some conditional redirects (based<br>
| on certain request variables). Here is a representation<br>
|<br>
| In my Product class, I have a method which conditionally redirects ...<br>
|<br>
| def check_and_redirect(self):<br>
| request = self.REQUEST<br>
| if request.get('redirect_to_fixed_page', False):<br>
| request.RESPONSE.redirect('<a href="http://somefixedurl_in_my_domain" target="_blank">http://somefixedurl_in_my_domain</a>')<br>
|<br>
| def getValue(self):<br>
| self.check_and_redirect()<br>
| # do some more stuff<br>
| ....<br>
| ....<br>
| return 'some value'<br>
|<br>
| My ZPT looks like this ...<br>
| ...<br>
| <tal:call tal:define="data python:mytemplate.getValue()"/><br>
| ...<br>
| ...<br>
| ...<br>
| ...<br>
| <tal:redir tal:condition="python:here.REQUEST.has_key('var')"><br>
| <tal:dummy tal:define="test python:here.REQUEST.RESPONSE.redirect('http://<br>
| someotherurl")"/><br>
| </tal:redir><br>
| ...<br>
| ...<br>
| ...<br>
|<br>
|<br>
| What is happeninig is that the redirect in the PT is taking precedence over my<br>
| redirect (which Im doing in the method). My question is: Can I make sure that<br>
| my redirect takes precedence without modifying the PT itself. Is there any<br>
| other ZopePageTemplate method which I can patch so that my own redirect kicks<br>
| in first??<br>
<br>
</div></div>add a flag to getValue that says don't redirect<br>
<br>
def getValue(self, redirect = False):<br>
if(redirect):<br>
self.check_and_redirect()<br>
<br>
or pass it up to check_and_redirect<br>
<br>
Which means you have to change other calls that aren't in the ZPT<br>
If you're happy to change the one ZPT, you can reverse the flag to be<br>
True and pass False in from the ZPT.<br>
<br>
It depends which way is more work.<br>
<br>
You'll also find that doing a redirect and then adding more stuff to the<br>
response will cause the redirect to "not work" under certain browsers<br>
under certain conditions. It's best to terminate processing as soon as<br>
possible when you decide to redirect, so it's probably unwise to<br>
redirect without returning some status to the caller than indicates the<br>
rest of the processing is redundant.<br>
<font color="#888888"><br>
--<br>
Andrew Milton<br>
<a href="mailto:akm@theinternet.com.au">akm@theinternet.com.au</a><br>
</font></blockquote></div><br>