[Zope] Tree tag and SQL methods?

Alexander Staubo alex@mop.no
Mon, 28 Jun 1999 01:14:43 +0200


It worked! Thanks. Btw, this looks like HOWTO material to me.

As for the infinite recursion, I'd already included such a guard in my
own SQL code, but I deleted in the quoted code to make it clearer. ;-)

--
Alexander Staubo             http://www.mop.no/~alex/
"`This must be Thursday,' said Arthur to himself, sinking low over
his beer, `I never could get the hang of Thursdays.'"
--Douglas Adams, _The Hitchhiker's Guide to the Galaxy_

>-----Original Message-----
>From: Phillip J. Eby [mailto:pje@telecommunity.com]
>Sent: 28. juni 1999 01:11
>To: Alexander Staubo; Zope Mailing List (E-mail)
>Subject: RE: [Zope] Tree tag and SQL methods?
>
>
>Aha.  I've got it now.  Change the tree tag to read:
>
><!--#tree id=publication branches_expr="Data.pb_sql(pb =
>publication)"-->
>
>I reproduced your setup with a query of my own (totally
>different format),
>and got the same problem as you.  That is, the first level
>showed but the
>plus signs wouldn't expand anything.  The problem isn't with
>the queries;
>it's that the tree tag needs a persistent ID value to keep
>track of what
>branches are open/closed.  By default it uses the object's
>persistent ID,
>if it has one, otherwise it uses the Python 'id()' value.
>However, if the
>object is the result of an SQL query, there's no persistent ID, and the
>Python id() will change from hit to hit.  So when using query
>results, it's
>necessary to do an 'id=primary_key_field_name' in your tree
>tag to ensure
>it'll actually work as a tree.  I was doing this in all my current
>production code, but I overlooked it when describing to you what I did.
>
>By the way, as you have your query constructed, it will cause
>the tree to
>infinitely recurse once you hit the second level.  It would be good to
>restructure it a bit, as follows:
>
><!--#if "pb == ''"-->
>select distinct publication, count(publication) as pub_cnt
>from articles
>where publication != ''
>group by publication
>order by publication
><!--#else-->
>select title, 'nosuchpublication' as publication
>from articles
>where publication = <!--#sqlvar pb type=string-->
><!--#/if-->
>
>Without this change, the tree tag will not realize the
>articles are leaves,
>because when it calls the query to check on them, it will
>return all the
>publications again.
>
>
>At 12:39 AM 6/28/99 +0200, Alexander Staubo wrote:
>>Here you go:
>>
>><!--#with "_.namespace(publication = '')"-->
>>  <!--#tree branches_expr="Data.pb_sql(pb = publication)"-->
>
>>    <!--#var publication-->
>>  <!--#/tree-->
>><!--#/with-->
>>
>