[Zope] Tree tag and SQL methods?

Alexander Staubo alex@mop.no
Fri, 25 Jun 1999 19:43:22 +0200


I haven't tested this yet, but it seems sound; I'll let you know if it
doesn't. :-)

Now perhaps you can assist in another similar case with the #tree tag.

Basically I have a two-level hierarchy of (simplified) articles and
their home publication. The article database might be something like
this:

	Title:	Publication:
	Foo	Bar Mag
	Bar	Fnargh Times
	...

I seek to render a "tree" where the publication is the tree node, and
the list of articles (by their title) are listed under each node. A
little like the "Quick Start" thing. Click on the "plus" icon beside the
publication and you get a (non-tree) list of articles. Actually I get
this is, strictly speaking, a one-level hierarchy.

While this structure is simple enough that could stay clear of using the
#tree tag, I'd still like to try. I tried:

<!--#tree expr="Query()" leaves="Leaf"-->
  <!--#var Publication--><br>
<!--#/tree-->

thinking that Query() would return the publications, and each
publication would use the DTML Method Leaf to render its contents, but
no. What am I missing?

--
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_

>-----Original Message-----
>From: Phillip J. Eby [mailto:pje@telecommunity.com]
>Sent: 25. juni 1999 18:38
>To: Alexander Staubo; Zope Mailing List (E-mail)
>Subject: RE: [Zope] Tree tag and SQL methods?
>
>
>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 )
>
>