it is me again. I am finally at a point where I try to write my first application in Zope. My goal is to write a threaded Discussion Board. I did one before in Python using CGIs. Here is the supporting table in PostGreSQL:
id int4 pid int4 date datetime title varchar(40) body text
First, I'd avoid using id as a column name in Zope -- Zope uses id and can get cranky when conflicts arise.. Let's assume you change it to: obj_id int4 parent_id int4 date datetime title varchar(40) body text What I'm about to suggest came to me by way of Anthony Baxter -- any cleverness it his. Any bugs are mine. Try: SQL Method sqlSelectChildren: --- select * from posts where <!--#if "parent_id == 0"--> parent_id is NULL <!--#else--> parent_id = <!--#sqlvar parent_id type=int--> <!--#/if--> --- Now the tree. This DTML gives a tree, with each node in the tree a link to URL1/main_view?obj_id=<the object's id> --- <!--#with "_.namespace(parent_id = 0)"--> <!--#tree id=parent_id branches_expr="sqlSelectChildren(parent_id=parent_id)"--> <a href="<!--#var URL1-->/ViewPost?parent_id=<!--#var parent_id-->"> <!--#var title--> </a> <!--#/tree--> <!--#/with-->
Rob Page wrote:
Try:
SQL Method sqlSelectChildren: --- select * from posts where <!--#if "parent_id == 0"--> parent_id is NULL <!--#else--> parent_id = <!--#sqlvar parent_id type=int--> <!--#/if--> ---
Now the tree. This DTML gives a tree, with each node in the tree a link to URL1/main_view?obj_id=<the object's id>
--- <!--#with "_.namespace(parent_id = 0)"--> <!--#tree id=parent_id branches_expr="sqlSelectChildren(parent_id=parent_id)"--> <a href="<!--#var URL1-->/ViewPost?parent_id=<!--#var parent_id-->"> <!--#var title--> </a> <!--#/tree--> <!--#/with-->
Lat week I did an example to test recursive calls with nearly the same TABLE-design (parent_id=father was the main difference + other entries in the table..)). To see the whole hierarchy I put <!--#var rekursiv--> in a file and "rekursiv" was somehting like.. <!--#in "getChildren(root=root)"--> <LI>..........</LI> <!--#with "_.namespace(root=child)"--> <!--#var rekursiv--> <!--#/with--> <!--#/in--> I was trying to figure out the code obove, so I was very happy to see how to do it. Unfortunately it does not work. When I test it I see nothing. I tried to take a look at a subtree with <!--#with "_.namespace(parent_id = 4)"--> ... and got something, but not what you would expect. The tree reproduces itself in an endless way! sqlSelectChildren works fine (when I plug in a parent_id, I see the children as expected..), so the problem is located in the other part. The code looks correct, so I do not have a clue what could be wrong?? Has anybody got this example running? -- Tom
I wrote Rob. I had the same problem. Could not figure it out either. I think the call branches_expr="sqlSelectChildren(parent_id=parent_id)" is wrong and should be: branches_expr="sqlSelectChildren(parent_id=obj_id)" ******** But obj_id is not defined, therefore it does not work. But I am pretty sure that's it. Can anyone help? stephan On Sun, 08 Aug 1999, you wrote:
Rob Page wrote:
Try:
SQL Method sqlSelectChildren: --- select * from posts where <!--#if "parent_id == 0"--> parent_id is NULL <!--#else--> parent_id = <!--#sqlvar parent_id type=int--> <!--#/if--> ---
Now the tree. This DTML gives a tree, with each node in the tree a link to URL1/main_view?obj_id=<the object's id>
--- <!--#with "_.namespace(parent_id = 0)"--> <!--#tree id=parent_id branches_expr="sqlSelectChildren(parent_id=parent_id)"--> <a href="<!--#var URL1-->/ViewPost?parent_id=<!--#var parent_id-->"> <!--#var title--> </a> <!--#/tree--> <!--#/with-->
Lat week I did an example to test recursive calls with nearly the same TABLE-design (parent_id=father was the main difference + other entries in the table..)). To see the whole hierarchy I put
<!--#var rekursiv-->
in a file and "rekursiv" was somehting like..
<!--#in "getChildren(root=root)"--> <LI>..........</LI> <!--#with "_.namespace(root=child)"--> <!--#var rekursiv--> <!--#/with--> <!--#/in-->
I was trying to figure out the code obove, so I was very happy to see how to do it. Unfortunately it does not work. When I test it I see nothing.
I tried to take a look at a subtree with
<!--#with "_.namespace(parent_id = 4)"--> ...
and got something, but not what you would expect. The tree reproduces itself in an endless way!
sqlSelectChildren works fine (when I plug in a parent_id, I see the children as expected..), so the problem is located in the other part. The code looks correct, so I do not have a clue what could be wrong??
Has anybody got this example running?
--
Tom -- Stephan Richter iXL - Software Designer and Engineer
Rob Page wrote:
Try:
SQL Method sqlSelectChildren: --- select * from posts where <!--#if "parent_id == 0"--> parent_id is NULL <!--#else--> parent_id = <!--#sqlvar parent_id type=int--> <!--#/if--> ---
Now the tree. This DTML gives a tree, with each node in the tree a link to URL1/main_view?obj_id=<the object's id>
--- <!--#with "_.namespace(parent_id = 0)"--> <!--#tree id=parent_id branches_expr="sqlSelectChildren(parent_id=parent_id)"--> <a href="<!--#var URL1-->/ViewPost?parent_id=<!--#var parent_id-->"> <!--#var title--> </a> <!--#/tree--> <!--#/with-->
There seems to be no answer to this question available yet (??), although I'd like to find a solution (the above "solution" does not work..) Maybe someone can give us a simpler example for building a tree with a database method (hope this is not a FAQ)? I remember having seen something here a long time ago, but finding the right keywords for a search in a Zope mail folder with over 9000 mails is not that easy ;-) -- Tom http://www.linux-magazin.de/
Tom Schwaller schrieb: [...]
Maybe someone can give us a simpler example for building a tree with a database method (hope this is not a FAQ)? I remember having seen something here a long time ago, but finding the right keywords for a search in a Zope mail folder with over 9000 mails is not that easy ;-)
The example in http://www.zope.org/pipermail/zope/1999-July/006454.html helped me a lot, when I started with trees and SQL. HTH thomas -- fon: ++49 (0)40 42878 3781 fax: ++49 (0)40 42878 2728
Thomas Weiner wrote:
Tom Schwaller schrieb:
Maybe someone can give us a simpler example for building a tree with a database method (hope this is not a FAQ)? I remember having seen something here a long time ago, but finding the right keywords for a search in a Zope mail folder with over 9000 mails is not that easy ;-)
The example in http://www.zope.org/pipermail/zope/1999-July/006454.html helped me a lot, when I started with trees and SQL.
thanks a lot for that hint. The example is very instructive. I´ll analyze it tomorrow and report if I get some results in the other case.. -- Tom http://www.linux-magazin.de/
Tom Schwaller wrote:
There seems to be no answer to this question available yet (??), although I'd like to find a solution (the above "solution" does not work..)
Maybe someone can give us a simpler example for building a tree with a database method (hope this is not a FAQ)? I remember having seen something here a long time ago, but finding the right keywords for a search in a Zope mail folder with over 9000 mails is not that easy ;-)
To keep in line with the post's subject : is this (sorting zope and zope-dev usefully) not a matter where building trees of keywords would be useful ? Regards, Boris Borcic
Boris Borcic wrote:
Tom Schwaller wrote:
There seems to be no answer to this question available yet (??), although I'd like to find a solution (the above "solution" does not work..)
Maybe someone can give us a simpler example for building a tree with a database method (hope this is not a FAQ)? I remember having seen something here a long time ago, but finding the right keywords for a search in a Zope mail folder with over 9000 mails is not that easy ;-)
To keep in line with the post's subject : is this (sorting zope and zope-dev usefully) not a matter where building trees of keywords would be useful ?
jes, indeed. Nevertheles, I`m still in search of a solution for a problem :-) -- Tom
participants (5)
-
Boris Borcic -
Rob Page -
Stephan Richter -
Thomas Weiner -
Tom Schwaller