[Zope3-Users] Q: Custom containers, non-persistent items

Stephan Richter srichter at cosmos.phy.tufts.edu
Wed Nov 10 18:50:07 EST 2004


On Wednesday 10 November 2004 02:47, Paul Everitt wrote:
> First, this is very much a newbie question, so apologies in advance.
> Yesterday I sent this note to zope3-dev before this list was created,
> but this question clearly isn't meant for zope3-dev.
>
> I'm trying to fill in the example in
> zope/app/container/sample.py->SampleContainer.  My ultimate goal is to
> traverse a custom container, grab the next item, and look it up in
> Berkeley DB XML.  For example, dbxmlfolder/37 would look up an item
> "37" in the DBXML and return some HTML that I generate.
>
> sample.py->SampleContainer has a method _newContainerData where you
> supply a mapping.  I have wired this up, returning an empty dictionary,
> and I can browse to dbxmlfolder.  I can't, though, browse to any items
> in the dictionary.

The dictionary is empty, so you cannot browse to any items. :-)

I think using the SampleContainer might not be what you want to do. I think it 
would be better to start implementing IContainer from scratch; this way you 
can control better what each method returns. In fact, you will be able to 
create better optimized queries for the methods. For example, when trying to 
get the number of items in the container, instead of taking the length of the 
dictionary (which has to be created), you can probably write a more efficient 
XPath expression to access the amount of items in the container.

> 1) Are the keys for this dictionary simple strings?

The IContainer interface does not say so, but trust me, almost all of Zope 3 
depends on them being unicode strings...I have been there before trying to 
make ids integers...it is a miserable pain in the b***!

> 2) Are the values...errr, special in any way?  For example, can I just
> put instances of Python classes that aren't wired into the CA (so I can
> skip debugging ZCML, interfaces, factories, views, etc. until I get
> past this traceback)?

No, but in order for them to work well, the have to be ILocations; you can put 
a proxy around the values before returning them using 
zope.app.location.locate(object, parent, name).

> Stated differently, what is the least amount of work to get
> _newContainerData to return non-empty sample information when
> traversing to an item?  I'm looking for something like Bobo's
> publishable mappings.

Yeah, you can do this, but it would be expensive, since you either would need 
a complex mapping object or do the query for all objects every time the 
container is created. I'd say implement IContainer yourself and be happy. :-)


Regards,
Stephan
-- 
Stephan Richter
CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student)
Web2k - Web Software Design, Development and Training


More information about the Zope3-users mailing list