[Zope] Catalog search from Python Script

Jens Vagelpohl jens@zope.com
Sun, 14 Oct 2001 19:25:47 -0400


tim,

what your sccript does right now is to find an item with menu_date set to 
the exact date and time your script is run. what you really want is to 
search a range of date/time values, the whole range that exists today.

there is a howto on zope.org at 
http://www.zope.org/Members/Zen/howto/AdvZCatalogSearching that describes 
searching a range of values on the same index. i think if you rewrite your 
script to do something like the following it should work (actually tested 
it on the CMF dogbowl on index "created" myself):

today_earliest = context.ZopeTime().earliestTime()
tomorrow_earliest = today_earliest + 1

return context.Catalog(
         {'menu_date' : [ today_earliest, tomorrow_earliest ]
         , 'menu_date_usage' : 'range:min:max'
         }
)

you pass a list of two elements as values for the index, one being today's 
data at 00:00:00 and one being tomorrow's date at 00:00:00. the 
"menu_date_usage" tells the catalog that you want to search a range of 
values, in this case being today_earliest the minimum value and 
tomorrow_earliest the maximum.

jens



On Sunday, October 14, 2001, at 06:27 , Timothy Wilson wrote:

> Hi everyone,
>
> I'm working on something that should be very easy, but I must be missing
> something.
>
> I've whipped up a little ZClass that will be used to keep track of our
> school lunch menus. The class has the following properties:
>
> menu_date (date)
> school (string)
> special_event (string)
> breakfast_menu (lines)
> lunch_menu (lines)
>
> I created a ZCatalog to allow me to pull out each day's menu and display 
> it
> on the school's homepage. I'm using a separate Catalog for this with the
> following indexes and metadata:
>
> Indexes
> =======
> menu_date
> school
>
> Metadata
> ========
> menu_date
> school
> special_event
> breakfast_menu
> lunch_menu
>
> I created a very simple Python Script that should query the catalog and
> return a reference that that day's menu. Here's the code (inspired by
> examples from the Zope Book):
>
> ## Script (Python) "queryMenu"
> ##bind container=container
> ##bind context=context
> ##bind namespace=
> ##bind script=script
> ##bind subpath=traverse_subpath
> ##parameters=
> ##title=Get today's lunch menu
> ##
> """
> Retrieve today's lunch menu from the Catalog
> """
> return context.Catalog(
>         {'menu_date' : context.ZopeTime(),
>         }
> )
>
> The problem is that nothing gets returned even when I know that there's an
> instance with menu_date set for 10/14/2001 (no we don't serve lunch on
> Sundays). 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 )