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
|
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):
|
class Field(Component):
|
||||||
|
|
||||||
implements(IField)
|
implements(IField)
|
||||||
|
@ -49,6 +76,7 @@ class Field(Component):
|
||||||
outputWith = ()
|
outputWith = ()
|
||||||
colspan=1
|
colspan=1
|
||||||
colheaderspan=1
|
colheaderspan=1
|
||||||
|
style = TableCellStyle()
|
||||||
colwidth='auto'
|
colwidth='auto'
|
||||||
coltextalign='left'
|
coltextalign='left'
|
||||||
colbordertop='1px solid #000'
|
colbordertop='1px solid #000'
|
||||||
|
|
|
@ -81,27 +81,33 @@ class ResultSet(object):
|
||||||
headerRow = self.headerRowFactory(None, self)
|
headerRow = self.headerRowFactory(None, self)
|
||||||
for c in columns:
|
for c in columns:
|
||||||
if c.output:
|
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)
|
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):
|
def getResult(self):
|
||||||
result = [self.rowFactory(item, self) for item in self.data]
|
result = [self.rowFactory(item, self) for item in self.data]
|
||||||
result = [row for row in result if self.queryCriteria.check(row)]
|
result = [row for row in result if self.queryCriteria.check(row)]
|
||||||
if self.sortCriteria:
|
if self.sortCriteria:
|
||||||
result.sort(key=lambda x: [f.getSortValue(x) for f in self.sortCriteria])
|
result.sort(key=lambda x: [f.getSortValue(x) for f in self.sortCriteria])
|
||||||
if self.groupColumns:
|
if self.groupColumns:
|
||||||
for idx, row in enumerate(result):
|
res = []
|
||||||
insert = []
|
groupValues = [None for f in self.groupColumns]
|
||||||
for f in self.groupColumns:
|
for row in result:
|
||||||
output = [f] + f.outputWith
|
for idx, f in enumerate(self.groupColumns):
|
||||||
if idx == 0:
|
value = f.getRawValue(row)
|
||||||
insert.append(output)
|
if value != groupValues[idx]:
|
||||||
else:
|
groupValues[idx] = value
|
||||||
if (result[idx].getRawValue(f.name) !=
|
res.append(self.getHeaderRow(row, (f,) + f.outputWith))
|
||||||
result[idx-1].getRawValue(f.name)):
|
res.append(row)
|
||||||
insert.append(output)
|
result = res
|
||||||
for output in insert:
|
|
||||||
self.insertHeaderRow(idx, result, output)
|
|
||||||
for idx, row in enumerate(result):
|
for idx, row in enumerate(result):
|
||||||
row.sequenceNumber = idx + 1
|
row.sequenceNumber = idx + 1
|
||||||
return result
|
return result
|
||||||
|
|
Loading…
Add table
Reference in a new issue