work in progress: reporting
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@3866 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
eb21c758ef
commit
d9c8ee3587
4 changed files with 78 additions and 9 deletions
|
@ -73,13 +73,14 @@ class Report(Template):
|
||||||
|
|
||||||
fields = Jeep((field.label,))
|
fields = Jeep((field.label,))
|
||||||
defaultOutputFields = (field.label,)
|
defaultOutputFields = (field.label,)
|
||||||
|
defaultSortCriteria = (field.label,)
|
||||||
presentationFormat = None
|
presentationFormat = None
|
||||||
|
|
||||||
renderers = ()
|
renderers = ()
|
||||||
sortSpec = ()
|
|
||||||
outputFields = ()
|
|
||||||
|
|
||||||
queryCriteria = None
|
queryCriteria = None
|
||||||
|
outputFields = ()
|
||||||
|
sortCriteria = ()
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, name):
|
def __init__(self, name):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
@ -87,9 +88,6 @@ class Report(Template):
|
||||||
def getQueryFields(self):
|
def getQueryFields(self):
|
||||||
return [f for f in self.fields if 'query' in f.executionSteps]
|
return [f for f in self.fields if 'query' in f.executionSteps]
|
||||||
|
|
||||||
def getSortFields(self):
|
|
||||||
return [f for f in self.fields if 'sort' in f.executionSteps]
|
|
||||||
|
|
||||||
def getOutputFields(self):
|
def getOutputFields(self):
|
||||||
return [f for f in self.fields if 'output' in f.executionSteps]
|
return [f for f in self.fields if 'output' in f.executionSteps]
|
||||||
|
|
||||||
|
@ -105,6 +103,20 @@ class Report(Template):
|
||||||
return [f for f in self.getOutputFields()
|
return [f for f in self.getOutputFields()
|
||||||
if f.name not in activeNames]
|
if f.name not in activeNames]
|
||||||
|
|
||||||
|
def getSortFields(self):
|
||||||
|
return [f for f in self.fields if 'sort' in f.executionSteps]
|
||||||
|
|
||||||
|
def getSortCriteria(self):
|
||||||
|
if not self.sortCriteria:
|
||||||
|
fieldNames = [f.name for f in self.getSortFields()]
|
||||||
|
return [f for f in self.defaultSortCriteria
|
||||||
|
if f.name in fieldNames]
|
||||||
|
return self.sortCriteria
|
||||||
|
|
||||||
|
def getAvailableSortFields(self):
|
||||||
|
sortCriteria = [f.name for f in self.getSortCriteria()]
|
||||||
|
return [f for f in self.getSortFields() if f.name not in sortCriteria]
|
||||||
|
|
||||||
def getPresentationFormats(self):
|
def getPresentationFormats(self):
|
||||||
return [dict(renderer='default', title='Default')]
|
return [dict(renderer='default', title='Default')]
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,10 @@ class Field(Component):
|
||||||
def name(self):
|
def name(self):
|
||||||
return self.__name__
|
return self.__name__
|
||||||
|
|
||||||
|
def getSortValue(self, row):
|
||||||
|
# TODO: consider 'descending' flag, use raw value instead of formatted one
|
||||||
|
return getattr(row, self.name)
|
||||||
|
|
||||||
|
|
||||||
label = Field('label', u'Label',
|
label = Field('label', u'Label',
|
||||||
u'A short text that identifies a row for humans.')
|
u'A short text that identifies a row for humans.')
|
||||||
|
|
51
composer/report/result.py
Normal file
51
composer/report/result.py
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
#
|
||||||
|
# Copyright (c) 2010 Helmut Merz helmutm@cy55.de
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
#
|
||||||
|
|
||||||
|
"""
|
||||||
|
Report result sets and related classes.
|
||||||
|
|
||||||
|
$Id$
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
class Row(object):
|
||||||
|
|
||||||
|
def __init__(self, context):
|
||||||
|
self.context = context
|
||||||
|
|
||||||
|
def __getattr__(self, attr):
|
||||||
|
return getattr(self.context, attr)
|
||||||
|
|
||||||
|
|
||||||
|
class ResultSet(object):
|
||||||
|
|
||||||
|
def __init__(self, context, data, rowFactory=Row, sortCriteria=None):
|
||||||
|
self.context = context
|
||||||
|
self.data = data
|
||||||
|
self.rowFactory = rowFactory
|
||||||
|
self.sortCriteria = sortCriteria
|
||||||
|
|
||||||
|
def getResult(self):
|
||||||
|
result = [self.rowFactory(item) for item in self.data]
|
||||||
|
if self.sortCriteria:
|
||||||
|
result.sort(key=lambda x: [f.getSortValue(x) for f in self.sortCriteria])
|
||||||
|
return result
|
||||||
|
|
||||||
|
def __iter__(self):
|
||||||
|
return iter(self.getResult())
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
#
|
#
|
||||||
# Copyright (c) 2008 Helmut Merz helmutm@cy55.de
|
# Copyright (c) 2010 Helmut Merz helmutm@cy55.de
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify
|
# This program is free software; you can redistribute it and/or modify
|
||||||
# it under the terms of the GNU General Public License as published by
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
@ -17,8 +17,10 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Example classes for the cybertools.reporter package. These use the
|
Result set and related classes for reporting.
|
||||||
cybertools.contact package
|
|
||||||
|
Now obsolete (but still used in some projects),
|
||||||
|
use cybertools.composer.report.result instead.
|
||||||
|
|
||||||
$Id$
|
$Id$
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Add table
Reference in a new issue