I looked back at what I posted, then at what I actually did in code, and realized why what I told you is wrong. See, here's what the tricky part of the tree tag is. It wants as its name/expr a single object to be the root; it doesn't grok the concept of multiple roots. So try it like this: <!--#with "_.namespace(obj_id=0)"--> <!--#tree branches_expr="query(obj_id=obj_id)"--> ... <!--#/tree--> <!--#/with--> Thus, the first query looks for roots, and subsequent queries should have obj_id filled in from the prior queries' results. Note that query() must look for root entries if obj_id is 0. As you can see, there are two minor changes from what I said before - first, there's no need to have the expr="query()" that I told you, it only messes things up. :) Second, a namespace is needed to provide a default value on the first execution of the query. At 02:39 AM 6/25/99 +0200, Alexander Staubo wrote:
[This post is old, but I haven't ended up tackling the topic until now.]
-----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Phillip J. Eby Sent: 9. juni 1999 21:21 To: Alexander Staubo; Zope Mailing List (E-mail) Subject: Re: [Zope] Tree tag and SQL methods?
No need. Just include the id as a field in your result, and have your branches_expr pass that id back into the query. Your query can then look like:
SELECT * FROM data WHERE <!--#if obj_id--> parent_id=<!--#sqlvar obj_id--> <!--#else--> parent_id IS NULL <!--#/if-->
And your tree would look like:
<!--#tree expr="query()" branches_expr="query(obj_id=obj_id)"--> ... etc.
It's been a long while since I did this, so I may be a bit off here. (It's been so long in fact, that when I did it, there was no such thing as a #sqlvar tag, and tree didn't *have* a branches_expr option! Which made this much more difficult to do, especially with pluggable brains thrown into the mix.)
Nope, doesn't work. First of all, #tree doesn't seem to handle SQL Method output the way I want -- I don't know why. Secondly, the branches_expr expression doesn't compute because obj_id isn't a known variable at this point; it should be written as
<!--#tree expr="query()" branches_expr="query(obj_id = _['obj_id'])"-->
But that doesn't seem to work either. Testing with a simple record with one parent record, #tree does render one item, but I can't get at the SQL row: For example, <!--#var obj_id--> inside the #tree tag gives me a NameError exception.
So how do I do it?
-- Alexander Staubo http://www.mop.no/~alex/ "What the hell, he thought, you're only young once, and threw himself out of the window. That would at least keep the element of surprise on his side." --Douglas Adams, _The Hitchhiker's Guide to the Galaxy_
_______________________________________________ Zope maillist - Zope@zope.org http://www.zope.org/mailman/listinfo/zope
(For developer-specific issues, use the companion list, zope-dev@zope.org - http://www.zope.org/mailman/listinfo/zope-dev )