Python method wrapping around DTML method
Hi, This has been buggering me for ages, and I've spent too many hours trying to figure it out already, so I'm resorting to the list for help. :) I have two functions, PlainFunc and DTMLFunc, where PlainFunc is Python method in a file system product, and DTMLFunc is a DTML Method in the ZODB. What I want to do is this: ZPublisher calls PlainFunc (publishes it) PlainFunc calls DTMLFunc in such a way that DTMLFunc gets everything it needs, e.g., namespace, but PlainFunc can do funky things to this namespace before-hand (like insert a few variables into it). In other words, I want a Python method to wrap around a DTML method. I've encountered many problems caused by the awkward calling conventions for DTML methods and the automagic switching between different calling conventions by the ZPublisher (isDocTemp; can I set that for a normal Python method?). Right now, I'm struggeling because I cannot get the namespace to be passed to PlainFunc, therefore PlainFunc cannot pass the namespace on to DTMLFunc. Any clues? Bye, -- Bjorn Stabell <mailto:bjorn@exoweb.net> bjorn@exoweb.net Tel +86 (10) 65918490
In most instances the REQUEST should be all you ever need. You can safely pass a REQUEST as second parameter to a DTML Method (most of the time). If you *really* want to be called with a namespace the preferred way is to derive your class from Shared.DC.Scripts.Bindings. Also see <http://www.zope.org/Members/lalo/scriptclass> HTH, Stefan On Fri, 3 Jan 2003, Bjorn Stabell wrote:
I have two functions, PlainFunc and DTMLFunc, where PlainFunc is Python method in a file system product, and DTMLFunc is a DTML Method in the ZODB.
What I want to do is this:
ZPublisher calls PlainFunc (publishes it) PlainFunc calls DTMLFunc
in such a way that DTMLFunc gets everything it needs, e.g., namespace, but PlainFunc can do funky things to this namespace before-hand (like insert a few variables into it). In other words, I want a Python method to wrap around a DTML method.
I've encountered many problems caused by the awkward calling conventions for DTML methods and the automagic switching between different calling conventions by the ZPublisher (isDocTemp; can I set that for a normal Python method?). Right now, I'm struggeling because I cannot get the namespace to be passed to PlainFunc, therefore PlainFunc cannot pass the namespace on to DTMLFunc. Any clues?
On Friday 03 January 2003 10:13 am, Bjorn Stabell wrote:
Right now, I'm struggeling because I cannot get the namespace to be passed to PlainFunc, therefore PlainFunc cannot pass the namespace on to DTMLFunc. Any clues?
There isnt one true namespace. You can create your own as easy as { }, and it will be as good as any other. If you want an authentic ZPublisher namespace then you need http://www.zope.org/Members/htrd/howto/FunctionTemplate -- Toby Dickenson http://www.geminidataloggers.com/people/tdickenson
Bjorn Stabell wrote:
in such a way that DTMLFunc gets everything it needs, e.g., namespace, but PlainFunc can do funky things to this namespace before-hand (like insert a few variables into it). In other words, I want a Python method to wrap around a DTML method.
It is pretty simple: class myProduct: # The dtml object DtmlFunc = HTMLFile('DtmlFunc', globals()) # to call it def PlainFunc(self): "Remember docstring" extraParameter = 'Some string' return self.DtmlFunc(self, self.REQUEST, extraParameter=extraParameter) regvards Max M
participants (4)
-
Bjorn Stabell -
maxm -
Stefan H. Holek -
Toby Dickenson