getting the number of returned objects
Hi everyone, Let's say I've got a PythonScript called 'getResults' that does a catalog query. What is the proper way to get how many results were returned by getResults in DTML? For example, <dtml-var "len(getResults)"> doesn't work (I didn't think it would). I've tried some other variants without success. Any ideas? -Tim -- Tim Wilson | Visit Sibley online: | Check out: Henry Sibley HS | http://www.isd197.org | http://www.zope.com W. St. Paul, MN | | http://slashdot.org wilson@visi.com | <dtml-var pithy_quote> | http://linux.com
Getting the number of results returned by a Catalog query is a thing that folks commonly want to do, and usually just doing len(resultset) works OK. I'm surprised it didn't for you. That said, it's an extremely expensive operation under some circumstances because it un-lazifies the carefully-lazified Catalog resultset, creating a brain object for each matching catalog record. If there's a way to not do this in your application, I'd recommend it. Timothy Wilson wrote:
Hi everyone,
Let's say I've got a PythonScript called 'getResults' that does a catalog query. What is the proper way to get how many results were returned by getResults in DTML? For example, <dtml-var "len(getResults)"> doesn't work (I didn't think it would). I've tried some other variants without success. Any ideas?
-Tim
-- Tim Wilson | Visit Sibley online: | Check out: Henry Sibley HS | http://www.isd197.org | http://www.zope.com W. St. Paul, MN | | http://slashdot.org wilson@visi.com | <dtml-var pithy_quote> | http://linux.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 )
-- Chris McDonough Zope Corporation http://www.zope.org http://www.zope.com "Killing hundreds of birds with thousands of stones"
On Sat, 20 Oct 2001, Chris McDonough wrote:
Getting the number of results returned by a Catalog query is a thing that folks commonly want to do, and usually just doing len(resultset) works OK. I'm surprised it didn't for you.
That said, it's an extremely expensive operation under some circumstances because it un-lazifies the carefully-lazified Catalog resultset, creating a brain object for each matching catalog record. If there's a way to not do this in your application, I'd recommend it.
Thanks for the quick reply. The cost of this particular operation isn't really important since this method will only get called once per day. (I'm trying to set up a method that will email the next day's school lunch menus to a listserv *if* there is a lunch menu for tomorrow.) I know it works to make two scripts, the first Python Script simply does the Catalog query and returns true if the query returned anything, and the second DTML Method just does the query again if the result of calling the first Python Script was "true" and processes the results. -Tim -- Tim Wilson | Visit Sibley online: | Check out: Henry Sibley HS | http://www.isd197.org | http://www.zope.com W. St. Paul, MN | | http://slashdot.org wilson@visi.com | <dtml-var pithy_quote> | http://linux.com
Oh OK. As long as you know it's not advised, try this: <dtml-var "_.len(getResults())"> ----- Original Message ----- From: "Timothy Wilson" <wilson@visi.com> To: "Zope listserv" <zope@zope.org> Sent: Saturday, October 20, 2001 3:25 PM Subject: Re: [Zope] getting the number of returned objects
On Sat, 20 Oct 2001, Chris McDonough wrote:
Getting the number of results returned by a Catalog query is a thing that folks commonly want to do, and usually just doing len(resultset) works OK. I'm surprised it didn't for you.
That said, it's an extremely expensive operation under some circumstances because it un-lazifies the carefully-lazified Catalog resultset, creating a brain object for each matching catalog record. If there's a way to not do this in your application, I'd recommend it.
Thanks for the quick reply. The cost of this particular operation isn't really important since this method will only get called once per day. (I'm trying to set up a method that will email the next day's school lunch menus to a listserv *if* there is a lunch menu for tomorrow.)
I know it works to make two scripts, the first Python Script simply does the Catalog query and returns true if the query returned anything, and the second DTML Method just does the query again if the result of calling the first Python Script was "true" and processes the results.
-Tim
-- Tim Wilson | Visit Sibley online: | Check out: Henry Sibley HS | http://www.isd197.org | http://www.zope.com W. St. Paul, MN | | http://slashdot.org wilson@visi.com | <dtml-var pithy_quote> | http://linux.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 )
participants (3)
-
Chris McDonough -
Chris McDonough -
Timothy Wilson