define row data for report totals
This commit is contained in:
parent
a33f17faf0
commit
add1a31bae
2 changed files with 18 additions and 8 deletions
|
@ -47,7 +47,7 @@ class Field(Component):
|
||||||
renderer = 'standard'
|
renderer = 'standard'
|
||||||
operator = 'in'
|
operator = 'in'
|
||||||
|
|
||||||
executionSteps = ['query', 'sort', 'output']
|
executionSteps = ['query', 'sort', 'output'] # , 'totals']
|
||||||
|
|
||||||
operators = [{'token': 'eq', 'label': '=='},
|
operators = [{'token': 'eq', 'label': '=='},
|
||||||
{'token': 'lt', 'label': '<'},
|
{'token': 'lt', 'label': '<'},
|
||||||
|
|
|
@ -26,24 +26,33 @@ from cybertools.composer.interfaces import IInstance
|
||||||
from cybertools.composer.report.base import BaseQueryCriteria
|
from cybertools.composer.report.base import BaseQueryCriteria
|
||||||
|
|
||||||
|
|
||||||
def getContextAttr(obj, attr):
|
|
||||||
return getattr(obj.context, attr)
|
|
||||||
|
|
||||||
|
class BaseRow(object):
|
||||||
class Row(object):
|
|
||||||
|
|
||||||
attributeHandlers = {}
|
|
||||||
|
|
||||||
def __init__(self, context, parent):
|
def __init__(self, context, parent):
|
||||||
self.context = context
|
self.context = context
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
|
self.data = {}
|
||||||
|
|
||||||
def __getattr__(self, attr):
|
def __getattr__(self, attr):
|
||||||
f = self.parent.context.fields[attr]
|
f = self.parent.context.fields[attr]
|
||||||
return f.getValue(self)
|
return f.getValue(self)
|
||||||
|
|
||||||
def getRawValue(self, attr):
|
def getRawValue(self, attr):
|
||||||
return self.attributeHandlers.get(attr, getContextAttr)(self, attr)
|
return self.data.get(attr)
|
||||||
|
|
||||||
|
|
||||||
|
class Row(BaseRow):
|
||||||
|
|
||||||
|
attributeHandlers = {}
|
||||||
|
|
||||||
|
def getRawValue(self, attr):
|
||||||
|
return self.attributeHandlers.get(attr, Row.getContextAttr)(self, attr)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def getContextAttr(obj, attr):
|
||||||
|
return getattr(obj.context, attr)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class ResultSet(object):
|
class ResultSet(object):
|
||||||
|
@ -55,6 +64,7 @@ class ResultSet(object):
|
||||||
self.rowFactory = rowFactory
|
self.rowFactory = rowFactory
|
||||||
self.sortCriteria = sortCriteria
|
self.sortCriteria = sortCriteria
|
||||||
self.queryCriteria = queryCriteria
|
self.queryCriteria = queryCriteria
|
||||||
|
self.totals = BaseRow(None, self)
|
||||||
|
|
||||||
def getResult(self):
|
def getResult(self):
|
||||||
result = [self.rowFactory(item, self) for item in self.data]
|
result = [self.rowFactory(item, self) for item in self.data]
|
||||||
|
|
Loading…
Add table
Reference in a new issue