Hello I have the following struture in my folders: sql - oracle - postgresql - odbc I've the idea to share most of the SQL-Methods via aqusition (they are in sql), but have the specific ones (not ANSI SQL) in the db folder (e.g Oracle with it's to_date function. I've tried this statement for an <dtml-in>: <dtml-set query="sql.oracle.browse()"> #1 See bottom <dtml-in "query" size=12 start=query_start> which works fine. I'd like to have it more dynamicly, so I tried: <dtml-set query_string="'sql.'+getDatabase()+'.browse()'"> #1 See bottom <dtml-set query="_.getitem(query_string)"> #1 See bottom <dtml-in "query" size=12 start=query_start sort="code,bez"> getDatabase is a Python-Script which get's the db for the folder (oracle,postgresql,odbc). But it doesn't find the object: Error Type: KeyError Error Value: sql.oracle.browse() This resource may be trying to reference a nonexistent object or variable sql.oracle.browse Anybody can give me an advice for the correct syntax? Thanks Dieter #1 I'm using the dtml-set tag, so <dtml-call "REQUEST.set(foo, 10)"> is: <dtml-set foo='10'>
Try using _.getitem('your assembled id name') Its been awhile since i've used this, but I think its close to what you are looking for. DAvid ----- Original Message ----- From: "Dieter Fischer" <dieter.fischer@grid-it.ch> To: "Zope@Zope.Org" <zope@zope.org> Sent: Wednesday, May 21, 2003 8:49 AM Subject: [Zope] Dynamic Folders in <dtml-in>
Hello
I have the following struture in my folders:
sql - oracle - postgresql - odbc
I've the idea to share most of the SQL-Methods via aqusition (they are in sql), but have the specific ones (not ANSI SQL) in the db folder (e.g Oracle with it's to_date function.
I've tried this statement for an <dtml-in>:
<dtml-set query="sql.oracle.browse()"> #1 See bottom <dtml-in "query" size=12 start=query_start>
which works fine.
I'd like to have it more dynamicly, so I tried:
<dtml-set query_string="'sql.'+getDatabase()+'.browse()'"> #1 See bottom <dtml-set query="_.getitem(query_string)"> #1 See bottom <dtml-in "query" size=12 start=query_start sort="code,bez">
getDatabase is a Python-Script which get's the db for the folder (oracle,postgresql,odbc). But it doesn't find the object:
Error Type: KeyError Error Value: sql.oracle.browse() This resource may be trying to reference a nonexistent object or variable sql.oracle.browse
Anybody can give me an advice for the correct syntax?
Thanks
Dieter
#1 I'm using the dtml-set tag, so
<dtml-call "REQUEST.set(foo, 10)"> is: <dtml-set foo='10'>
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Try using
_.getitem('your assembled id name')
I've already tried this, this leads to: Error Type: InError Error Value: Strings are not allowed as input to the in tag. Means, the <dtml-in> doesn't accept strings Alexis Roda also pointed me out, that it shouldn't be: <dtml-set query_string="'sql.'+getDatabase()+'.browse()'"> it should be <dtml-set query_string="'sql.'+getDatabase()+'.browse'"> But there's no difference. Dieter
Dieter Fischer wrote:
Try using
_.getitem('your assembled id name')
I've already tried this, this leads to:
Error Type: InError Error Value: Strings are not allowed as input to the in tag.
Means, the <dtml-in> doesn't accept strings
First, if I'd do somethink like that I'd call the sql method explictly, like (first the static version)" <dtml-in "sql.oracle.browse({'var1':REQUEST.form['var1'],'var2':REQUEST.form['var2']})" yes, it's longer, and it isn't applicable in all situations, but it's explicit. Second, also a matter of taste, I'd prefer <dtml-let ..></dtml-let> for variables, because when REQUEST gets passed around umpteen methods, which call each other in sometimes convoluted (dynamic ;)) ways, it might be hard to tell why some <dtml-var bla> doesn't render what we expected it to render, because it has been injected in the REQUEST much earlier and in a galaxy far away. With dtml-let you at least have an explicit point where the variable vanishes. Now, finally, my try to answer your question: <dtml-let query="oracle" <dtml-in "sql[query].browse({'var1':REQUEST.form['var1'],'var2':REQUEST.form['var2']})" </dtml-in> </dtml-let> or, if you don't want to pass explicitly: <dtml-in "sql[query].browse(REQUEST})"> (which assumes that the variables you want to use are infact in REQUEST, otherwise the mythical "_" should do it) HTH, oliver
Hello Oliver Thanks for your help, this method works also. I was so concentrated to do it with the getitem method, that I didn't try it with namespaces. But I just wonder, is it possible with getitem or not. Regards Dieter
OK, This is bugging me now. I've got this working: (and it should work for you as well) <dtml-with "_.getitem('directory1')"> <dtml-with "_.getitem('directory2')"> <dtml-in yourSQLMethod> </dtml-in> </dtml-with> </dtml-with> But not <dtml-with "_.getitem('directory1.directory2')"> ... (i've been away from Zope so sue me!) David ----- Original Message ----- From: "Dieter Fischer" <dieter.fischer@grid-it.ch> To: "Zope@Zope.Org" <zope@zope.org> Sent: Wednesday, May 21, 2003 10:15 AM Subject: RE: [Zope] Dynamic Folders in <dtml-in>
Try using
_.getitem('your assembled id name')
I've already tried this, this leads to:
Error Type: InError Error Value: Strings are not allowed as input to the in tag.
Means, the <dtml-in> doesn't accept strings
Alexis Roda also pointed me out, that it shouldn't be:
<dtml-set query_string="'sql.'+getDatabase()+'.browse()'">
it should be
<dtml-set query_string="'sql.'+getDatabase()+'.browse'">
But there's no difference.
Dieter
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
<dtml-with "_.restrictedTraverse('directory1/directory2')"> On Wed, 21 May 2003 10:29:52 -0700, David Hassalevris <bluepaul@earthlink.net> wrote:
OK, This is bugging me now.
I've got this working: (and it should work for you as well) <dtml-with "_.getitem('directory1')"> <dtml-with "_.getitem('directory2')"> <dtml-in yourSQLMethod> </dtml-in> </dtml-with> </dtml-with>
But not
from Zope so sue me!) David
----- Original Message ----- From: "Dieter Fischer" <dieter.fischer@grid- it.ch> To: "Zope@Zope.Org" <zope@zope.org> Sent: Wednesday, May 21, 2003 10:15 AM Subject: RE: [Zope] Dynamic Folders in <dtml-in>
Try using
_.getitem('your assembled id name')
I've already tried this, this leads to:
Error Type: InError Error Value: Strings are not allowed as input to the in tag.
Means, the <dtml-in> doesn't accept strings
Alexis Roda also pointed me out, that it shouldn't be:
<dtml-set query_string="'sql.'+getDatabase()+'.browse()'">
it should be
<dtml-set query_string="'sql.'+getDatabase()+'.browse'">
But there's no difference.
Dieter
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
-- Phil Harris
Dieter Fischer wrote at 2003-5-21 17:49 +0200:
<dtml-set query="sql.oracle.browse()"> #1 See bottom <dtml-in "query" size=12 start=query_start>
which works fine.
I'd like to have it more dynamicly, so I tried:
<dtml-set query_string="'sql.'+getDatabase()+'.browse()'"> #1 See bottom
You call for "Computed attribute access". Pythons "getattr" function implements it. In DTML, its available as "_.getattr". In your case, its use looks like: <dtml-set query="_.getattr(sql,getDatabase()).browse()"> Dieter
participants (5)
-
David Hassalevris -
Dieter Fischer -
Dieter Maurer -
Oliver Bleutgen -
Phil Harris