work in progress: use query criteria as check/filter in result set creation

git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@3885 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
helmutm 2010-06-05 06:31:56 +00:00
parent 2fc491b744
commit e4a5c8e8d9
3 changed files with 30 additions and 7 deletions

View file

@ -28,7 +28,8 @@ from cybertools.composer.base import Component, Element, Compound
from cybertools.composer.base import Template
from cybertools.composer.report import field
from cybertools.composer.report.interfaces import IReportManager, IReport
from cybertools.composer.report.interfaces import ILeafQueryCriteria
from cybertools.composer.report.interfaces import IQueryCriteria, ILeafQueryCriteria
from cybertools.composer.report.interfaces import ICompoundQueryCriteria
from cybertools.util.jeep import Jeep
from cybertools.util.randomname import generateName
@ -125,7 +126,15 @@ class Report(Template):
return [dict(renderer='default', title='Default')]
class LeafQueryCriteria(Element):
class BaseQueryCriteria(Component):
implements(IQueryCriteria)
def check(self, obj):
return True
class LeafQueryCriteria(BaseQueryCriteria, Element):
implements(ILeafQueryCriteria)
@ -135,7 +144,9 @@ class LeafQueryCriteria(Element):
self.comparisonValue = comparisonValue
class CompoundQueryCriteria(Compound):
class CompoundQueryCriteria(BaseQueryCriteria, Compound):
implements(ICompoundQueryCriteria)
logicalOperator = 'and'

View file

@ -175,7 +175,15 @@ class IBaseReportComponent(IComponent):
required=False,)
class ILeafQueryCriteria(IBaseReportComponent):
class IQueryCriteria(Interface):
def check(obj):
""" Return True if the object given meets the query conditions
specified by this criteria object.
"""
class ILeafQueryCriteria(IQueryCriteria, IBaseReportComponent):
""" A terminal query criteria element.
"""
@ -192,7 +200,7 @@ class ILeafQueryCriteria(IBaseReportComponent):
required=True,)
class ICompoundQueryCriteria(ICompound):
class ICompoundQueryCriteria(IQueryCriteria, IBaseReportComponent, ICompound):
""" A query criteria element consisting of leaf query criteria elements.
The names of the component criteria are given by the ``parts``
attribute.

View file

@ -25,6 +25,7 @@ $Id$
from zope.cachedescriptors.property import Lazy
from cybertools.composer.interfaces import IInstance
from cybertools.composer.report.base import BaseQueryCriteria
class Row(object):
@ -40,14 +41,17 @@ class Row(object):
class ResultSet(object):
def __init__(self, context, data, rowFactory=Row, sortCriteria=None):
def __init__(self, context, data, rowFactory=Row,
sortCriteria=None, queryCriteria=BaseQueryCriteria()):
self.context = context
self.data = data
self.rowFactory = rowFactory
self.sortCriteria = sortCriteria
self.queryCriteria = queryCriteria
def getResult(self):
result = [self.rowFactory(item, self) for item in self.data]
result = [self.rowFactory(item, self) for item in self.data
if self.queryCriteria.check(item)]
if self.sortCriteria:
result.sort(key=lambda x: [f.getSortValue(x) for f in self.sortCriteria])
return result