Name lookup emulation with a Product
Hi, I'd like to perform a name lookup inside a product, relying on acquisition, property and REQUEST lookups. In fact, I want to use the DTML Reference / Table 7 schema to look-up variables. I know how to perform REQUEST lookups. I know how to perform object properties lookups. I know how to perform acquisition lookups. I could write a method of my own to try to imitate the Zope process, but is there an already existing method (that would be used by the dtml-var source code, for example), that already does the job for me ? I found the BaseRequest / traverse method that seems to do it, but is there a convinient way to call it ? Many thanks, Pierre-Julien -- If the only tool you have is a hammer, you tend to see every problem as a nail. Si le seul outil dont vous disposez est un marteau, vous avez tendance à voir chaque problème comme un clou. --Abraham Maslow
Pierre-Julien Grizel wrote:
Hi,
I'd like to perform a name lookup inside a product, relying on acquisition, property and REQUEST lookups.
Are you talking about a python product's __call__ method, by any chance? Chris
Chris Withers wrote:
Pierre-Julien Grizel wrote:
Hi,
I'd like to perform a name lookup inside a product, relying on acquisition, property and REQUEST lookups.
Are you talking about a python product's __call__ method, by any chance?
Chris
Ahem... Not exactly... I want my product to be callable with two method, say "m1" and "m2", that perform different tasks. And, inside those methods, I need to check some variables, which may be of several kinds (REQUEST, properties & so on). If found little help in the mailing list history : http://www.egroups.com/message/zope/40811 It references a mysterious (for me !) "md" attribute, which relates to the namespace. Uh, uh... Maybe is there a way to do what I want with this ?... ...But how ?..... Thanks, P.-J. -- If the only tool you have is a hammer, you tend to see every problem as a nail. Si le seul outil dont vous disposez est un marteau, vous avez tendance à voir chaque problème comme un clou. --Abraham Maslow
Chris Withers wrote:
Pierre-Julien Grizel wrote:
I want my product to be callable with two method, say "m1" and "m2", that perform different tasks.
How would these methods be called?
Chris
Well, I've got my product P somewhere in my object hierarchy. Its methods _should_ be called <dtml-var "P.m1 (<param1>)"> where <param1> is a string parameter my method needs to know. I'd like to avoid the _.None and _ stuff if there is a way to do so. I looked at the __call__ method (and read the 'isDocTemp' thread ;-) ) and, if I must, I can replace m1 and m2 with a __call__ method taking another parameter specifying what kind of action it has to do. Many thanks, P.-J. -- If the only tool you have is a hammer, you tend to see every problem as a nail. Si le seul outil dont vous disposez est un marteau, vous avez tendance à voir chaque problème comme un clou. --Abraham Maslow
Pierre-Julien Grizel wrote:
I looked at the __call__ method (and read the 'isDocTemp' thread ;-) ) and, if I must, I can replace m1 and m2 with a __call__ method taking another parameter specifying what kind of action it has to do.
Well, there's another little gem which got covered in a later bit of that thread. Try defining your method like: m1isDocTemp=1 def m1(self,ignored,md): # Your method here Also, check out the code in: <http://www.zope.org/Members/htrd/howto/FunctionTemplate> which is really helpful in this area. In fact, a FunctionTemplate may be exactly what you're looking for... HTH, Chris
participants (2)
-
Chris Withers -
Pierre-Julien Grizel