[Zope3-dev] Re: Constraining where objects can be added

Philipp von Weitershausen philipp at weitershausen.de
Sun Jun 6 06:00:44 EDT 2004


Michał Węgrzynek wrote:
> IArtist.__parent__ = zs.Field(constraint = \ 
>     zcc.ContainerTypesConstraint(IArtistsContainer))

This will not work. Interfaces are not classes and they don't expose 
their fields and method definitions through the getattr protocol, but 
the getitem protocol. Alas, they don't support the setitem protocol, so 
there's no good way to dynamically change an interface like.

In analogy to the buddy demo [1], I suggest the following:

from zope.app.container.interfaces import IContained

class IArtistContained(IContained):
     __parent__ = zs.Field(
         constraint=zcc.ContainerTypesConstraint(IArtistsContainer))

...

class Artist(object):
     implements(IArtist, IArtistContained)

Philipp

[1] 
http://svn.zope.org/Zope3/trunk/src/buddydemo/interfaces.py?rev=13888&view=markup




More information about the Zope3-dev mailing list