Skip to content

Commit c0b105f

Browse files
author
Andrey Lebedev
committed
Searches on range of dates for metakit
1 parent 5297877 commit c0b105f

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

roundup/backends/back_metakit.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# $Id: back_metakit.py,v 1.41 2003-03-10 20:24:30 kedder Exp $
12
'''
23
Metakit backend for Roundup, originally by Gordon McMillan.
34
@@ -34,6 +35,7 @@
3435
import re, marshal, os, sys, weakref, time, calendar
3536
from roundup import indexer
3637
import locking
38+
from roundup.date import Range
3739

3840
_dbs = {}
3941

@@ -852,7 +854,11 @@ def filter(self, search_matches, filterspec, sort=(None,None),
852854
# filterspec is a dict {propname:value}
853855
# sort and group are (dir, prop) where dir is '+', '-' or None
854856
# and prop is a prop name or None
857+
858+
timezone = self.db.getUserTimezone()
859+
855860
where = {'_isdel':0}
861+
wherehigh = {}
856862
mlcriteria = {}
857863
regexes = {}
858864
orcriteria = {}
@@ -906,8 +912,20 @@ def filter(self, search_matches, filterspec, sort=(None,None),
906912
bv = value
907913
where[propname] = bv
908914
elif isinstance(prop, hyperdb.Date):
909-
t = date.Date(value).get_tuple()
910-
where[propname] = int(calendar.timegm(t))
915+
try:
916+
# Try to filter on range of dates
917+
date_rng = Range(value, date.Date, offset=timezone)
918+
if date_rng.from_value:
919+
t = date_rng.from_value.get_tuple()
920+
where[propname] = int(calendar.timegm(t))
921+
if date_rng.to_value:
922+
t = date_rng.to_value.get_tuple()
923+
wherehigh[propname] = int(calendar.timegm(t))
924+
else:
925+
wherehigh[propname] = None
926+
except ValueError:
927+
# If range creation fails - ignore that search parameter
928+
pass
911929
elif isinstance(prop, hyperdb.Interval):
912930
where[propname] = str(date.Interval(value))
913931
elif isinstance(prop, hyperdb.Number):
@@ -917,7 +935,9 @@ def filter(self, search_matches, filterspec, sort=(None,None),
917935
v = self.getview()
918936
#print "filter start at %s" % time.time()
919937
if where:
920-
v = v.select(where)
938+
where_higherbound = where.copy()
939+
where_higherbound.update(wherehigh)
940+
v = v.select(where, where_higherbound)
921941
#print "filter where at %s" % time.time()
922942

923943
if mlcriteria:

0 commit comments

Comments
 (0)