[Zope] getView/getMultiAdapter and 'global name 'view' is not defined'

Maciej Wisniowski maciej.wisniowski at coig.katowice.pl
Thu Mar 9 08:24:12 EST 2006


Hello

I have a view defined for my content class that uses both view template 
and view class.
In zcml it looks like:

<browser:page
      for=".xyz.IXyz"
      class=".browser.xyz_view.XyzView"
      template="xyz_body.pt"
      name="render"
      permission="zope2.View"
  />

in 'xyz_body.pt' I have statements like:

------------------------------------------------------------------------
<div tal:define="xyz_dict python: view.xyz_function();">
------------------------------------------------------------------------

where 'xyz_function' is defined in 'XyzView' class.

Calling @@render from another view or directly by
URL in browser works, but when I'm using:
------------------------------------------------------------------------
rnd = zapi.getMultiAdapter((self.xyz_instance, self.REQUEST), Interface, 
name='render')
------------------------------------------------------------------------
or

------------------------------------------------------------------------
rnd = getView(self.xyz_instance, 'render', self.REQUEST)
------------------------------------------------------------------------

where 'xyz_instance' is a instance of content class (in ZODB)
that implements IXyz I get:

------------------------------------------------------------------------
NameError   
Exception Value    global name 'view' is not defined   

Traceback (innermost last):
Module ZPublisher.Publish, line 114, in publish
Module ZPublisher.mapply, line 88, in mapply
Module ZPublisher.Publish, line 40, in call_object
Module Products.XyzBase.XyzBase line 178, in save_form
Module Products.XyzModule.xyz_emailer, line 51, in save_data
Module Products.Five.browser.metaconfigure, line 403, in __call__
Module Shared.DC.Scripts.Bindings, line 311, in __call__
Module Shared.DC.Scripts.Bindings, line 348, in _bindAndExec
Module Products.PageTemplates.PageTemplateFile, line 110, in _exec
Module Products.PageTemplates.PageTemplate, line 104, in pt_render
<ImplicitAcquirerWrapper object at 0xb351b80c>
Module TAL.TALInterpreter, line 238, in __call__
Module TAL.TALInterpreter, line 281, in interpret
Module TAL.TALInterpreter, line 507, in do_setLocal_tal
Module Products.PageTemplates.TALES, line 221, in evaluate
URL: index
Line 1, Column 0
Expression: <PythonExpr view.xyz_function()>
Names:

<...cutted here...>

Module Products.PageTemplates.PythonExpr, line 70, in __call__
__traceback_info__: view.xyz_function()
Module <string>, line 2, in f
NameError: global name 'view' is not defined
------------------------------------------------------------------------

How can I call such view from python code?
I'm using Zope 2.9.1.
In Zope 2.8.5 it was possible to use
context.xyz_function() instead of view.xyz_function() but now it causes
errors.

One more question - is it necessary to inherit from
Products.Five.BrowserView in view class?
I think that I've found somwhere that ZCML itself puts BrowserView
into base clases of view class...?

-- 
Maciej Wisniowski



More information about the Zope mailing list