Kevin Dangoor <kid@kendermedia.com> wrote
----- Original Message ----- From: "Darran Edmundson" <dee124@rsphy1.anu.edu.au> To: <zope@zope.org> Sent: Sunday, February 13, 2000 9:40 AM Subject: [Zope] building a revisitable object list???
I'm using nested <dtml-in> blocks to descend two levels into a portion of my ZODB. I'm only interested in the leaf nodes. However, rather than act on them while "visiting", I want to conditionally store a reference to them in a python list so that I can visit any leaf later on.
This should probably be done in a PythonMethod. It's sooooo much cleaner. I used to do this kind of thing in DTML, because it was too much of a pain to make an ExternalMethod. With PythonMethods, I find it so much more user friendly to write this kind of logic directly in python.
I'll make it clear with a pared-down example.
root folder1 subfolder1a subfolder1b folder2 subfolder2a
I want to build a list such that I can visit various subfolders without having to search them out.
So the subfolders all have unique names? If so, you can build a hash:
leaves = {}
for folder in objectValues('Folder'): for leaf in folder.objectValues('Folder'): leaves.update({leaf.id : leaf})
After this, you can just do leaves['subfolder1a'] to get the actual subfolder1a object.
That 'leaves.update(..}' is a really ugly workaround to the fact that PythonMethods won't allow the "natural" dictionary manipulation: 'leaves[ leaf.id ] = leaf'. While I understand not wanting to allow key replacement in "global" dictionaries, can we lose this restriction for "local" ones? (OTOH, we need to look at potential security issues around the use of update(), too). Tres. -- ========================================================= Tres Seaver tseaver@palladion.com 713-523-6582 Palladion Software http://www.palladion.com
----- Original Message ----- From: Tres Seaver <tseaver@palladion.com>
That 'leaves.update(..}' is a really ugly workaround to the fact that PythonMethods won't allow the "natural" dictionary manipulation: 'leaves[ leaf.id ] = leaf'. While I understand not wanting to allow key replacement in "global" dictionaries, can we lose this restriction for "local" ones?
Yes we can, provided you code carefully. See my PROPOSAL: in Zope-dev a few weeks ago.
(OTOH, we need to look at potential security issues around the use of update(), too).
Too true. Any exposed list or dict needs a sharp examination. Cheers, Evan @ digicool
participants (2)
-
Evan Simpson -
Tres Seaver