Code

Searches on range of dates for metakit
authorkedder <kedder@57a73879-2fb5-44c3-a270-3262357dd7e2>
Mon, 10 Mar 2003 20:24:30 +0000 (20:24 +0000)
committerkedder <kedder@57a73879-2fb5-44c3-a270-3262357dd7e2>
Mon, 10 Mar 2003 20:24:30 +0000 (20:24 +0000)
git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1584 57a73879-2fb5-44c3-a270-3262357dd7e2

roundup/backends/back_metakit.py

index d8adbee4198c346131b50994d5a26224c339c28b..fec52eb95579bc27887062c38f31dc3bc0b8e21e 100755 (executable)
@@ -1,3 +1,4 @@
+# $Id: back_metakit.py,v 1.41 2003-03-10 20:24:30 kedder Exp $
 '''
    Metakit backend for Roundup, originally by Gordon McMillan.
 
@@ -34,6 +35,7 @@ from sessions import Sessions, OneTimeKeys
 import re, marshal, os, sys, weakref, time, calendar
 from roundup import indexer
 import locking
+from roundup.date import Range
 
 _dbs = {}
 
@@ -852,7 +854,11 @@ class Class:
         # filterspec is a dict {propname:value}
         # sort and group are (dir, prop) where dir is '+', '-' or None
         #                    and prop is a prop name or None
+
+        timezone = self.db.getUserTimezone()
+
         where = {'_isdel':0}
+        wherehigh = {}
         mlcriteria = {}
         regexes = {}
         orcriteria = {}
@@ -906,8 +912,20 @@ class Class:
                     bv = value
                 where[propname] = bv
             elif isinstance(prop, hyperdb.Date):
-                t = date.Date(value).get_tuple()
-                where[propname] = int(calendar.timegm(t))
+                try:
+                    # Try to filter on range of dates
+                    date_rng = Range(value, date.Date, offset=timezone)
+                    if date_rng.from_value:
+                        t = date_rng.from_value.get_tuple()
+                        where[propname] = int(calendar.timegm(t))
+                    if date_rng.to_value:
+                        t = date_rng.to_value.get_tuple()
+                        wherehigh[propname] = int(calendar.timegm(t))
+                    else:
+                        wherehigh[propname] = None
+                except ValueError:
+                    # If range creation fails - ignore that search parameter
+                    pass                        
             elif isinstance(prop, hyperdb.Interval):
                 where[propname] = str(date.Interval(value))
             elif isinstance(prop, hyperdb.Number):
@@ -917,7 +935,9 @@ class Class:
         v = self.getview()
         #print "filter start at  %s" % time.time() 
         if where:
-            v = v.select(where)
+            where_higherbound = where.copy()
+            where_higherbound.update(wherehigh)
+            v = v.select(where, where_higherbound)
         #print "filter where at  %s" % time.time() 
 
         if mlcriteria: