I want to override DTMLFile from Globals in my own special product. I managed to do this:: class PeterDTMLFile(DTMLFile): def foo(self): return "works" Then from somewhere else I do:: manage_edit = PeterDTMLFile('dtml/manage_edit', globals()) This works but doing <dtml-var foo> raises a KeyError. I've looked at Localizer and how they override DTMLFile's __init__ and _exec method. But if I try to do:: # pointless inheritance hack but for testing class PeterDTMLFile(DTMLFile): def __init__(self, name, _prefix=None, **kw): apply(DTMLFile.inheritedAttribute('__init__'), (self, name, _prefix), kw) Which in effect is pretty pointless, I get the following error when trying my manage_edit:: Traceback (innermost last): Module ZPublisher.Publish, line 98, in publish Module ZPublisher.mapply, line 62, in mapply AttributeError: 'None' object has no attribute 'co_varnames' So, can anybody tell me how to override the DTMLFile class (and possible also the PageTemplateFile) Grateful, Peter
Hi, You can have a look at our SkinMI product in http://sourceforge.net/projects/ingeniweb which overrides DTMLFile - but maybe not in the way you want to do. Anyway, it may give you some clues... Regards, P.-J. Grizel -- Ingeniweb www.ingeniweb.com
I want to override DTMLFile from Globals in my own special product. I managed to do this::
class PeterDTMLFile(DTMLFile): def foo(self): return "works"
Then from somewhere else I do::
manage_edit = PeterDTMLFile('dtml/manage_edit', globals())
This works but doing <dtml-var foo> raises a KeyError.
I've looked at Localizer and how they override DTMLFile's __init__ and _exec method. But if I try to do::
# pointless inheritance hack but for testing class PeterDTMLFile(DTMLFile): def __init__(self, name, _prefix=None, **kw): apply(DTMLFile.inheritedAttribute('__init__'), (self, name, _prefix), kw)
Which in effect is pretty pointless, I get the following error when trying my manage_edit::
Traceback (innermost last): Module ZPublisher.Publish, line 98, in publish Module ZPublisher.mapply, line 62, in mapply AttributeError: 'None' object has no attribute 'co_varnames'
So, can anybody tell me how to override the DTMLFile class (and possible also the PageTemplateFile)
Grateful, Peter
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
I got it! class CTDTMLFile(DTMLFile): def __init__(self, name, _prefix=None, **kw): " doc string " <do whatever needs to be done> apply(DTMLFile.__init__, (self, name, _prefix), kw) def _exec(self, bound_data, args, kw): " doc string " zope = bound_data['context'] <do whatever needs to be done> return apply(DTMLFile._exec, (self, bound_data, args, kw)) The aim of this hack is for me to be able to control whether DTML Methods should be run from the filesystem or as DTML Method objects. This will hopefully lead to a all-purpose product for whatever reasons one might have. At 12:57 2003-05-23 +0100, you wrote:
I want to override DTMLFile from Globals in my own special product. I managed to do this::
class PeterDTMLFile(DTMLFile): def foo(self): return "works"
Then from somewhere else I do::
manage_edit = PeterDTMLFile('dtml/manage_edit', globals())
This works but doing <dtml-var foo> raises a KeyError.
I've looked at Localizer and how they override DTMLFile's __init__ and _exec method. But if I try to do::
# pointless inheritance hack but for testing class PeterDTMLFile(DTMLFile): def __init__(self, name, _prefix=None, **kw): apply(DTMLFile.inheritedAttribute('__init__'), (self, name, _prefix), kw)
Which in effect is pretty pointless, I get the following error when trying my manage_edit::
Traceback (innermost last): Module ZPublisher.Publish, line 98, in publish Module ZPublisher.mapply, line 62, in mapply AttributeError: 'None' object has no attribute 'co_varnames'
So, can anybody tell me how to override the DTMLFile class (and possible also the PageTemplateFile)
Grateful, Peter
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Peter Bengtsson wrote:
I got it!
class CTDTMLFile(DTMLFile): def __init__(self, name, _prefix=None, **kw): " doc string " <do whatever needs to be done> apply(DTMLFile.__init__, (self, name, _prefix), kw)
def _exec(self, bound_data, args, kw): " doc string " zope = bound_data['context'] <do whatever needs to be done> return apply(DTMLFile._exec, (self, bound_data, args, kw))
The aim of this hack is for me to be able to control whether DTML Methods should be run from the filesystem or as DTML Method objects. This will hopefully lead to a all-purpose product for whatever reasons one might have.
Cool, but what doe sit do? I suspect the "zope = bound_data['context']" is to get the current namespace for the "<do whatever needs to be done>" part in "_exec"? What is the bound_data anyway? And what is prefix? Johan Carlsson
At 10:34 2003-05-24 +0200, Johan Carlsson wrote:
Peter Bengtsson wrote:
I got it! class CTDTMLFile(DTMLFile): def __init__(self, name, _prefix=None, **kw): " doc string " <do whatever needs to be done> apply(DTMLFile.__init__, (self, name, _prefix), kw) def _exec(self, bound_data, args, kw): " doc string " zope = bound_data['context'] <do whatever needs to be done> return apply(DTMLFile._exec, (self, bound_data, args, kw))
The aim of this hack is for me to be able to control whether DTML Methods should be run from the filesystem or as DTML Method objects. This will hopefully lead to a all-purpose product for whatever reasons one might have.
Cool, but what doe sit do?
Nothing. More important: What _can_ it do. What I do with it is to keep track of which templates use the DTMLFile class.
I suspect the "zope = bound_data['context']" is to get the current namespace for the "<do whatever needs to be done>" part in "_exec"?
What is the bound_data anyway? And what is prefix?
Yes, bound_data['context'] == self _prefix is what is sucked up when globals() is called.
Johan Carlsson
participants (3)
-
Johan Carlsson -
Peter Bengtsson -
Pierre-Julien Grizel