[Zope3-dev] Re: wading through zcml...

Philipp von Weitershausen philipp at weitershausen.de
Thu Nov 16 11:38:28 EST 2006


Chris Withers wrote:
> What's the difference between zope:view, browser:view, browser:page and 
> browser:viewlet?

It's a mess. Here's the gist:


zope:adapter
   Registers an adapter and optionally applies a permission to the
   interface that you're adapting to, e.g.::

     <adapter
         factory="..."
         provides="...IFoo"
         permission="foo.permission"
         />

   will cause the adapter's attributes as specified in IFoo to be
   protected with the 'foo.permission' (everything else will not be
   accessible).

zope:view
   Registers an adapter and optionally applies a permission to all
   "allowed_attirbutes" or the "allowed_interface" if the "permission"
   parameter is given.

browser:view
   Like zope:view, except:

     * the request type (second adapted object) defaults to
       IBrowserDefaultLayer

     * the "permission" always applies to 'publishTraverse',
       'browserDefault' and '__call__' attributes, in addition to the
       optionally specified "allowed_attributes" or "allowed_interface"

     * support sub-pages that will be available as
       obj/@@viewname/subpage.

   Note: browser:view always creates new classes on the fly.

browser:page
   Registers an adapter where the second adapted object defaults to
   IBrowserDefaltLayer. Always creates a new class on the fly and
   mixes in functionality that makes the adapter a *publishable view*.

browser:viewlet
   Registers an adapter for (context, request, view). It's out of
   scope here, I think.


I wish we could clean this up some day, but all my earlier attempts to 
walk this direction have mostly been shot down because people apparently 
hate deprecation warnings.

I'm sick of ZCML and its magic and its inconsistency. The typing and the 
pointy brackets I could live with... ME GROK SMASH ZCML.

> I'm trying to register an adapter in such a way that I can do the 
> following in a page template:
> 
> <p tal:content="structure someobj/@@render"/>
> 
> Which of the myriad flavours of view registration should I be using?

Inherit from BrowserView and use either a simple <adapter /> or a <view 
/> or a <browser:view /> directive to register it. Note that this thing 
won't be publishable via the URL then (which is probably what you want).

If you want it to be published, inherit from BrowserPage and use 
<browser:page />

> Also, why, when zope:view is described as a synonym for zope:adapter, 
> does zope:view support an allowed_attributes attribute, while 
> zope:adapter does not?

zope:adapter assumes the "provides" interface as the "allowed_interface".


-- 
http://worldcookery.com -- Professional Zope documentation and training


More information about the Zope3-dev mailing list