[Zope3-Users] Getting view result from Python

Thierry Florac thierry.florac at onf.fr
Wed Jun 27 10:59:07 EDT 2007


Le mercredi 27 juin 2007 à 14:31 +0200, Christophe Combelles a écrit :
> Thierry Florac a écrit :
> >   Hi,
> > 
> > I'd like to get a view output from some Python code.
> > 
> > Actually, I don't have any problem if I use a page template with a
> > simple <tal:x content="structure context/@@viewname" /> expression and
> > return "self.template()" in Python.
> > But it should certainly be "cleaner" and less expensive to get view
> > output directly from Python code, which I don't actually manage to do...
> > 
> > So any advise to this probably simple problem would be welcome.
> 
> It depends on what you call a view,
> if this is a BrowserPage, you have a __call__ method that returns the output.
> so just call your view().
> If this is a BrowserView, there is no __call__ because a BrowserView is not 
> intended to be published as is. But you can have any method that returns HTML.
> If this is a Viewlet or a ContentProvider, there is a render method that returns 
> the output. (provided you first call the update method)

In fact it's a little bit more complicated...
What I have at first is a BrowserPage view, which is generally called
from a page template with "context/@@viewname" syntax, without any
problem.

But I need also to be able to get the same view output from a JSON call,
so that I can update a little bit of HTML code dynamically. I don't have
any problem when defining a template with the same syntax. But if I call
in python :

  view = zapi.getMultiAdapter((myContext,myRequest), Interface,
                              name=u'viewname')

I receive an error message :

  __init__() takes at least 3 arguments (1 given)

So zapi.getMultiAdapter creates the view, but how can I initialize it
with it's required parameters (context and request) ?

Thanks,

  Thierry Florac
-- 
  Chef de projet intranet/internet
  Office National des Forêts - Département Informatique
  2, Avenue de Saint-Mandé
  75570 PARIS Cedex 12
  Mél : thierry.florac at onf.fr
  Tél. : +33 01.40.19.59.64
  Fax. : +33 01.40.19.59.85



More information about the Zope3-users mailing list