[ZPT] ZPT for manage_addForm

Evan Simpson evan@zope.com
Wed, 27 Feb 2002 16:52:07 -0500


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.

You *could* write a ModuleInit function that scanned your module's 
globals for PTFs and set __name__, but 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)

Cheers,

Evan @ Zope