introduce special Style class; implement grouping via sequential access
This commit is contained in:
parent
cd97e6787e
commit
ec5e832dd6
2 changed files with 47 additions and 13 deletions
|
@ -33,6 +33,33 @@ from cybertools.composer.report.interfaces import IField
|
|||
from cybertools.composer.report.interfaces import fieldTypes
|
||||
|
||||
|
||||
class Style(object):
|
||||
|
||||
initData = {}
|
||||
|
||||
def __getitem__(self, k):
|
||||
return self.data[k]
|
||||
|
||||
def __init__(self, **kw):
|
||||
self.data = dict(self.initData)
|
||||
self.data.update(kw)
|
||||
|
||||
def __str__(self):
|
||||
return ';'.join('%s: %s' % (k, v) for k, v in self.data.items())
|
||||
|
||||
|
||||
class TableCellStyle(Style):
|
||||
|
||||
initData = dict(
|
||||
width='auto',
|
||||
textalign='left',
|
||||
bordertop='1px solid #000',
|
||||
borderright='1px solid #000',
|
||||
borderbottom='1px solid #000',
|
||||
borderleft='1px solid #000',
|
||||
)
|
||||
|
||||
|
||||
class Field(Component):
|
||||
|
||||
implements(IField)
|
||||
|
@ -49,6 +76,7 @@ class Field(Component):
|
|||
outputWith = ()
|
||||
colspan=1
|
||||
colheaderspan=1
|
||||
style = TableCellStyle()
|
||||
colwidth='auto'
|
||||
coltextalign='left'
|
||||
colbordertop='1px solid #000'
|
||||
|
|
|
@ -81,27 +81,33 @@ class ResultSet(object):
|
|||
headerRow = self.headerRowFactory(None, self)
|
||||
for c in columns:
|
||||
if c.output:
|
||||
headerRow.data[c.output] = c.getDisplayValue(result[idx])
|
||||
#headerRow.data[c.output] = c.getRawValue(result[idx])
|
||||
headerRow.data[c.output] = c.getRawValue(result[idx])
|
||||
result.insert(idx, headerRow)
|
||||
|
||||
def getHeaderRow(self, row, columns):
|
||||
headerRow = self.headerRowFactory(None, self)
|
||||
for c in columns:
|
||||
if c.output:
|
||||
headerRow.data[c.output] = c.getRawValue(row)
|
||||
return headerRow
|
||||
|
||||
def getResult(self):
|
||||
result = [self.rowFactory(item, self) for item in self.data]
|
||||
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])
|
||||
if self.groupColumns:
|
||||
for idx, row in enumerate(result):
|
||||
insert = []
|
||||
for f in self.groupColumns:
|
||||
output = [f] + f.outputWith
|
||||
if idx == 0:
|
||||
insert.append(output)
|
||||
else:
|
||||
if (result[idx].getRawValue(f.name) !=
|
||||
result[idx-1].getRawValue(f.name)):
|
||||
insert.append(output)
|
||||
for output in insert:
|
||||
self.insertHeaderRow(idx, result, output)
|
||||
res = []
|
||||
groupValues = [None for f in self.groupColumns]
|
||||
for row in result:
|
||||
for idx, f in enumerate(self.groupColumns):
|
||||
value = f.getRawValue(row)
|
||||
if value != groupValues[idx]:
|
||||
groupValues[idx] = value
|
||||
res.append(self.getHeaderRow(row, (f,) + f.outputWith))
|
||||
res.append(row)
|
||||
result = res
|
||||
for idx, row in enumerate(result):
|
||||
row.sequenceNumber = idx + 1
|
||||
return result
|
||||
|
|
Loading…
Add table
Reference in a new issue