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
Luca Olivetti wrote:
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()").
Duh, I got it, even without help from the list :-/ tal:define="client nocall:item/getClient" will return the *method* getClient and not the object returned by it, so it's obvious that a "python method" doesn't have such attributes as "absolute_url" or "id" :-) The correct incantation is tal:define="client python:item.getClient()" BTW, the correct condition to test if the returned object is not None is tal:condition="python: client" and not tal:condition="client" (which works but would cause the object to render). Thank you again. -- Luca Olivetti Wetron Automatización S.A. http://www.wetron.es/ Tel. +34 93 5883004 Fax +34 93 5883007
On Wed, Mar 20, 2002 at 03:58:39PM +0100, Luca Olivetti wrote:
Luca Olivetti wrote:
...snip...
Duh, I got it, even without help from the list :-/
...snip... No offense to you or anyone in this list, but you might get better responses to zpt questions from the zpt list. With the volume here sometimes zpt questions get lost. Sign up here http://lists.zope.org/mailman/listinfo/zpt Chris
-- Luca Olivetti Wetron Automatización S.A. http://www.wetron.es/ Tel. +34 93 5883004 Fax +34 93 5883007
Chris Meyers wrote:
No offense to you or anyone in this list, but you might get better responses to zpt questions from the zpt list. With the volume here sometimes zpt questions get lost.
Sign up here http://lists.zope.org/mailman/listinfo/zpt
Thanks, I'm doing that now. With so many lists that one just escaped me ;-) Bye -- Luca Olivetti Wetron Automatización S.A. http://www.wetron.es/ Tel. +34 93 5883004 Fax +34 93 5883007
participants (2)
-
Chris Meyers -
Luca Olivetti