[Zope] Dictionary properties within Zope.

Martijn Pieters mj@antraciet.nl
Mon, 30 Aug 1999 09:18:38 +0200


At 20:50 29/08/99 , happyrhino@usa.net wrote:
>I'm embarassed to be asking yet another silly question but
>after 40 minutes searching the archives and the documentation,
>can't find it. Hopefully it'll be short and sweet =
>
>I can add properties which can be lines, strings, numbers.
>But hasn't anyone found the need to add dictionaries ?
>In almost every website I've created, the global configuration
>files are full of dictionary variables.
>For example, for navigation menus we might have
>navigation = {"Title 1" : URL1, "Title2" : URL2, etc}
>from which it's then simple to generate the HTML for the navigation.
>And there are many other instances where dictionaries save the day.
>
>This would have been something very useful to put in the root
>folder properties as a form of "site configuration".
>
>The only references to dictionaries seem to be with respect to the
>REQUEST.cookies and REQUEST.form and DTML doesn't seem to have the
>mechanisms for dealing with dictionary properties on folders.
>
>I'm getting around this right now with external methods but I'm also
>hoping to move all of my code into the Zope environment.
>
>Again, sorry for yet another question. Believe me, I searched.
>
>Henry

Indeed, there are no dictionary properties in Zope. But there are a few 
alternatives:

1) Reconsider your need for a dictionary.

     If you are duplicating data that is already in your Zope database, why 
not use that? If you are trying to create a site navigation scheme, try 
using methods like objectValues and properties on Folders to create you 
links. It avoids redundancy and broken links because of typos and 
out-of-sync dictionaries.

2) Use a TinyTable.

     This is a read-only tablelike object, that has the added advantage it 
retains order, unlike a dictionary. It is downloadable from the Contributed 
Area of the Zope web site. I think you might need to patch it slightly to 
have it working in Zope 2. Search the archives or ask Ty Sarna (his email 
address is likely to be mentioned somewhere in the TinyTable package).

3) Use a DTML Method.

     Using the return tag, a DTML Method can return more then just text. It 
can return any Python object:

   <dtml-return "{'Title 1' : URL1, 'Title2' : URL2}">



--
Martijn Pieters, Web Developer
| Antraciet http://www.antraciet.nl
| Tel: +31-35-7502100 Fax: +31-35-7502111
| mailto:mj@antraciet.nl http://www.antraciet.nl/~mj
| PGP: http://wwwkeys.nl.pgp.net:11371/pks/lookup?op=get&search=0xA8A32149
------------------------------------------