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

Mikel Larreategi mlarreategi at codesyntax.com
Thu Apr 19 13:10:24 UTC 2007


Martin Aspeli(e)k dio:
>> 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.
>>
> 
> I really hate this view, and we're not using it any more in new views in
> Plone 3. 

Hi:

Well, everything inside CMFPlone/browser/* still depends on that
BrowserView (at least in the latest svn-Plone3), and I think that many
developers, like me, have written their BrowserViews in that way, just
because "Plone does it in that way".

For many of us, acquisition is "magic that works", so we don't really
care about it until we have problems (like with UnicodeErrors :)).

What I would like to see, is a common pattern to create BrowserView, not
having utils.BrowserView here and Five.browser.BrowserView there. It
seems that, following Martin's post, "the right way" is to inherit from
Five.browser.BrowserView. I will try to do that in my new BrowserViews
of my products for Plone 2.5, but perhaps deprecating (if possible)
CMFPlone.utils.BrowserView will be a good idea, to try to avoid
upgrading problems.

Just my two cents. Thanks for your great job with Plone3.


Mikel

-- 
Mikel Larreategi
mlarreategi at codesyntax.com

CodeSyntax
Azitaingo Industrialdea 3 K
E-20600 Eibar
Tel: (+34) 943 82 17 80





More information about the Product-Developers mailing list