Le mercredi 27 juin 2007 à 20:17 +0300, Marius Gedminas a écrit :
> On Wed, Jun 27, 2007 at 04:59:07PM +0200, Thierry Florac wrote:
> > Le mercredi 27 juin 2007 à 14:31 +0200, Christophe Combelles a écrit :
> > > Thierry Florac a écrit :
> > > > 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...
> > > 
> > > 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 you use getMultiAdapter to get the view, all these differences are
> hidden and you can call the view to get its output.
> 
> > > If this is a Viewlet or a ContentProvider, there is a render method that 
> > > returns 
> > > the output. (provided you first call the update method)
> 
> Then it's not really a view, is it?  ;-)
> 
> > 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')
> 
> This should work.  You don't have to pass Interface explicitly, by the
> way, view = getMultiAdapter((context, request), name='...') will work as
> well.
> 
> > I receive an error message :
> > 
> >   __init__() takes at least 3 arguments (1 given)
> 
> I don't believe you :-)
> 
> Can you show the full traceback?  getMultiAdapter definitely passes the
> context tuple to the adapter's __init__.  There must be some other piece
> of code that fails for you.
> 
> > So zapi.getMultiAdapter creates the view, but how can I initialize it
> > with it's required parameters (context and request) ?
> 
> getMultiAdapter does that.  I speak from personal experience.

Whoops !
I'm really sorry but I think I made a stupid mistake in my
zapi.getMultiAdapter() call, because I used a "custom" request as
parameter instead of the initial request I received in my JSON
MethodPublisher subclass ; that's probably because of several tests I
made to get things working as I need... :-(

Really sorry again, but now it works perfectly...

  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 : [EMAIL PROTECTED]
  Tél. : +33 01.40.19.59.64
  Fax. : +33 01.40.19.59.85

_______________________________________________
Zope3-users mailing list
Zope3-users@zope.org
http://mail.zope.org/mailman/listinfo/zope3-users

Reply via email to