Re: [Zope3-Users] Weird behaviour of ViewPageTemplateFile()

2008-04-10 Thread Martin J. Laubach

 class MyView(BrowserView):
 def __call__(self):
 pt = ViewPageTemplateFile('empty.pt')
 data = pt()
 return data


try this:

pt = ViewPageTemplateFile('empty.pt')
return pt(self)


  Nope, same result:

AttributeError: 'str' object has no attribute 'other'

  Cheers,

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


Re: [Zope3-Users] Weird behaviour of ViewPageTemplateFile()

2008-04-10 Thread Martin J . Laubach
 Well, it's called a *View*PageTemplate for a reason :-) If the  
file is

 really empty and you do not need to pass any arguments to it (view,
 context, request), use a plain PageTemplateFile

  No, of course it's not empty and it needs the parameters. Nor does
the view really look as trivial as the example. That was the minimal
test case for the behaviour I could come up with.

   I still don't understand how the naming / storage of a variable
holding the page template can influence the page rendering process.

  Cheers,

mjl

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


Re: [Zope3-Users] Weird behaviour of ViewPageTemplateFile()

2008-04-10 Thread Martin J . Laubach

 ViewPageTemplate must be in the view's namespace, and it magically
 fishes out the view, view's context and request, and makes them
 available in the TAL namespace.

  Ah, so there _IS_ heavy magic involved here. Thanks for
clarifying that, I was already doubting my sanity!

  Cheers,

mjl



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


Re: [Zope3-Users] Weird behaviour of ViewPageTemplateFile()

2008-04-10 Thread Martin J. Laubach

 ViewPageTemplate must be in the view's namespace, and it magically
 fishes out the view, view's context and request, and makes them
 available in the TAL namespace.

 Ah, so there _IS_ heavy magic involved here. Thanks for
clarifying that, I was already doubting my sanity!



This is exactly the same magic that methods use. ViewPageTemplateFiles
are, like functions, meant to be used as methods and to be bound to
instances.


  Okay, then this leads me to the strong suspicion that what I'm
(mis)using ViewPageTemplateFiles for is the wrong way to attack
the problem.

  What I'm doing is something along the lines of

class MyView(BrowserView):
def __call__(self):
	pagename = somehow_compute_new_page_name(self.request,  
self.context)

pt = ViewPageTemplateFile(pagename)
return pt.__get__(self, self.__class__)()

  but quite obviously, that's not how it's meant to be used, is it...
Perhaps I need a radically different approach?

  Cheers,

mjl

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