[Zope] odd behavior when External Method calls DTML Method

Thomas B. Passin tpassin@mitretek.org
Wed, 17 Apr 2002 11:36:06 -0400


[Brian Withun]

>
> I am experiencing some kind of acquisition problem when calling DTML
Methods
> from External Methods
>
> In a nutshell, I have a dtml method:
>
> ---------------------(test1_dtml)---
> <dtml-var URL>
> ------------------------------------
>
>...
>   File /usr/local/Zope-2.5.0-linux2-x86/lib/python/OFS/DTMLMethod.py, line
> 127, in __call__
>     (Object: test1_dtml)
>   File
> /usr/local/Zope-2.5.0-linux2-x86/lib/python/DocumentTemplate/DT_String.py,
> line 473, in __call__
>     (Object: test1_dtml)
> KeyError: URL
>
> This is the module containing the function for my External Method:
>
> --------------------(myModule.py)---
> def test1( self ):
>   return self.Test.test1_dtml( self )
> ------------------------------------
>
> Curiously, though my DTML Method '''<dtml-var URL>''' does not work, if I
> change it
> to '''<dtml-var "REQUEST.get('URL')">''' it works fine.  ?????
>


This is not the correct way to write an external method.  First of all,
Python does not have a "self" parameter or property.  The name is used, by
convention, in defining classes, and has nothing to do with function
definitions.  Even though you may call it "self", it is just a parameter to
be passed in like any other.

You need to figure out what object reference to send to the external method.
Remember, when you modify the external method, you have to save it again in
the "properties" tab for the page of that method, otherwise Zope won't know
about your changes.

But you aren't passing any argument to the function - none is passed by
default to an external method.  So you should see an error "not enough
arguments", which you don't.

I can't say why "URL" is not being found - is that really the id of the
external method?  If it were defined in the parent page of the dtml method,
that might explain why it wasn't found.

If

<dtml-var "REQUEST.get('URL')">

succeeds, as you say, it indicates that your REQUEST object has a 'URL'
property, and has nothing to do with the external method.  I would name your
external method something else to be on the safe side - "URL" seems like it
would be likely to have name collisions.

Cheers,

Tom P