RE: [Zope] zope: accessing zsql methods from external methods (1. 10.2 and 1.11pr1)
I'm stumped.
I need a simple example of how to get an external python method to grok a working zsql query.
I have a zsql query which works fine, called showcont, returning the entire contents of a small table.
I have a simple external method based on the hint on page 11 of the zsql methods user's guide which implies that an external method should get something useful back from showcont() - I've stripped it to the basics so I expect to get some horrible but familiar text back without adding any python complications - I just want this to work !!!
===========testzsql.py in Extensions directory # testing external methods def test(self): s = '' for cont in showcont(): for contitem in cont: s = s + contitem + '<BR>' return s ========= The external method is loaded into the same folder as the zsql method and function test is called as testzsql.
I put a <!--#var testzsql--> into a dtml method and get...tracebacks. Basically, they all point to the fourth line - the showcont() call seems to break.
At first glance, I'd guess that the problem is that you are not qualifying the showcont() method ( but I cant be sure without seeing the actual traceback ). Note that the "magical" namespace binding that happens in DTML does *not* happen in external methods -- in other words, you need to qualify the method yourself: self.showcont() instead of just showcont(), assuming that your showcont() method lives in the same folder. Hope this helps! Brian Lloyd brian@digicool.com Software Engineer 540.371.6909 Digital Creations http://www.digicool.com
AAhhhhh. I feel zope much better. Calling self.showcont() works like a charm. Thanks Brian ! Solved even without seeing the traceback. May I suggest an adjustment to the zsql methods documentation which is sadly quite wrong (!!!) to prevent further head banging out there in the zope community. If I get time, I'll write this up as a howto since it's a really important, simple and useful trick. Brian Lloyd wrote:
I'm stumped.
I need a simple example of how to get an external python method to grok a working zsql query.
I have a zsql query which works fine, called showcont, returning the entire contents of a small table.
I have a simple external method based on the hint on page 11 of the zsql methods user's guide which implies that an external method should get something useful back from showcont() - I've stripped it to the basics so I expect to get some horrible but familiar text back without adding any python complications - I just want this to work !!!
===========testzsql.py in Extensions directory # testing external methods def test(self): s = '' for cont in showcont(): for contitem in cont: s = s + contitem + '<BR>' return s ========= The external method is loaded into the same folder as the zsql method and function test is called as testzsql.
I put a <!--#var testzsql--> into a dtml method and get...tracebacks. Basically, they all point to the fourth line - the showcont() call seems to break.
At first glance, I'd guess that the problem is that you are not qualifying the showcont() method ( but I cant be sure without seeing the actual traceback ).
Note that the "magical" namespace binding that happens in DTML does *not* happen in external methods -- in other words, you need to qualify the method yourself: self.showcont() instead of just showcont(), assuming that your showcont() method lives in the same folder.
Hope this helps!
Brian Lloyd brian@digicool.com Software Engineer 540.371.6909 Digital Creations http://www.digicool.com
-- Dr Ross Lazarus Associate Professor and Sub-Dean for Information Technology Faculty of Medicine, A27, R126a, University of Sydney, Camperdown, NSW 2006, Australia Tel: (+61 2) 93514429 Mobile: +61414872482 Fax: (+61 2) 93516646 Email: rossl@med.usyd.edu.au http://www.health.usyd.edu.au/people/rossl.htm
participants (2)
-
Brian Lloyd -
Dr. Ross Lazarus