[Zope-CMF] Extending FTI.isConstructionAllowed

Wichert Akkerman wichert at wiggy.net
Tue Jun 2 08:47:40 EDT 2009


Previously yuppie wrote:
> Wichert Akkerman wrote:
> > Previously yuppie wrote:
> >> A CMF specific precondition would look up type restrictions in the fti 
> >> of the container.
> >>
> >> checkFactory and checkObject are quite similar to isConstructionAllowed. 
> >> I think we should reimplement this based on zope.container before we 
> >> start adding new features.
> > 
> > I looked at the code in zope.container and frankly it scared me. I found
> > the documentation and code hard to follow, and the usage of
> > sys._getframe() made me drop the idea of using it.
> 
> That scary code is used for supporting 'contains' declarations in the 
> interface. I don't propose to write something similar for CMF.
> 
> AFAICS it is sufficient to set __setattr__.precondition directly for 
> supporting checkObject.
> 
> A precondition that just checks allowType would look like this:
> 
> 
>    class PortalTypePrecondition:
> 
>        def __call__(self, container, name, obj):
> 
>            ti = container.getTypeInfo()
>            if ti is None:
>                return
> 
>            if not ti.allowType(obj.getPortalTypeName()):
>                raise ValueError(u'Disallowed subobject type: %s' % 
> type_name)

That assumes the object has already been constructed and you're only
testing constraints for adding the instance to the container. Our use
case is different: we are testing at a point where construction has
not happened yet.

Wichert.

-- 
Wichert Akkerman <wichert at wiggy.net>    It is simple to make things.
http://www.wiggy.net/                   It is hard to make things simple.


More information about the Zope-CMF mailing list