continuous improvement and extension of reporting facilities
This commit is contained in:
parent
cce0993684
commit
a33f17faf0
4 changed files with 19 additions and 10 deletions
|
@ -18,8 +18,6 @@
|
|||
|
||||
"""
|
||||
Basic classes for report management.
|
||||
|
||||
$Id$
|
||||
"""
|
||||
|
||||
import operator as standard_operators
|
||||
|
|
|
@ -70,7 +70,7 @@ class Field(Component):
|
|||
return self.__name__
|
||||
|
||||
def getRawValue(self, row):
|
||||
return getattr(row.context, self.name)
|
||||
return row.getRawValue(self.name)
|
||||
|
||||
def getSelectValue(self, row):
|
||||
return getattr(row, self.name, None)
|
||||
|
@ -84,6 +84,9 @@ class Field(Component):
|
|||
return value
|
||||
return getattr(value, 'title', str(value))
|
||||
|
||||
def getDisplayValue(self, row):
|
||||
return self.getValue(row)
|
||||
|
||||
def getSortValue(self, row):
|
||||
# TODO: consider 'descending' flag, use raw value instead of formatted one
|
||||
return getattr(row, self.name, None)
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
|
||||
"""
|
||||
Report result sets and related classes.
|
||||
|
||||
$Id$
|
||||
"""
|
||||
|
||||
from zope.cachedescriptors.property import Lazy
|
||||
|
@ -28,8 +26,14 @@ from cybertools.composer.interfaces import IInstance
|
|||
from cybertools.composer.report.base import BaseQueryCriteria
|
||||
|
||||
|
||||
def getContextAttr(obj, attr):
|
||||
return getattr(obj.context, attr)
|
||||
|
||||
|
||||
class Row(object):
|
||||
|
||||
attributeHandlers = {}
|
||||
|
||||
def __init__(self, context, parent):
|
||||
self.context = context
|
||||
self.parent = parent
|
||||
|
@ -38,12 +42,15 @@ class Row(object):
|
|||
f = self.parent.context.fields[attr]
|
||||
return f.getValue(self)
|
||||
|
||||
def getRawValue(self, attr):
|
||||
return self.attributeHandlers.get(attr, getContextAttr)(self, attr)
|
||||
|
||||
|
||||
class ResultSet(object):
|
||||
|
||||
def __init__(self, context, data, rowFactory=Row,
|
||||
sortCriteria=None, queryCriteria=BaseQueryCriteria()):
|
||||
self.context = context
|
||||
self.context = context # the report or report instance
|
||||
self.data = data
|
||||
self.rowFactory = rowFactory
|
||||
self.sortCriteria = sortCriteria
|
||||
|
|
|
@ -18,8 +18,6 @@
|
|||
|
||||
"""
|
||||
Date and time utilities.
|
||||
|
||||
$Id$
|
||||
"""
|
||||
|
||||
import time
|
||||
|
@ -30,6 +28,11 @@ def getTimeStamp():
|
|||
return int(time.time())
|
||||
|
||||
|
||||
def timeStamp2Date(ts, useGM=False):
|
||||
if ts is None:
|
||||
ts = getTimeStamp()
|
||||
return datetime.fromtimestamp(ts)
|
||||
|
||||
def timeStamp2ISO(ts, useGM=False, format='%Y-%m-%d %H:%M'):
|
||||
return formatTimeStamp(ts, useGM, format)
|
||||
|
||||
|
@ -38,8 +41,6 @@ def formatTimeStamp(ts, useGM=False, format='%Y-%m-%d %H:%M'):
|
|||
ts = getTimeStamp()
|
||||
fct = useGM and time.gmtime or time.localtime
|
||||
return time.strftime(format, fct(ts))
|
||||
#return time.strftime('%Y-%m-%d %H:%M', time.gmtime(ts))
|
||||
#return time.strftime('%Y-%m-%d %H:%M', time.localtime(ts))
|
||||
|
||||
|
||||
def str2timeStamp(s):
|
||||
|
|
Loading…
Add table
Reference in a new issue