[Zope] AW: [Zope] external methods
Stefan Franke
sfranke@cdc-group.com
Fri, 26 Mar 1999 13:06:42 +0100
Hi Jepthe,
First, if you want to acces the REQUEST object, you need
to declare it as a formal parameter:
def myExtMethod(self, REQUEST): ...
REQUEST is then passed automatically by Zope's internal
magic, which looks up formal parameter names and matches
them to arguments from HTML forms, HTTP Headers, etc.
The "read only class, buffer" traceback is due to a very
annoying bug in ExternalMethod.py and screws up any
other error messages in external methods.
I can't remember exactly if it was in line 254 or 256 in
ExternalMethod.py, but here's the code I use to fix it:
ExternalMethod.py, from line 254
if type(error_type) is type('') and lower(error_type) in
('redirect',):
raise error_type, error_value, tb
if (type(error_value) is type('') and
regex.search('[a-zA-Z]>', error_value) > 0):
error_message=error_value
else:
error_message=''
With that you should get better error messages.
Regards,
Stefan
PS:
<!--#var myExtMethod-->
<!--#var "myExtMethod()"-->
should be both OK
Service Informatique CHSR wrote:
> Hello,
>
> I'm confused with external methods. Please help.
>
> I want an external method to access its context (for the
> purpose of acquisition, etc.). So I write:
>
> def myExtMethod(self):
> pass
>
> Within myExtMethod, I should be able to:
> - write self.REQUEST to access the current REQUEST object (I
> need to be able to modify the current REQUEST object with
> self.REQUEST.set(...))
> - or for example self.myzsqlmethod() to call a zsql method object,
> right???
>
> Let's suppose that myExtMethod is:
>
> def myExtMethod(self):
> l=[]
> for i in self.l:
> l.append(i+1)
> self.REQUEST.set('l', l)
>
> Now, how can I call this method from DTML?
>
> <!--#var myExtMethod-->
> <!--#var "myExtMethod()"-->
> <!--#var "myExtMethod(this())"-->
>
> All don't work. I end up in a traceback. "read only class, buffer"
>
> Any hints?
>
> Jepthe CLAIN
> Service Informatique CHSR
>