[Zope3-Users] question about a constraint conflict

Christophe Combelles ccomb at free.fr
Sun Jan 7 08:10:20 EST 2007


FB a écrit :
> Hi,
> 
> On Sat, Jan 06, 2007 at 01:35:35AM +0100, Christophe Combelles wrote:
>> Hello
>>
>> I define the following interfaces:
>>
>> class IFoo(Interface):
>>   pass
>> class IBar(Interface):
>>   pass
>>
>> class IFooContainer(IContainer):
>>   contains(IFoo)
>> class IBarContainer(IContainer):
>>   contains(IBar)
>>
>> Then I would like to configure a class Test to to be both a FooContainer and a BarContainer:
>>
>> <zope:class class=".test.Test">
>>     <implements interface=".interfaces.IFooContainer" />
>>     <implements interface=".interfaces.IBarContainer" />
>> </zope:class>
>>
>> Then I define AddMenuEntries for Foo and Bar implementations.
>>
>> This does not work and as a result I only get Foo in the Add Menu. If I switch the two 
>> implements zcml directives, I obviously get only Bar.
>>
>> Is there a solution to configure a class to be both a FooContainer and a BarContainer with 
>> constraintment ? (I would like to avoid dependencies between Foo, Bar and Test.)
> 
> IHMO you should use the containers()-statement on IFoo and IBar instead of
> contains() on their containers. Even if the contains-constraints of
> IFooContainer and IBarContainer would be merged somehow on the Test-class,
> it wouldn't behave as you expect:
> 
> The contains()-statement can be read as "mustn't contain anything but...".
> Mixing those two constraints depending on two different contained interfaces
> would result in "Can't contain anything.".
> This makes sense, if you have classes, relying on self.values() returning *nothing*
> but objects implementing the given interface.

thanks,

I understand there is an inconsistency between these two interfaces, and this is 
not a correct solution.
But using just containers() on content objects doesn't prevent their containers 
from displaying everything in the Add Menu.
It just prevents from adding these objects in other containers.

Is there a way to restrict the Add Menu list of a specific container?

(actually maybe I shouldn't bother with this, since the zmi and the addmenu is 
not an end solution for an application?).


Christophe


More information about the Zope3-users mailing list