Browser views: inherit from object or BrowserView from Five/Plone

Maurits van Rees m.van.rees at zestsoftware.nl
Wed Apr 18 13:51:35 UTC 2007


Hi,

I was wondering what the best approach to BrowserViews is for 3rd
party developers of Plone Products.

I saw some discussion on lists, but could not find a definitive
answer, if there is one.

The main differences I am aware of are the security and the use of
context, both of which have to do with Acquisition.


Inherit from object
-------------------

    class MyView(object):
        def __init__(self, context, request):
            self.context = context
            self.request = request

The view is not Acquisition wrapped, which means that any permission
you set in the configure.zcml is ignored and everyone can see this
view, right?

You define your own __init__() so you can handle the context anyway you
please.


Inherit from Five
-----------------

    from Products.Five.browser import BrowserView
    class MyView(BrowserView):

The view is Acquisition wrapped, so Zope security kicks in, which is
probably good.

If you do not overwrite the __init__() you can use the context with
self.context.


Inherit from Plone
------------------

    from Products.CMFPlone import utils
    class MyView(utils.BrowserView):

Acquisition wrapped, same as Five.

But in the __init__() of this BrowserView there is the line:

    self.context = [context]

So you cannot use self.context in your code like you would do in the
other cases, but you have to use this:

    context = utils.context(self)

This is the only thing that is different from the Five BrowserView.
All the browser views in CMFPlone/browser use this.


Should developers of Plone products in the collective care about this?
Is it better that everyone uses this BrowserView from CMFPlone.utils?


I am still looking at product compatibility with Plone 2.5.  Would the
recommendation be different with Plone 3.0?

Thanks,

-- 
Maurits van Rees | http://maurits.vanrees.org/ [NL]
            Work | http://zestsoftware.nl/
"Do not worry about your difficulties in computers,
 I can assure you mine are still greater."





More information about the Product-Developers mailing list