[Zope] Re: Error publishing resource

Maciek Pasternacki maciekp at japhy.fnord.org
Mon Aug 30 08:51:05 EDT 2004


On Pungenday, Bureaucracy 24, 3170 YOLD, Raja Subramanian wrote:

>>   class BasketGenerator(Something):
>>       """Basket Generator product kept in ZODB"""
>>       def __getitem__(self, id):
>>           """Return theBasket instance"""
>>           rv = theBasket(self, id)
>>           return rv.__of__(self)
>>   
>
> I'm unable to understand what BasketGenerator is doing.
> Can you please explain what __getitem__ is upto?

It generates theBasket instance from given id (real data are taken
from SQL database) and returns it as its own subobject (it acts like
a folder).  So when I want to access theBasket with id 23, I go to
http://server/BasketGenerator/23 (I use it instead of
__bobo_traverse__, because I use generator also from Python and
dictionary-like access is easier than calling __bobo_traverse__ by
hand, and I don't need request passed as argument).

__of__ method of theBasket is inherited from Acquisition.Implicit and
sets returned instance's acquisition parent so that it can acquire
methods and attributes as if it was part of ZODB tree.

I omitted standard inheritance, __init__ etc. of normal Zope product
-- it's almost copy-and-paste from DevGuide, nothing special.  It's
there of course but it's __getitem__ that does the magic.

-- 
__    Maciek Pasternacki <maciekp at japhy.fnord.org> [ http://japhy.fnord.org/ ]
`| _   |_\  / { I tell you this, no eternal reward will forgive us now
,|{-}|}| }\/                                           for wasting the dawn! }
\/   |____/                                             ( Jim Morrison )  -><-



More information about the Zope mailing list