[Zope-dev] More almost __call__ ;-)

Jim Fulton jim@digicool.com
Fri, 13 Oct 2000 11:33:47 -0400


Shane Hathaway wrote:
> 
> Jim Fulton wrote:
> >
> > Chris Withers wrote:
> > >
> > > Toby Dickenson wrote:
> > > > <http://www.zope.org/Members/htrd/howto/FunctionTemplate>
> > > >
> > > > you would use....
> > > >
> > > >     def a_method(self,md):
> > > >         do_stuff_with(md['param1'],md['param2'])
> > > >     a_method = FunctionTemplate(a_method)
> > >
> > > That looks like it'll do the trick... I wonder if there's any way you
> > > can role it up into a Product so that I don't need to have
> > > FunctionTemplate.py in each folder of a product that needs to use it?
> >
> > Is it *really* the case that you often want to method to be called directly
> > via the Web *and* and from DTML?  This doesn't seem right to me.
> 
> As I understand it, that's not the issue.  Chris wants to receive the
> DTML namespace implicitly.
> 
> > In any case, if you *just* want to get your function to be
> > called from DTML (and your class is an extension class), you can give
> > it the isDocTemp attribute like so:
> >
> >   class MyClass(.... include some extension class ...):
> >
> >     some_methodisDocTemp=1
> >     def some_method(trueself, self, REQUEST, RESPONSE=None):
> >         ....
> 
> That's a good idea, I wish I'd thought of it. :-)
> 
> However, the new calling convention (__render_with_namespace__, or
> something like that) might break "isDocTemp" code.

I thought of that, but I don't think so. There are obviously 
enough people using the isDocTemp thing that we'll probably need to
keep supporting it.  The use of a separate render method won't be
convenient for iplementing simple methods. Not that that is necessarily
that critical.

> > Note that if you get called from the web, RESPONSE will
> > not be none. This is a handy way to decide if you
> > are called from the web or as a sub-template. Of course,
> > someone could pass a non-None RESPONSE argument directly.
> 
> This convention is helpful but not at all documented, so products (ZWiki
> is a good example) often break this convention.

Which convention? The passing of arguments with names meaningful to
the publisher is certainly well documented.

Jim

--
Jim Fulton           mailto:jim@digicool.com   Python Powered!        
Technical Director   (888) 344-4332            http://www.python.org  
Digital Creations    http://www.digicool.com   http://www.zope.org    

Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
address may not be added to any commercial mail list with out my
permission.  Violation of my privacy with advertising or SPAM will
result in a suit for a MINIMUM of $500 damages/incident, $1500 for
repeats.