[ZPT] ZPT for manage_addForm

Michael R. Bernstein mbernstein@codeit.com
27 Feb 2002 15:05:22 -0800


On Wed, 2002-02-27 at 13:52, Evan Simpson wrote:
> Michael R. Bernstein wrote:
> > Hmm. So shouldn't it be possible for the PageTemplateFile class __init__
> > to assign __name__ based on the module attribute that it's being
> > assigned to, instead of based on the file name? This would seem to be
> > more consistent with the class attribute __name__ assignment.
> 
> Nope.  The PageTemplateFile's __init__ gets called before the local 
> variable is ever bound.  The only reason that the class attribute thing 
> is possible is that the work is done by scanning the class of which the 
> PTF is an attribute.

Hmm. Ok.

> [snip] if you've got a bunch of 
> module-level PTFs I would advise something like:
> 
> g = globals()
> for name in ('foo', 'bar', 'etc'):
>    g[name] = PageTemplateFile('www/' + name, g, __name__=name)

<blinks>

Evan, that's pretty slick, thanks.

Does any of Zope's core use this pattern?

Michael.
-- 
---------------------------------------------------
| Michael Bernstein   http://michaelbernstein.com |
|                                                 |
| CodeIt Computing    http://codeit.com           |
---------------------------------------------------