[Zope3-dev] ItemTypePrecondition and __setitem__

Peter Mayne PeterMayne at ap.spherion.com
Mon Sep 27 21:15:58 EDT 2004


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
-- 
Peter Mayne
Spherion Technology Solutions
Canberra, ACT, Australia
"You're given the form, but you have to write the sonnet yourself.
What you say is completely up to you." - Mrs. Whatsit



More information about the Zope3-dev mailing list