[z3-five] How to use bound variable view with getMultiAdapter was: How to use getMultiAdapter

Maciej Wisniowski maciej.wisniowski at coig.katowice.pl
Mon Mar 13 22:29:19 CET 2006


>You *must* use getView for view look up in Zope X3 3.0 and hence in Zope
>2.8. In Zope 3.2/2.9 and higher, getMultiAdapter is appriopriate and
>getView is deprecated.
>  
>
Thank you for clearing this. I've found that getMultiAdapter works in 2.9
but using it in 2.8 didn't cause errors like key error of something
so I though it is my mistake :)


Another question: Is this possible to use 'view' bound variable name
in view template used with getView or getMultiAdapter??  The problem
appears when view has both template and class, and template uses
'view.xxx' expression.

I tried this with ViewsTutorial from Five.
I've added one function to democontent.py -> DemoContent class:

def checkFolder(self):
        """ docstring
        """
        from zope.app import zapi
        from zope.interface import Interface
        viewx = zapi.getMultiAdapter((self.bear, self.REQUEST),
                          Interface, 'overview2.html')
        return viewx()

I've created 'Folder' with id: 'bear' and put 'Five Demo Content' object
with id: 'demo' inside.
When I call http://localhost:8080/bear/demo/checkFolder

the result is:

Error Type: KeyError
Error Value: 'view'


I tried to change checkFolder function, and now it works but it seems
to be odd for me:

def checkFolder(self):
        """ docstring
        """
        from zope.app import zapi
        from zope.interface import Interface
        from browser import Overview
        viewx = zapi.getMultiAdapter((self.bear, self.REQUEST),
                          Interface, 'overview2.html')      
        view = Overview()
        return viewx.__of__(self)()

Any clues? What is the correct way of doing such things?

-- 
Maciej Wisniowski


More information about the z3-five mailing list