[Zope] zpt weirdness?

Luca Olivetti luca@wetron.es
Tue, 19 Mar 2002 17:19:38 +0100


Hi,

I'm using mxmRelations (no, the problem isn't with that product) so I can track 
relations between various objects (companies, proposals, projects).
I defined some macros in zpt in order to, e.g., show a table of all proposals in the 
proposals folder and reuse that macro to show all proposals related to a company when 
I'm showing the company. Inside the tabular data for each proposal I show the company id 
and a link: e.g.: ("item" is the loop variable and is my object for proposal, and has ha 
method "getClient" which wraps an mxmRelation and returns an object, the company, or None)

<td tal:define="client item/getClient">
    <span tal:condition="client" tal:replace="default">
      <a href="somewhere" tal:attributes="href client/absolute_url"
          tal:content="client/id">Client</a>
     </span>
     <span tal:condition="not: client" tal:replace="default">
        <font color="red">not defined</font>
     </span>
</td>


All was working fine while I was using the macro inside the "proposals" folder, but when 
I tried to use it inside a company I got a recursion depth error.
It turns out that I didn't assimilate yet all the documentation ;-) and, after many 
desperate attempts to understand what was going wrong, I realized that path expressions 
will render the content of the page, so obviously inside the company trying to render 
the same company would cause a recursion error.
At first I changed the tal:define="client item/getClient" with tal:define="client 
python:item.getClient()" but that gave the same error.
So I changed the tal:define="client item/getClient" to tal:define="client 
nocall:item/getClient"

This solved the recursion problem but now I could not use "client/id" and 
"client/absolute_url" (and permutations like "python:client.getId()" and 
"python:client.absolute_url()").

I solved my problem by defining two more methods in my class (getClientId and 
getClientUrl). I'm not satisfied with this solution and I still don't understand why I 
could access attributes and methods of a rendered page and could not do that with the 
raw object. Besides, even if it's not causing a recursion depth exception, there are 
other sites where I'm using similar macros and I don't like the idea of causing a page 
to render just to show the id and a link.

Bye
-- 
Luca Olivetti
Wetron Automatización S.A. http://www.wetron.es/
Tel. +34 93 5883004      Fax +34 93 5883007