[Zope] Tree tag and SQL methods?

Phillip J. Eby pje@telecommunity.com
Wed, 09 Jun 1999 14:09:35 -0500


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.)