[Zope-dev] to __of__ or not to __of__ ?

Johan Carlsson [Torped] johanc@torped.se
Thu, 15 Aug 2002 10:32:19 +0200


>At 23:38 2002-08-14 -0400, Casey Duncan said:
>>The Item class mixes in Traversable, which is probably responsible for=20
>>making
>>this work TTW. It also gives you a bunch of other stuff that many Zope
>>classes need, like DAV support, copy support, ZMI tab support and=
 security.
>>It doen't mix-in acquisition tho.
>>
>>If you need support for acquistion machinery (including __of__ which=
 creates
>>wrappers), then you need to mix-in Acquisition.Implicit. The SimpleItem=20
>>class
>>mixes this and Persistence in for you (along with Item), so many Zope=20
>>classes
>>derive form SimpleItem. You need Persistence to store instances of your=20
>>class
>>in the ZODB, and implicit acquisition is the standard for Zope objects.
>>
>>In short I would recommend mixing in SimpleItem or you may find that your
>>objects are not stored properly in the ZODB.
>>
>>-Casey


You also might want to wrap the object before returning them,
because the are stored in _item and not in the AixtraTableProduct.

     def getItem(self,key): #{{{
         "returns item"
         data =3D self._items
         if data.has_key(key):
             item =3D self._items[key]
             if not hasattr(item,'key'):
                 setattr(item,'key',key)
             return item.__of__(self)  <--- wrap the item before returned

Regards,
Johan Carlsson




--=20
Torped Strategi och Kommunikation AB
Johan Carlsson
johanc@torped.se

Mail:
Birkagatan 9
SE-113 36  Stockholm
Sweden

Visit:
V=E4stmannagatan 67, Stockholm, Sweden

Phone +46-(0)8-32 31 23
Fax +46-(0)8-32 31 83
Mobil +46-(0)70-558 25 24
http://www.torped.se
http://www.easypublisher.com