provide default operator for a field; define special operators 'in' and 'only'

git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@3924 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2010-07-24 14:45:13 +00:00
parent e4a493ea2f
commit c22acae02d
2 changed files with 19 additions and 11 deletions

View file

@ -22,7 +22,7 @@ Basic classes for report management.
$Id$ $Id$
""" """
import operator import operator as standard_operators
from zope.interface import implements from zope.interface import implements
from cybertools.composer.base import Component, Element, Compound from cybertools.composer.base import Component, Element, Compound
@ -154,16 +154,9 @@ class LeafQueryCriteria(BaseQueryCriteria, Element):
if not self.comparisonValue: if not self.comparisonValue:
return True return True
value = self.field.getSelectValue(row) value = self.field.getSelectValue(row)
if self.operator == 'in': op = operators.get(self.operator)
if isinstance(value, (list, tuple)): if op is None:
for v in value: op = getattr(standard_operators, self.operator, None)
if v in self.comparisonValue:
return True
else:
return False
else:
return value in self.comparisonValue
op = getattr(operator, self.operator, None)
if op is None: if op is None:
# TODO: log warning # TODO: log warning
return True return True
@ -171,6 +164,20 @@ class LeafQueryCriteria(BaseQueryCriteria, Element):
return op(value, self.comparisonValue) return op(value, self.comparisonValue)
def checkOnly(value, compValue):
if not value:
return 'none' in compValue
for v in value:
if v not in compValue:
return False
return True
def checkIn(value, compValue):
return value in compValue
operators = {'only': checkOnly, 'in': checkIn}
class CompoundQueryCriteria(BaseQueryCriteria, Compound): class CompoundQueryCriteria(BaseQueryCriteria, Compound):
implements(ICompoundQueryCriteria) implements(ICompoundQueryCriteria)

View file

@ -45,6 +45,7 @@ class Field(Component):
instance_name = None instance_name = None
storeData = True storeData = True
renderer = 'standard' renderer = 'standard'
operator = 'in'
executionSteps = ['query', 'sort', 'output'] executionSteps = ['query', 'sort', 'output']