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.
 | 
					Basic classes for report management.
 | 
				
			||||||
 | 
					 | 
				
			||||||
$Id$
 | 
					 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import operator as standard_operators
 | 
					import operator as standard_operators
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -70,7 +70,7 @@ class Field(Component):
 | 
				
			||||||
        return self.__name__
 | 
					        return self.__name__
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def getRawValue(self, row):
 | 
					    def getRawValue(self, row):
 | 
				
			||||||
        return getattr(row.context, self.name)
 | 
					        return row.getRawValue(self.name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def getSelectValue(self, row):
 | 
					    def getSelectValue(self, row):
 | 
				
			||||||
        return getattr(row, self.name, None)
 | 
					        return getattr(row, self.name, None)
 | 
				
			||||||
| 
						 | 
					@ -84,6 +84,9 @@ class Field(Component):
 | 
				
			||||||
            return value
 | 
					            return value
 | 
				
			||||||
        return getattr(value, 'title', str(value))
 | 
					        return getattr(value, 'title', str(value))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def getDisplayValue(self, row):
 | 
				
			||||||
 | 
					        return self.getValue(row)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def getSortValue(self, row):
 | 
					    def getSortValue(self, row):
 | 
				
			||||||
        # TODO: consider 'descending' flag, use raw value instead of formatted one
 | 
					        # TODO: consider 'descending' flag, use raw value instead of formatted one
 | 
				
			||||||
        return getattr(row, self.name, None)
 | 
					        return getattr(row, self.name, None)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,8 +18,6 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
Report result sets and related classes.
 | 
					Report result sets and related classes.
 | 
				
			||||||
 | 
					 | 
				
			||||||
$Id$
 | 
					 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from zope.cachedescriptors.property import Lazy
 | 
					from zope.cachedescriptors.property import Lazy
 | 
				
			||||||
| 
						 | 
					@ -28,8 +26,14 @@ 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 Row(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
 | 
				
			||||||
| 
						 | 
					@ -38,12 +42,15 @@ class Row(object):
 | 
				
			||||||
        f = self.parent.context.fields[attr]
 | 
					        f = self.parent.context.fields[attr]
 | 
				
			||||||
        return f.getValue(self)
 | 
					        return f.getValue(self)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def getRawValue(self, attr):
 | 
				
			||||||
 | 
					        return self.attributeHandlers.get(attr, getContextAttr)(self, attr)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ResultSet(object):
 | 
					class ResultSet(object):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def __init__(self, context, data, rowFactory=Row,
 | 
					    def __init__(self, context, data, rowFactory=Row,
 | 
				
			||||||
                 sortCriteria=None, queryCriteria=BaseQueryCriteria()):
 | 
					                 sortCriteria=None, queryCriteria=BaseQueryCriteria()):
 | 
				
			||||||
        self.context = context
 | 
					        self.context = context  # the report or report instance
 | 
				
			||||||
        self.data = data
 | 
					        self.data = data
 | 
				
			||||||
        self.rowFactory = rowFactory
 | 
					        self.rowFactory = rowFactory
 | 
				
			||||||
        self.sortCriteria = sortCriteria
 | 
					        self.sortCriteria = sortCriteria
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -18,8 +18,6 @@
 | 
				
			||||||
 | 
					
 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
Date and time utilities.
 | 
					Date and time utilities.
 | 
				
			||||||
 | 
					 | 
				
			||||||
$Id$
 | 
					 | 
				
			||||||
"""
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import time
 | 
					import time
 | 
				
			||||||
| 
						 | 
					@ -30,6 +28,11 @@ def getTimeStamp():
 | 
				
			||||||
    return int(time.time())
 | 
					    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'):
 | 
					def timeStamp2ISO(ts, useGM=False, format='%Y-%m-%d %H:%M'):
 | 
				
			||||||
    return formatTimeStamp(ts, useGM, format)
 | 
					    return formatTimeStamp(ts, useGM, format)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -38,8 +41,6 @@ def formatTimeStamp(ts, useGM=False, format='%Y-%m-%d %H:%M'):
 | 
				
			||||||
        ts = getTimeStamp()
 | 
					        ts = getTimeStamp()
 | 
				
			||||||
    fct = useGM and time.gmtime or time.localtime
 | 
					    fct = useGM and time.gmtime or time.localtime
 | 
				
			||||||
    return time.strftime(format, fct(ts))
 | 
					    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):
 | 
					def str2timeStamp(s):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		
		Reference in a new issue