[Zope3-dev] ItemTypePrecondition and __setitem__

Jim Fulton jim at zope.com
Tue Sep 28 05:45:28 EDT 2004


See the section on containers toward the end of
http://dev.zope.org/Zope3/programmers_tutorial.pdf.

Jim

Peter Mayne wrote:
> I have a simple MessageBoard-like product where a container has 
> instances of a single type. I'd like to restrict it so the container 
> only has instances of that type in the Add box.
> 
> In (the latest version of) the developer's book, IMessageBoard does this 
> by defining __setitem__ and setting the precondition 
> ItemTypePrecondition(IMessage). If I do this in my code, my container 
> contents page only allows me to add my type, which is exactly what I want.
> 
> However, curiosity leads me on.
> 
> When I look at bugtracker, it doesn't do that. Instead, there is an 
> interface called IBugContainer which is implemented by BugTracker. This 
> works for BugTracker's Add box, but when I try this, I get all of the 
> other types showing in my container's Add box.
> 
> Furthermore, the MessageBoard also has an IMessageContainer interface, 
> which is implemented by Message, and this also works correctly.
> 
> The only obvious difference I can see is that my contained type 
> implementation is declared as "class DataElement(Persistent, Contained)" 
> whereas Message and Bug are "class Message(BTreeContainer)", but I don't 
>  see how that changes things.
> 
> Why does the IMessageContainer/IBugContainer form of precondition work 
> for Message/Bug, but not for my type? Why does the IMessageBoard 
> interface do this directly, rather than letting MessageBoard implement 
> an IMessageContainer style interface?
> 
> Thanks.
> 
> PJDM


-- 
Jim Fulton           mailto:jim at zope.com       Python Powered!
CTO                  (540) 361-1714            http://www.python.org
Zope Corporation     http://www.zope.com       http://www.zope.org



More information about the Zope3-dev mailing list