[Zope] DTMLFile question -- half solution

Max M maxm@mxm.dk
Thu, 15 Aug 2002 14:57:26 +0200


tomas@fabula.de wrote:

>As a reminder: My aim was to use DTML methods on a product without
>`declaring' them `by hand' in the product class definition. 
>
This would probably work, but beware of security issues

def __getattr__(self, attr):
    attr = HTMLFile('www/%s' % attr, globals())
    return attr(self, self.REQUEST)
    
But I am worried that it might be too slow, as it compiles the dtml for every call.
So you could cache it in the object:

def __getattr__(self, attr):
    if not self._dynPages.has_key(attr):
        self._dynPages[attr] = HTMLFile('www/%s' % attr, globals())
    return self._dynPages[attr](self, self.REQUEST)


That should be more efficient.



regards Max M

    "klaatu verata niktu"