betabug... Sascha Welter

home english | home deutsch | Site Map | Sascha | Kontakt | Pro | Weblog | Wiki

09 May 2005

Trees for Page Templates

ZopeTree, ZTUtils.Tree, DTML tree, or... ExpansionTree?

After my last note on using ZopeTree (with patch), I had contacted the author and heard that ZopeTree will be all new and nice in Zope 3. But for the moment the lack of documentation made me look elsewhere. What I'm using now is ExpansionTree.

Expansion Tree has just a little bit more documentation. But it works nice for me, especially for storing state information in the SESSION. The tree generation logic is not in my Page Template, but in a method of my Python Product. Getting the state is done with a simple:

ctree = request.SESSION.get("ctree", '')
and after processing we can store the state again, approximately like this:
[...some other code...]
tree, rows, state = t.grow(root, ctree,
        request.form.get(todo_var, ''), default_state={})
request.SESSION["ctree"] = state
return {"tree":tree, "rows":rows}
Where the "return" will give back the values needed to display the tree in the ZPT (Zope Page Template).

Caveats: When the SESSION expires, the tree state is gone and the tree will be shown collapsed again. In this application I have set the SESSION to a long time, plus I have the tree in a default partially expanded state. But you may want to look into this.

Posted by betabug at 09:21 | Comments (2) | Trackbacks (0)
ch athens
Life in Athens (Greece) for a foreigner from the other side of the mountains. And with an interest in digital life and the feeling of change in a big city. Multilingual English - German - Greek.
Main blog page
Recent Entries
Best of
Some of the most sought after posts, judging from access logs and search engine queries.

Apple & Macintosh:
Security & Privacy:
Misc technical:
Athens for tourists and visitors:
Life in general:
<< Slacky Tiger on a Rainbow | Main | May 1st Postponed Due to Popular Demand >>
Re: Trees for Page Templates

I am having a problem when I try to list the Plone Folders. AttributeError: getId. Do you know how to solve this?

Posted by: Silvio at September 20,2005 21:32
Re: Trees for Page Templates

Yes, I know how to solve it, but very likely you won't like my answer :-)

- Look at the complete Traceback from the error (can be found in the /error_log)
- Find the code that produces the error, including in which product it is, which line, on which object
- Look at the code and try to see what's wrong
- For Plone Folders there is already a ready made module that does the tree thing, the NavTreePortlet, use that

Posted by: betabug at September 21,2005 08:46
You can trackback to:
There are no trackbacks.