[Zope3-dev] Constraining where objects can be added
Michał Węgrzynek
Michal.Wegrzynek at litex.pl
Sat Jun 5 12:39:42 EDT 2004
Hello!
I've got some problems with constraining where my content objects can be
added. The example in the zope book
(http://dev.zope.org/Wikis/DevSite/Projects/ComponentArchitecture/Zope3Book/contentobject.html)
I used doesn't work also.
Is this a bug, or the apis changed?
Here is my code:
8<-----------------------------------------------------------------------------
# -*- encoding: UTF-8 -*-
__doc__ = """An IArtist interface"""
#------------------------------------------------------------------------------
import zope.interface as zi
import zope.schema as zs
import zope.app.container.interfaces as zci
import zope.app.container.constraints as zcc
#------------------------------------------------------------------------------
class IArtist(zi.Interface):
name = zs.TextLine(title = u"Name",
description = u"Artist's name",
required = True,
default = u"New")
description = zs.Text(title = u"Description",
description = u"Few words about artist",
default = u"")
picture = zs.Bytes(title = u"Picture",
description = u"Artist's picture")
homepage = zs.TextLine(title = u"Homepage",
description = u"Artist's homepage",
required = False,
default = u"")
#------------------------------------------------------------------------------
class IArtistsContainer(zci.IContainer):
def __setitem__(name, object):
"""Adds a IArtistsContainer object."""
__setitem__.precondition = zcc.ItemTypePrecondition(IArtist)
#------------------------------------------------------------------------------
IArtist.__parent__ = zs.Field(constraint = \
zcc.ContainerTypesConstraint(IArtistsContainer)) # <-- This line
# supposed to allow adding artist only in ArtistsContainer
#------------------------------------------------------------------------------
Thanks for help in advance,
Michał
More information about the Zope3-dev
mailing list