[Zope3-dev] IAdding

Jim Fulton jim at zope.com
Fri Nov 12 08:59:20 EST 2004


Shane Hathaway wrote:
> Today I created a content object that implemented IReadContainer but not
> IContentContainer.  @@contents.html failed for this object because the
> standard IAdding implementation is registered only for IContentContainer
> (contents.pt broke when trying to traverse through "/@@+".)

That's not quite right.  For better or worse, IAdding views are generally
registered on a case-by-case basis.  This is normally done using the
containerViews ZCML directive that is, essentially, a macro that configures
contents, adding, and/or index views.  The reason that adding views are
registered on a case-by-case basis is:

1. Historical: it used to be that each container needed it's own adding view,
    because each adding view needed it's own adding menu. We've gotten away from
    this.

2. Explicit is better than implicit: we didn't want to assume that every container
    would use the adding framework. (You might want to use a different mechanism to
    add ites, for example.)

As a side note, I'd like to refactor this a bit one of these days so that
menu items are actually registered for the container, rather than for the
adding. This will make add-menu filtering much cheapter. (If I remember correctly.
creating the adding menu is the most expensive part of rendering a management page.)

 >  So I looked
> into creating a do-nothing IAdding implementation that would satisfy the
> demands of contents.pt, but then I discovered that contents.pt relies on
> methods not documented in any interface, such as "namesAccepted" and
> "addingInfo".  I finally figured out that if I implement IContentContainer
> as well, contents.pt works.
> 
> So I have a few questions:
> 
> - Should those undocumented methods be declared in the IAdding interface? 
> I'm happy to add them if that's the right thing to do.

Absolutely. This was a sorry oversight. Thanks.

> - Is it really necessary to implement IContentContainer? 

No.  It *is* necessary to create an adding view for whatever container
you use.  You *will* need to implement IWriteContainer. (Adding to a read-only
container doesn't make any sense.)

 > This container
> has fixed contents; it's actually only a container so that I can reuse
> "@@contents.html".  No one will ever add or remove anything.

Then why do need an adding.  If contents *requires* an adding, then that's
a bug in contents that we ought to fix.

> - Should there be a default do-nothing IAdding implementation?  Or, in
> other words, should page templates always expect "@@+" to be traversable?

The contents view should not generate links to @@+ if there is no adding.

Jim

-- 
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