work in progress: reporting
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@3867 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
d9c8ee3587
commit
2e61afc21a
3 changed files with 23 additions and 4 deletions
|
@ -85,6 +85,10 @@ class Report(Template):
|
|||
def __init__(self, name):
|
||||
self.name = name
|
||||
|
||||
@property
|
||||
def components(self):
|
||||
return self.fields
|
||||
|
||||
def getQueryFields(self):
|
||||
return [f for f in self.fields if 'query' in f.executionSteps]
|
||||
|
||||
|
|
|
@ -42,6 +42,7 @@ class Field(Component):
|
|||
vocabulary = None
|
||||
default = None
|
||||
instance_name = None
|
||||
storeData = True
|
||||
|
||||
executionSteps = ['query', 'sort', 'output']
|
||||
|
||||
|
@ -59,9 +60,17 @@ class Field(Component):
|
|||
def name(self):
|
||||
return self.__name__
|
||||
|
||||
def getValue(self, row):
|
||||
value = getattr(row.context, self.name)
|
||||
if value is None:
|
||||
return u''
|
||||
if isinstance(value, basestring):
|
||||
return value
|
||||
return getattr(value, 'title', str(value))
|
||||
|
||||
def getSortValue(self, row):
|
||||
# TODO: consider 'descending' flag, use raw value instead of formatted one
|
||||
return getattr(row, self.name)
|
||||
return self.getValue(row)
|
||||
|
||||
|
||||
label = Field('label', u'Label',
|
||||
|
|
|
@ -22,14 +22,20 @@ Report result sets and related classes.
|
|||
$Id$
|
||||
"""
|
||||
|
||||
from zope.cachedescriptors.property import Lazy
|
||||
|
||||
from cybertools.composer.interfaces import IInstance
|
||||
|
||||
|
||||
class Row(object):
|
||||
|
||||
def __init__(self, context):
|
||||
def __init__(self, context, parent):
|
||||
self.context = context
|
||||
self.parent = parent
|
||||
|
||||
def __getattr__(self, attr):
|
||||
return getattr(self.context, attr)
|
||||
f = self.parent.context.fields[attr]
|
||||
return f.getValue(self)
|
||||
|
||||
|
||||
class ResultSet(object):
|
||||
|
@ -41,7 +47,7 @@ class ResultSet(object):
|
|||
self.sortCriteria = sortCriteria
|
||||
|
||||
def getResult(self):
|
||||
result = [self.rowFactory(item) for item in self.data]
|
||||
result = [self.rowFactory(item, self) for item in self.data]
|
||||
if self.sortCriteria:
|
||||
result.sort(key=lambda x: [f.getSortValue(x) for f in self.sortCriteria])
|
||||
return result
|
||||
|
|
Loading…
Add table
Reference in a new issue