[Zope] Tree tag and SQL methods?

Alexander Staubo alex@mop.no
Fri, 25 Jun 1999 02:39:06 +0200


[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?
>
>
>At 07:08 PM 6/9/99 +0200, Alexander Staubo wrote:
>>I don't have a head for figuring this out today, but maybe
>somebody here
>>can help me out.
>>
>>I'm thinking of exploiting the #tree tag in conjunction with
>one or more
>>SQL method. Say I have a hierarchical-ish table with id/parent_id
>>references, and I'd like to display this information in a nice
>>collapsible tree. Possible? Possibly the expr= or branches_expr=
>>arguments to #tree could evaluate the result of an SQL
>method, although
>>it sounds to me like this would require one query per tree level.
>>Possibly you could put the query results of the complete table in a
>>temporary variable and evaluate on that?
>
>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_