[Zope3-Users] containment constraints via ZCML ?

Christophe Combelles ccomb at free.fr
Wed Jan 3 12:18:20 EST 2007


Hello and happy new year!

Actually I was just writing this message to ask a question, but in the meantime 
I found the solution. So I'm posting it anyway in case it helps.



I have two independant classes Foo and Bar, defined in two different modules.

In the beginning, I want Foo to be a container for Bar,
with symetric containment constraints (contains and containers)

But in the future, I will probably want Bar to be contained in something else, 
so I don't want to hardcode the containment constraints.

Is there a solution for this problem? Can I define containment constraint with ZCML?


The solution is just to define a generic IBarContainer, and to define 
constraints on it. Then to tell Foo to implement IBarContainer in ZCML.

class IFoo(IContainer):
   pass
class IBar(Interface):
   contains('dotted.path.to.IBarContainer')
class IBarContainer(IContainer):
   containers(IBar)

Then I must configure the class Foo to implement IBarContainer.
<zope:class class="Foo">
   <implements interface="IBarContainer">
</zope:class>





More information about the Zope3-users mailing list