How do I link objects with containers?

(Part of ZopeInAnger)

class IItem(IContained):
  """The item interface.

  An item is contained in an item container.
  The containers constraint must use a string definition for
  the container interface because the interpreter did not know
  the definition at this point.
  """
  zope.app.container.constraints.containers('.IItemContainer')


class IItemContainer(IContainer):
  """The container for IItem and only IItem.
  """
  zope.app.container.contraints.contains(IItem)

The workings can be verified through the [ZMI]?.

Note: If you have a better implementation please edit this page

... --PjotrPrins?, Fri, 05 Jan 2007 04:55:09 -0800 reply

Can anyone tell me how this is supposed to be done? jukart modified my example (the original worked like the Richter examples with a wrapper object for containment), but the current version on the Wiki does not work for me. In fact the ZOPE source code says 'contained' should only be used for testing (contained.py). What is the right way of doing this so I can put it on the Wiki? See http://wiki.zope.org/zope3/HowDoILinkObjectsWithContainers

Pj.

... --PjotrPrins?, Fri, 05 Jan 2007 05:19:18 -0800 reply

Perhaps Zope3In30Minutes shows the proper way to achieve contraints?

Pj.

... --jukart, Fri, 05 Jan 2007 08:09:37 -0800 reply

Hm, I use this pattern everywhere in my applications. Both methods are doing the same as you do manually in the examples from Stephan's book.

containers(...) adds a ContainerTypesContraint? to the __parent__ attribute and contains adds __setitem__ with an ItemTypePrecondition?.

zope.app.container.contained.contained is not used in this example.

jukart

... --PjotrPrins?, Fri, 05 Jan 2007 10:39:42 -0800 reply

I replaced the __setitem__.ItemTypePrecondition? with contains and the result is that all objects get listed in URL object/+/. That is easy to verify and not what I expected.



( 97 subscribers )