On Wed, Jan 24, 2007 at 08:31:52PM +0100, Dominique Lederer wrote:
> can someone explain me please when to use browser:view and when browser:page?

As far as I understand, the intended use of <browser:page> is to define
views that are accessible to browsers by using URLs.

The intended use of <browser:view> is to define helper views that are
accessible to page templates in TALES expressions like
tal:attributes="href context/@@absolute_url".

I might be wrong.

> and when would i inherit a View Class from zope.publisher.BrowserView
> and when from zope.publisher.BrowserPage, and why do i need them when
> i could just inherit from object without any errors?

A browser page must implement IBrowserPublisher if you want it to be
accessible from the outside.  BrowserPage does that.  The <browser:page>
also does that, but in a different way.  The directive does deep magic
-- it constructs a new class on the fly that implements
IBrowserPublisher and inherits from the view class you've specified.  It
can also provide a 'index' attribute and a default implementation of
__call__.

BrowserView only gives you a useful __init__.  If you inherit directly
from object, you'll have to define __init__ by yourself.

Looking at the code I see that BrowserView also gives you a __parent__
property that is used by the standard Zope 3 security policy.  I do not
think it is all that important, as usually views in Zope3-land are not
security proxied.

Magic is going out of fashion in Zope3-land.  In my personal opinion
the best practice for Zope 3 views is to follow this pattern:

    class MyView(BrowserPage):
        adapts(ISomeContext, IBrowserRequest)

        template = ViewPageTemplateFile('...')

        def __call__(self):
            # do form processing, if any
            return self.template()

and then register it with <browser:page>.

> and what means the @@ or ++view++ if i can access a view(page?) without that?

Yes.  The @@ (which is a shorter spelling of ++view++) is a way to
resolve ambiguities when you have both a view named 'foo.html' and an
object in a container also named 'foo.html'.  When there are no
ambiguities, the @@ is optional.

> i am really confused :)
> please help.

I hope I've made some things clearer.

I also hope that the big Zope 3 gurus will correct all the mistakes I've
made in the above.  I'm sure there must be at least one or two.

Marius Gedminas
-- 
No sane person should use frame buffers if they have the choice.
        -- Linus Torvalds on lkml

Attachment: signature.asc
Description: Digital signature

_______________________________________________
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users

Reply via email to