Trees for Page Templates
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.