add definition for CalculatedField (direct attribute of row); use for sequential numbering of rows

This commit is contained in:
Helmut Merz 2012-02-11 15:56:44 +01:00
parent a7f54226d8
commit 1ec981f04a
2 changed files with 12 additions and 3 deletions

View file

@ -1,5 +1,5 @@
#
# Copyright (c) 2010 Helmut Merz helmutm@cy55.de
# Copyright (c) 2012 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
@ -18,8 +18,6 @@
"""
Implementation of report field definitions.
$Id$
"""
from datetime import datetime
@ -93,6 +91,14 @@ class Field(Component):
#return self.getValue(row)
class CalculatedField(Field):
def getRawValue(self, row):
return getattr(row, self.name)
# sample field
label = Field('label', u'Label',
u'A short text that identifies a row for humans.')

View file

@ -33,6 +33,7 @@ class BaseRow(object):
self.context = context
self.parent = parent
self.data = {}
self.sequenceNumber = 0
def __getattr__(self, attr):
f = self.parent.context.fields[attr]
@ -71,6 +72,8 @@ class ResultSet(object):
result = [row for row in result if self.queryCriteria.check(row)]
if self.sortCriteria:
result.sort(key=lambda x: [f.getSortValue(x) for f in self.sortCriteria])
for idx, row in enumerate(result):
row.sequenceNumber = idx + 1
return result
def __iter__(self):