[z3-five] Adaptation in untrusted code
Martin Aspeli
optilude at gmx.net
Thu Nov 16 13:30:35 CET 2006
Chris Withers <chris <at> simplistix.co.uk> writes:
>
> Martin Aspeli wrote:
> >>> If your class derives from Products.Five.browser.BrowserView (I assume
> >>> you're on Zope 2 underneath, if not it's
> >>> zope.publisher.browser.BrowserView I think), you can override
> >>> __call__() to do whatever (using self.context and self.request as
> >>> appropriate).
> >> Dammit, why can't I just use a simple adapter
> >
> > You can. You just can't traverse to an adapter using foo/ <at> <at>
adapter_name as you
> > seem to want to do. You can either do it in a view class and return the
> > rendered result for use in TAL, or you can have a view on foo that does
> > whatever.
>
> Can you explain the difference between "do it in a view class and return
> the rendered result" and "have a view on foo that does whatever"?
I think what you want is this:
- a browser:page that is *the template you are working with*. This has a
template attribute to specify the page template and a class attribute that
specifies a view class
- this view class inherits (explicitly or implicitly) BrowserView, which just
means that it's an appropriate multi-adapter (it can get context and request
in its __init__() method).
- whatever logic you need in the template goes in methods on this view class,
and you use them in tal:content/replace/repeat expressions that are as simple
as possible
- you do your IRender() plain adapter lookups etc inside such methods and
return the rendered results for display in the template
You could register views for everything that is to be rendered (the second
option above), but as you identify you'd need to look it up each time (that's
the point).
Martin
More information about the z3-five
mailing list