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$
"""
import operator
import operator as standard_operators
from zope.interface import implements
from cybertools.composer.base import Component, Element, Compound
@ -154,16 +154,9 @@ class LeafQueryCriteria(BaseQueryCriteria, Element):
if not self.comparisonValue:
return True
value = self.field.getSelectValue(row)
if self.operator == 'in':
if isinstance(value, (list, tuple)):
for v in value:
if v in self.comparisonValue:
return True
else:
return False
else:
return value in self.comparisonValue
op = getattr(operator, self.operator, None)
op = operators.get(self.operator)
if op is None:
op = getattr(standard_operators, self.operator, None)
if op is None:
# TODO: log warning
return True
@ -171,6 +164,20 @@ class LeafQueryCriteria(BaseQueryCriteria, Element):
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):
implements(ICompoundQueryCriteria)

View file

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