ER: [Zope] Looking if a record with a given key exists in a database several times, in dtml
Hi Steve! I've tried your suggestion (and I think I've done it correctly), but I get an error: Zope Error Zope has encountered an error while publishing this resource. Error Type: AttributeError Error Value: key Any idea? Igor Leturia
-----Jatorrizko mezua----- Nondik: Steve Spicklemire [mailto:steve@spvi.com] Bidalia: Igandea, 2002.eko otsailak 17 21:13 Nora: Igor Leturia Cc: Steve Spicklemire; zope@zope.org Gaia: Re: [Zope] Looking if a record with a given key exists in a database several times, in dtml
Your idea sounds reasonable.. are you asking how to implement it, or is there some other problem? I would think you could create a python script that returns a dictionary that could be used to lookup results. Something like:
buildCache with argument "results"
cache_dict = {}
for result in results: cache_dict[result.key] = result
return cache_dict -----------------
called from DTML as:
<dtml-let theCache="buildCache(results=yourQuery())"> <dtml-in ....> <dtml-if "theCache.has_key(yourTestKey)"> <dtml-let theResult="theChache[yourTestKey]"> Do something with "theResult".. </dtml-let> </dtml-if> </dtml-in> </dtml-let>
Does that help? -steve
On Sunday, February 17, 2002, at 02:42 PM, Igor Leturia wrote:
Hi all!
I have a problem: in dtml, I have to iterate through a very big list and for each item I must look if there is a record with that key in a database. I can't run a 'select' ZSQLMethod for each, because it would take too long. What I want to do is run the 'select' ZSQLMethod once and load the results in a variable (an array or dictionary) which then will be faster to look up in, or look up in the results of that query in some fast way.
I have searched zope.org, but found nothing. Any ideas?
Igor Leturia
_______________________________________________ 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 )
Hi Igor, I'm sorry.. "key" was just an example! You've got to use an actual field from your database as a key! -steve On Monday, February 18, 2002, at 07:16 AM, Igor Leturia wrote:
Hi Steve!
I've tried your suggestion (and I think I've done it correctly), but I get an error:
Zope Error Zope has encountered an error while publishing this resource.
Error Type: AttributeError Error Value: key
Any idea?
Igor Leturia
-----Jatorrizko mezua----- Nondik: Steve Spicklemire [mailto:steve@spvi.com] Bidalia: Igandea, 2002.eko otsailak 17 21:13 Nora: Igor Leturia Cc: Steve Spicklemire; zope@zope.org Gaia: Re: [Zope] Looking if a record with a given key exists in a database several times, in dtml
Your idea sounds reasonable.. are you asking how to implement it, or is there some other problem? I would think you could create a python script that returns a dictionary that could be used to lookup results. Something like:
buildCache with argument "results"
cache_dict = {}
for result in results: cache_dict[result.key] = result
return cache_dict -----------------
called from DTML as:
<dtml-let theCache="buildCache(results=yourQuery())"> <dtml-in ....> <dtml-if "theCache.has_key(yourTestKey)"> <dtml-let theResult="theChache[yourTestKey]"> Do something with "theResult".. </dtml-let> </dtml-if> </dtml-in> </dtml-let>
Does that help? -steve
On Sunday, February 17, 2002, at 02:42 PM, Igor Leturia wrote:
Hi all!
I have a problem: in dtml, I have to iterate through a very big list and for each item I must look if there is a record with that key in a database. I can't run a 'select' ZSQLMethod for each, because it would take too long. What I want to do is run the 'select' ZSQLMethod once and load the results in a variable (an array or dictionary) which then will be faster to look up in, or look up in the results of that query in some fast way.
I have searched zope.org, but found nothing. Any ideas?
Igor Leturia
_______________________________________________ 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 )
_______________________________________________ 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 )
Also.. it looking a the "result" object code.. it appears you probably need to do: cache_dict[result['theNameOfTheFieldThatYouWantToBeAkey'] = result or somesuch.. -steve On Wednesday, February 20, 2002, at 12:45 PM, Steve Spicklemire wrote:
Hi Igor,
I'm sorry.. "key" was just an example! You've got to use an actual field from your database as a key!
-steve
On Monday, February 18, 2002, at 07:16 AM, Igor Leturia wrote:
Hi Steve!
I've tried your suggestion (and I think I've done it correctly), but I get an error:
Zope Error Zope has encountered an error while publishing this resource.
Error Type: AttributeError Error Value: key
Any idea?
Igor Leturia
-----Jatorrizko mezua----- Nondik: Steve Spicklemire [mailto:steve@spvi.com] Bidalia: Igandea, 2002.eko otsailak 17 21:13 Nora: Igor Leturia Cc: Steve Spicklemire; zope@zope.org Gaia: Re: [Zope] Looking if a record with a given key exists in a database several times, in dtml
Your idea sounds reasonable.. are you asking how to implement it, or is there some other problem? I would think you could create a python script that returns a dictionary that could be used to lookup results. Something like:
buildCache with argument "results"
cache_dict = {}
for result in results: cache_dict[result.key] = result
return cache_dict -----------------
called from DTML as:
<dtml-let theCache="buildCache(results=yourQuery())"> <dtml-in ....> <dtml-if "theCache.has_key(yourTestKey)"> <dtml-let theResult="theChache[yourTestKey]"> Do something with "theResult".. </dtml-let> </dtml-if> </dtml-in> </dtml-let>
Does that help? -steve
On Sunday, February 17, 2002, at 02:42 PM, Igor Leturia wrote:
Hi all!
I have a problem: in dtml, I have to iterate through a very big list and for each item I must look if there is a record with that key in a database. I can't run a 'select' ZSQLMethod for each, because it would take too long. What I want to do is run the 'select' ZSQLMethod once and load the results in a variable (an array or dictionary) which then will be faster to look up in, or look up in the results of that query in some fast way.
I have searched zope.org, but found nothing. Any ideas?
Igor Leturia
_______________________________________________ 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 )
_______________________________________________ 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 )
participants (2)
-
Igor Leturia -
Steve Spicklemire