allow list of values in tracking queries
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@2098 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
f5429af719
commit
c266f353df
2 changed files with 17 additions and 8 deletions
|
@ -39,6 +39,12 @@ track data.
|
|||
>>> len(result)
|
||||
2
|
||||
|
||||
By supplying a list we can also search for more than one value in one query.
|
||||
|
||||
>>> result = tracks.query(taskId=('a001', 'a002'))
|
||||
>>> len(result)
|
||||
2
|
||||
|
||||
What happens if we store more than on record for one set of keys?
|
||||
|
||||
>>> tracks.saveUserTrack('a001', 0, 'u1', {'somekey': 'newvalue'})
|
||||
|
|
|
@ -30,7 +30,7 @@ from zope.index.field import FieldIndex
|
|||
|
||||
from persistent import Persistent
|
||||
from BTrees import OOBTree, IOBTree
|
||||
from BTrees.IFBTree import intersection
|
||||
from BTrees.IFBTree import intersection, union
|
||||
|
||||
from interfaces import IRun, ITrackingStorage, ITrack
|
||||
|
||||
|
@ -209,14 +209,14 @@ class TrackingStorage(BTreeContainer):
|
|||
for idx in kw:
|
||||
value = kw[idx]
|
||||
if idx in self.indexAttributes:
|
||||
#if type(value) not in (list, tuple):
|
||||
# value = [value]
|
||||
if type(value) not in (list, tuple):
|
||||
value = [value]
|
||||
# TODO: handle a list of values, provide union of results
|
||||
# resultx = None
|
||||
# for v in value:
|
||||
# result = self.union(result, self.indexes[idx].apply((v, v)))
|
||||
# result = self.intersect(result, resultx)
|
||||
result = self.intersect(result, self.indexes[idx].apply((value, value)))
|
||||
resultx = None
|
||||
for v in value:
|
||||
resultx = self.union(resultx, self.indexes[idx].apply((v, v)))
|
||||
result = self.intersect(result, resultx)
|
||||
#result = self.intersect(result, self.indexes[idx].apply((value, value)))
|
||||
elif idx == 'timeFrom':
|
||||
result = self.intersect(result,
|
||||
self.indexes['timeStamp'].apply((value, None)))
|
||||
|
@ -232,6 +232,9 @@ class TrackingStorage(BTreeContainer):
|
|||
def intersect(self, r1, r2):
|
||||
return r1 is None and r2 or intersection(r1, r2)
|
||||
|
||||
def union(self, r1, r2):
|
||||
return r1 is None and r2 or union(r1, r2)
|
||||
|
||||
def getUserNames(self, taskId):
|
||||
return sorted(self.taskUsers.get(taskId, []))
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue