add more configuration options; implement default checking of query criteria
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@3888 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
4731481f48
commit
643fe8db4d
3 changed files with 18 additions and 3 deletions
|
@ -143,6 +143,12 @@ class LeafQueryCriteria(BaseQueryCriteria, Element):
|
|||
self.operator = operator
|
||||
self.comparisonValue = comparisonValue
|
||||
|
||||
def check(self, obj):
|
||||
value = getattr(obj, self.name, None)
|
||||
if value is not None:
|
||||
return value in self.comparisonValue
|
||||
return True
|
||||
|
||||
|
||||
class CompoundQueryCriteria(BaseQueryCriteria, Compound):
|
||||
|
||||
|
@ -153,3 +159,8 @@ class CompoundQueryCriteria(BaseQueryCriteria, Compound):
|
|||
def __init__(self, parts):
|
||||
self.parts = Jeep(parts)
|
||||
|
||||
def check(self, obj):
|
||||
for p in self.parts:
|
||||
if not p.check(obj):
|
||||
return False
|
||||
return True
|
||||
|
|
|
@ -43,6 +43,7 @@ class Field(Component):
|
|||
default = None
|
||||
instance_name = None
|
||||
storeData = True
|
||||
renderer = 'standard'
|
||||
|
||||
executionSteps = ['query', 'sort', 'output']
|
||||
|
||||
|
@ -60,8 +61,11 @@ class Field(Component):
|
|||
def name(self):
|
||||
return self.__name__
|
||||
|
||||
def getRawValue(self, row):
|
||||
return getattr(row.context, self.name)
|
||||
|
||||
def getValue(self, row):
|
||||
value = getattr(row.context, self.name)
|
||||
value = self.getRawValue(row)
|
||||
if value is None:
|
||||
return u''
|
||||
if isinstance(value, basestring):
|
||||
|
|
|
@ -50,8 +50,8 @@ class ResultSet(object):
|
|||
self.queryCriteria = queryCriteria
|
||||
|
||||
def getResult(self):
|
||||
result = [self.rowFactory(item, self) for item in self.data
|
||||
if self.queryCriteria.check(item)]
|
||||
result = [self.rowFactory(item, self) for item in self.data]
|
||||
result = [row for row in result if self.queryCriteria.check(row)]
|
||||
if self.sortCriteria:
|
||||
result.sort(key=lambda x: [f.getSortValue(x) for f in self.sortCriteria])
|
||||
return result
|
||||
|
|
Loading…
Add table
Reference in a new issue