Calling dynamic zsql method from zpt?
I've searched everywhere for a seamingly obvious thing to have in the documentation - how to call a dynamic zsql method from a zope page template using arguments. What I need is something like this: <div tal:define="sqlRows nocall:here/ZSQLTerritoryList(parent_id=parent_id)"> <select name="country_list"> <option value="">ANY</option> <option tal:repeat="sqlRow sqlRows" ... etc... but obviously the first line of code doesn't work. How else are variables passed do zsql methods from page templates? Thanks, Nick
On Nov 27, 2003, at 3:53 PM, Nick Bower wrote:
I've searched everywhere for a seamingly obvious thing to have in the documentation - how to call a dynamic zsql method from a zope page template using arguments.
What I need is something like this:
<div tal:define="sqlRows nocall:here/ZSQLTerritoryList(parent_id=parent_id)"> <select name="country_list"> <option value="">ANY</option> <option tal:repeat="sqlRow sqlRows" ... etc...
but obviously the first line of code doesn't work. How else are variables passed do zsql methods from page templates?
What happens if you change the call to: <div tal:define="sqlRows python:here.ZSQLTerritoryList(parent_id=parent_id)"> ___/ / __/ / ____/ Ed Leafe Linux Love: unzip;strip;touch;finger;mount;fsck;more;yes;umount;sleep
What I need is something like this:
<div tal:define="sqlRows nocall:here/ZSQLTerritoryList(parent_id=parent_id)"> <select name="country_list"> <option value="">ANY</option> <option tal:repeat="sqlRow sqlRows" ... etc...
but obviously the first line of code doesn't work. How else are variables passed do zsql methods from page templates?
What happens if you change the call to:
<div tal:define="sqlRows python:here.ZSQLTerritoryList(parent_id=parent_id)">
Thanks. But then why does zope go to the trouble of having a "nocall:"? Would multiple operations on subsequent sqlRows variables not result in multiple queries in the above python implementation? If not, then I'm safe and it's exactly what I need :-) -- Nick Bower Ph.D. Cybersecurity Sector Institute for the Protection and Security of the Citizen European Commission Joint Research Centre TP 267 Via Enrico Fermi 1 Ispra 21020 VA Italy nicholas.bower@jrc.it tel:+39 0332786679 fax:+39 0332789576
On Nov 28, 2003, at 7:58 AM, Nick Bower wrote:
What happens if you change the call to:
<div tal:define="sqlRows python:here.ZSQLTerritoryList(parent_id=parent_id)">
Thanks. But then why does zope go to the trouble of having a "nocall:"? Would multiple operations on subsequent sqlRows variables not result in multiple queries in the above python implementation? If not, then I'm safe and it's exactly what I need :-)
No, the query is run when the div statement defining it is processed. Subsequent references to sqlRows will work with the results tuple returned from the query. ___/ / __/ / ____/ Ed Leafe Linux Love: unzip;strip;touch;finger;mount;fsck;more;yes;umount;sleep
Nick Bower wrote:
What I need is something like this:
<div tal:define="sqlRows nocall:here/ZSQLTerritoryList(parent_id=parent_id)"> <select name="country_list"> <option value="">ANY</option> <option tal:repeat="sqlRow sqlRows" ... etc...
but obviously the first line of code doesn't work. How else are variables passed do zsql methods from page templates?
You must use a Python expression, and not a TALES expression. TALES is path-like, and has no support for arguments.
What happens if you change the call to: <div tal:define="sqlRows python:here.ZSQLTerritoryList(parent_id=parent_id)">
Thanks. But then why does zope go to the trouble of having a "nocall:"?
'nocall' is for getting a handle to a method. Sort of like:: def foo(): print "A" bar = foo bar() The standard (calling) operation gets a method's results. It's the difference bewteen parens and no parens.
Would multiple operations on subsequent sqlRows variables not result in multiple queries in the above python implementation? If not, then I'm safe and it's exactly what I need :-)
You're safe. It binds the results, as per above. Using 'nocall' is very rare. I've seen a legit use in the wild only a couple of times. --jcc
participants (3)
-
Ed Leafe -
J Cameron Cooper -
Nick Bower