Hello All, I'm trying to create a product like this: ...skipped class testclass(SimpleItem, Folder): ... def __init__(self,id): """Constructor method """ self.id=id self._setObject('sql', SQL('sql1', ' RDBMS', 'testconn', 'parm1:string', ''' select * from table where ... ''') ) ... def getTable(self,REQUEST=None): "get table with results" self.parm1=0 self.REQUEST.set('sql',self.sql()) if REQUEST is not None: return self.showResult_html(self, REQUEST) ... and then I call it from a page like: <span tal:replace="structure python:here.name.getTable(request)"></span> it works ,but in a few clicks I get this error: Failed to import class r from module Record. if I need to set a variable in request inside getTable method , do I need to use REQUEST or self.REQUEST? what is a correct way to register sql and to pass parameters in such class? thanks. __________________________________ Do you Yahoo!? Yahoo! Mail SpamGuard - Read only the mail you want. http://antispam.yahoo.com/tools
Alexander B. wrote at 2004-2-21 21:21 -0800:
I'm trying to create a product like this:
...skipped class testclass(SimpleItem, Folder): ... def getTable(self,REQUEST=None): "get table with results" self.parm1=0 self.REQUEST.set('sql',self.sql())
if REQUEST is not None: return
self.showResult_html(self, REQUEST)
This looks like funny code... Usually, you pass arguments to Z SQL Methods not via acquisition especially not by writing the parent object (this gives you a new copy of your object for each call to "getTable" -- surely not what you want). Usually, you do not pass information around in the REQUEST object (though, they may be (sometimes) reasons to do so). Why do you return when "REQUEST" is not "None" but call "showResult_html" with a "None" "Request"? This calls for trouble...
... and then I call it from a page like: <span tal:replace="structure python:here.name.getTable(request)"></span>
This will almost surely remove your "span" (as "request" will not be "None").
it works ,but in a few clicks I get this error: Failed to import class r from module Record.
Look at the traceback! Report it when you do not understand it! Each click gives you a new request. What you did in previous requests is lost. Are the new "clicks" calling "getTable" again?
if I need to set a variable in request inside getTable method , do I need to use REQUEST or self.REQUEST?
When you chose your names adequately, both will be the same. Of course, noone can force you to chose names adequately and use them as their name dictates...
what is a correct way to register sql and to pass parameters in such class?
I do not know what you mean with "register sql". But you pass arguments to Z SQL Methods by passing them as keyword arguments. When I had written your "getTable" method, it would have looked like: def getTable(self): "get rendered table results" return self.showResult_html( self, self.REQUEST, self.sql(parm1=0) ) -- Dieter
participants (2)
-
Alexander B. -
Dieter Maurer