[Zope] Re: Error publishing resource

Garito garito at sistes.net
Mon Aug 30 12:50:42 EDT 2004


Maciek Pasternacki wrote:

>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.
>
>  
>
Thanks all



More information about the Zope mailing list