passing method names into a python script?
I want to pass the name of a Z SQL Method into a python script, then execute that method and iterate over the results. Is this possible? My app uses a lot of dropdowns populated from database tables. Rather than rewriting the code for each one, I'd like to create one python script that takes a z sql method as a parameter, then executes it and spits out the html for the dropdown. Every Z SQL Method would return the same column names (id & value). Has this been done before? thanks -Kevin __________________________________________________ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/
Hi Keven, This is more for your humour than applied use. When I started with Zope a year ago, I made this ugly, clunky, retarded ZSQL method that would read tables using a template call: <dtml-in "select(select='id', as='l1id', sfrom='lgenre1', where='', operand='', equals='', orderby='id', dir='desc')" size=1 orphan=0> The ZSQL: <dtml-call "REQUEST.set('validate', -1)"> <dtml-in "(_.str(select), _.str(as), _.str(sfrom), _.str(where), _.str(operand), _.str(orderby), _.str(equals), _.str(dir))"> <dtml-let a=sequence-item> <dtml-in "('create', 'drop', 'alter', 'rename', 'optimize', 'backup', 'restore', 'repair', 'delete', 'truncate', 'replace', 'update', 'kill', 'grant', 'revoke', 'set', 'lock')"> <dtml-let b=sequence-item> <dtml-if "_.string.find(_.string.lower(a), b)!=-1"> <dtml-call "REQUEST.set('validate', 0)"> <dtml-else> <dtml-call "REQUEST.set('validate', 1)"> </dtml-if> </dtml-let> </dtml-in> </dtml-let> </dtml-in> <dtml-if "REQUEST['validate']==1"> select <dtml-var select> <dtml-if "as">as <dtml-var as></dtml-if> from <dtml-var sfrom> <dtml-if "where">where <dtml-var where> <dtml-if "operand"><dtml-var operand><dtml-if "equals"><dtml-var equals></dtml-if></dtml-if></dtml-if> <dtml-if "orderby">order by <dtml-var orderby> <dtml-if "dir"><dtml-var dir></dtml-if></dtml-if> <dtml-elif "REQUEST['validate']==0"> <dtml-call "REQUEST.set('state', 'ERROR')"> <dtml-elif "REQUEST['validate']==-1"> <dtml-call "REQUEST.set('action', 'view')"> <dtml-else> <dtml-call "REQUEST.set('state', 'ERROR')"> </dtml-if> I laugh very hard when I look at this, but if you can write the script, you could very well model it after this. Its fairly secure that you can at least be prevented from changing records. Cheers, Paz -----Original Message----- From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Kevin L Sent: Friday, July 06, 2001 9:44 PM To: zope@zope.org Subject: [Zope] passing method names into a python script? I want to pass the name of a Z SQL Method into a python script, then execute that method and iterate over the results. Is this possible? My app uses a lot of dropdowns populated from database tables. Rather than rewriting the code for each one, I'd like to create one python script that takes a z sql method as a parameter, then executes it and spits out the html for the dropdown. Every Z SQL Method would return the same column names (id & value). Has this been done before? thanks -Kevin __________________________________________________ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.com/ _______________________________________________ Zope maillist - Zope@zope.org http://lists.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://lists.zope.org/mailman/listinfo/zope-announce http://lists.zope.org/mailman/listinfo/zope-dev )
You could use a single ZSQL method that accepts either a table name, or part of a select statement if you need to do more tuning than just change the table name in the query. You always call the same method but tell it what you want each time. I'd suggest creating the html with dtml rather than a python script. After all, that's really what it's for. Let python pass a list to the dtml in the page, let the page format itself. Tom P [Kevin L]
I want to pass the name of a Z SQL Method into a python script, then execute that method and iterate over the results. Is this possible?
My app uses a lot of dropdowns populated from database tables. Rather than rewriting the code for each one, I'd like to create one python script that takes a z sql method as a parameter, then executes it and spits out the html for the dropdown. Every Z SQL Method would return the same column names (id & value). Has this been done before?
participants (3)
-
Kevin L -
Paz -
Thomas B. Passin