[Zope] Passing variables from ZSQL Methods
Dennis Allison
allison@sumeru.stanford.EDU
Sun, 13 Oct 2002 11:23:47 -0700
Norman Khine, <norman@khine.net>, wrote:
> >
> Can someone please point me in the right direction, I have the following
> python script:
>
> print '<SCRIPT LANGUAGE="JavaScript">'
> print '<!-- Begin'
> print """if (!assocArray) var assocArray = new Object();"""
> regions = context.sql_list_region()
> for region in regions:
> print """assocArray["region_list="%d"] = new Array("('Select
> county','',true,true)",""" % region.region_id
> counties= context.sql_list_county()
> for county in counties:
> print '''"('%d')",''' % county.county_id
>
> print " ); "
>
> print "-->"
> print "</script>"
>
> return printed
>
> this connects to two z sql methods, sql_list_region and sql_list_county
> respectively and the result i get is:
>
> <SCRIPT LANGUAGE="JavaScript">
> <!-- Begin
> if (!assocArray) var assocArray = new Object();
> assocArray["region_list="2"] = new Array("('Select county','',true,true)",
> "('1')",
> "('2')",
> "('3')",
> "('4')",
> "('5')",
> ...........
> ..........
> "('80')",
> );
> assocArray["region_list="3"] = new Array("('Select county','',true,true)",
> "('1')",
> "('2')",
> "('3')",
> "('4')",
> "('5')",
>
> and so on..........
>
> "('79')",
> "('80')",
> );
> -->
> </script>
>
> Now one of the problems I am having is that I want to be able to for each
> region_id to be able to list the related counties, so i passed a variable in
> the sql_list_county ZSQL Method, which is as follows:
>
> arguments: region_id:int=0
> select county, county_id from county where region_id=region_id
>
> but this returns the whole list for the counties, where as i want to be able
> to itarate for each region_id.
>
> also in the above script, how do i return both the county_id and county
> within the same print statement?
>
I guess I don't understand why you are constructing a Javascript script?
Javascript is a client-side system and (sigh) unstable across browsers.
You can (and should) do your entire processing in Zope and not use Javascript
unless you absolutely must.
I would have thought you'd have a couple of ZSQL methods which return a result
plus one or two Python scripts (not Javascript!), DTML-methods, or Templates
to present the information an you wish. You should be able to select the
information you need with an appropriate query.