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

Casey Duncan casey@zope.com
Wed, 14 Aug 2002 23:38:52 -0400


The Item class mixes in Traversable, which is probably responsible for ma=
king=20
this work TTW. It also gives you a bunch of other stuff that many Zope=20
classes need, like DAV support, copy support, ZMI tab support and securit=
y.=20
It doen't mix-in acquisition tho.

If you need support for acquistion machinery (including __of__ which crea=
tes=20
wrappers), then you need to mix-in Acquisition.Implicit. The SimpleItem c=
lass=20
mixes this and Persistence in for you (along with Item), so many Zope cla=
sses=20
derive form SimpleItem. You need Persistence to store instances of your c=
lass=20
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=
=20
objects are not stored properly in the ZODB.

-Casey

BTW: People will take you a lot more seriously on this list if you loose =
the=20
#{{{ ... #}}} crutches ;^)

On Wednesday 14 August 2002 05:29 pm, Joachim Schmitz wrote:
> Hi,
>=20
> in my AixtraTable product the newItem method is defined like this:
>=20
>     def newItem(self,key): #{{{
> =09"returns item"
> =09data =3D self._items
> =09if data.has_key(key):
> =09    return None
> =09else:
> =09    item =3D makeItem(key,self.FieldList)
> =09    data[key] =3D item
> =09    self.catalog_object(item)
> =09    return data[key]
>     #}}}
>=20
> where self._items is:
>=20
> =09self._items =3D OOBTree()
>=20
>=20
> and the makeItem-Class is:
>=20
> class makeItem(Item): #{{{
>     """
>     AixtraTable Item class
>=20
>     """
>     def __init__(self, key, fieldlist):
> =09self.id =3D key
> =09for f in fieldlist:
> =09    setattr(self,f,"")
>=20
> #}}}
>=20
> it only worked, when I inherited from Item, otherwise I could not acces=
s=20
> the items from the web, my guess is, cause they had no acquisition=20
> wrappers. Can I achieve the same with the __of__ magic and how ?
>=20
> you can download the product from=20
> http://www.zope.org/Members/perry/AixtraTable
>=20
>=20
>=20
>=20
> Mit freundlichen Gr=FC=DFen                              Joachim Schmit=
z
> --------------------------------------------------------------------
> AixtraWare Ingenieurb=FCro f=FCr Internetanwendungen
> H=FCsgenstr. 33a, D-52457 Aldenhoven
> Telefon: +49-2464-8851, FAX: +49-2464-905163
> --------------------------------------------------------------------
> Key fingerprint =3D DA10 CC82 62F8 1DBB 39A1  1EDC 725B 3317 A8D7 C3A6
> Keyserver: http://www.keyserver.net/en/
>=20
> _______________________________________________
> Zope-Dev maillist  -  Zope-Dev@zope.org
> http://lists.zope.org/mailman/listinfo/zope-dev
> **  No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope )
>=20