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">&lt;<a href="mailto:akm@theinternet.com.au">akm@theinternet.com.au</a>&gt;</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(&#39;redirect_to_fixed_page&#39;, False):<br>
|         request.RESPONSE.redirect(&#39;<a href="http://somefixedurl_in_my_domain" target="_blank">http://somefixedurl_in_my_domain</a>&#39;)<br>
|<br>
| def getValue(self):<br>
|     self.check_and_redirect()<br>
|     # do some more stuff<br>
|     ....<br>
|     ....<br>
|     return &#39;some value&#39;<br>
|<br>
| My ZPT looks like this ...<br>
| ...<br>
| &lt;tal:call tal:define=&quot;data python:mytemplate.getValue()&quot;/&gt;<br>
| ...<br>
| ...<br>
| ...<br>
| ...<br>
| &lt;tal:redir tal:condition=&quot;python:here.REQUEST.has_key(&#39;var&#39;)&quot;&gt;<br>
| &lt;tal:dummy tal:define=&quot;test python:here.REQUEST.RESPONSE.redirect(&#39;http://<br>
| someotherurl&quot;)&quot;/&gt;<br>
| &lt;/tal:redir&gt;<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&#39;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&#39;t in the ZPT<br>
If you&#39;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&#39;ll also find that doing a redirect and then adding more stuff to the<br>
response will cause the redirect to &quot;not work&quot; under certain browsers<br>
under certain conditions. It&#39;s best to terminate processing as soon as<br>
possible when you decide to redirect, so it&#39;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>