From c22acae02df7bb121b0fc0010162a1d9bd7c02ee Mon Sep 17 00:00:00 2001 From: helmutm Date: Sat, 24 Jul 2010 14:45:13 +0000 Subject: [PATCH] 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 --- composer/report/base.py | 29 ++++++++++++++++++----------- composer/report/field.py | 1 + 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/composer/report/base.py b/composer/report/base.py index 447de4c..dab60e4 100644 --- a/composer/report/base.py +++ b/composer/report/base.py @@ -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) diff --git a/composer/report/field.py b/composer/report/field.py index 317b09c..116def3 100644 --- a/composer/report/field.py +++ b/composer/report/field.py @@ -45,6 +45,7 @@ class Field(Component): instance_name = None storeData = True renderer = 'standard' + operator = 'in' executionSteps = ['query', 'sort', 'output']