[Zope] DTMLFile question

Jens Vagelpohl jens@zope.com
Wed, 14 Aug 2002 00:13:55 -0400


what is supposed to be "lazy" about re-instantiating those DTMLFiles every 
single time you call that "render" method??? i don't get it. the only "lazy"
  thing to do would be - as is the usual case - instantiate them once on 
startup.

if you don't have some really good reason why instantiating them once at 
class level is horribly bad then you should just stick with that.

jens


On Tuesday, August 13, 2002, at 03:15 , tomas@fabula.de wrote:

> Hi,
>
> I'm trying my hands on a Zope product. The different `views' are to be
> rendered with the help of dtml files, thus the class definition looks
> something like:
>
>   |class CMSResource( Traversable.Traversable, ...)
>   |    "Yadda, yadda"
>   |
>   |    ...
>   |
>   |    manage_main = DTMLFile("dtml/CMSResource/main",  globals())
>   |    manage_edit = DTMLFile("dtml/CMSResource/edit",  globals())
>   |
>   |    def __init__(self, resource):
>   |      ...
>
> So I can call on <a CMS resource>/manage_main and I get this view, etc.
>
> The dtml/CMSResource/ directory is of course a directory delivered
> with the product, it is ``part of'' the product, so to say.
>
> Now I'd like to be lazy and try to fetch the views `as needed',
> instead of declaring them as DTML class methods. Is that possible?
>
> What I have in mind is a method
>
>   |class CMSResource( Traversable.Traversable, ...)
>   |    "Yadda, yadda"
>   |
>   |    ...
>   |
>   |    def render(name, args):
>   |      my d = DTMLFile("dtml/CMSResource/" + name)
>   |      return <<call d with appropriate arguments>>
>
> enriched of course with error checking, caching of things and all that.
>
> Whatever I've tried failed because of --as I understand-- acquisition
> issues (the object returned by calling on d, like d(self, self.REQUEST)
> is expected to have an aq_parent and the like somewhere in the innards
> of Zope.
>
> My understanding of Zope is not as deep as to have an idea whether what
> I'm trying is possible (or rather: sensible).
>
> Any hints?
>
> Thanks,
> -- tomas
>