From 8915a22bdab1899e1ddb015471e6994416282c9f Mon Sep 17 00:00:00 2001 From: hplattner Date: Wed, 7 Aug 2013 11:02:50 +0200 Subject: [PATCH] only generate subTotalsRows for totals fields with corresponding group field --- .gitignore | 2 ++ composer/report/base.py | 2 +- composer/report/result.py | 32 ++++++++++++++++---------------- 3 files changed, 19 insertions(+), 17 deletions(-) mode change 100644 => 100755 composer/report/result.py diff --git a/.gitignore b/.gitignore index e02b8ec..df07c09 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ ajax/dojo/* *.project *.pydevproject +*.sublime-project +*.sublime-workspace diff --git a/composer/report/base.py b/composer/report/base.py index 61cd7c9..31660f4 100644 --- a/composer/report/base.py +++ b/composer/report/base.py @@ -186,7 +186,7 @@ class LeafQueryCriteria(BaseQueryCriteria, Element): if comparisonValue in (None, '',): return True value = self.field.getSelectValue(row) - if (self.field.fieldType == 'number' and + if (self.field.fieldType == 'number' and isinstance(comparisonValue, basestring)): comparisonValue = int(comparisonValue) op = operators.get(self.operator) diff --git a/composer/report/result.py b/composer/report/result.py old mode 100644 new mode 100755 index 7f5dd4f..c6cb8de --- a/composer/report/result.py +++ b/composer/report/result.py @@ -61,7 +61,7 @@ class Row(BaseRow): @Lazy def displayedColumns(self): return self.parent.context.getActiveOutputFields() - + @Lazy def allColumns(self): return self.parent.context.getAllFields() @@ -121,8 +121,10 @@ class ResultSet(object): headerColumn.cssClass = c.cssClass headerRow.headerColumns.append(headerColumn) return headerRow - + def getSubTotalsRow(self, gf, row, columns, values): + if not gf.name in [','.join(c.totals) for c in columns]: + return None subTotalsRow = SubTotalsRow(None, self) subTotalsRow.cssClass = 'subTotalsRow' for idx, c in enumerate(columns): @@ -131,8 +133,10 @@ class ResultSet(object): if gf.totalsDescription is None: subTotalsRow.data[gf.output] = u'SUMME: ' + gf.getDisplayValue(row) else: - subTotalsRow.data[gf.totalsDescription.output] = u'SUMME: ' + \ - gf.totalsDescription.getDisplayValue(row) + v = gf.totalsDescription.getDisplayValue(row) + if v is None: + v = u'' + subTotalsRow.data[gf.totalsDescription.output] = u'SUMME: ' + v return subTotalsRow def getResult(self): @@ -158,12 +162,10 @@ class ResultSet(object): groupValues[idx] = value headerRows.append(self.getHeaderRow(row, (f,) + f.outputWith)) if lastRow is not None and f.getDisplayValue(lastRow): - subTotalsRows.append( - self.getSubTotalsRow(f, - lastRow, - self.subTotalsColumns[idx], - subTotals[idx] - )) + subTr = self.getSubTotalsRow(f, lastRow, + self.subTotalsColumns[idx], subTotals[idx]) + if subTr is not None: + subTotalsRows.append(subTr) subTotals[idx] = [0.0 for f in self.subTotalsColumns[idx]] for subTotalsRow in reversed(subTotalsRows): res.append(subTotalsRow) @@ -178,12 +180,10 @@ class ResultSet(object): subTotalsRows = [] for idx, f in enumerate(self.groupColumns): if f.getDisplayValue(lastRow): - subTotalsRows.append( - self.getSubTotalsRow(f, - lastRow, - self.subTotalsColumns[idx], - subTotals[idx] - )) + subTr = self.getSubTotalsRow(f, lastRow, + self.subTotalsColumns[idx], subTotals[idx]) + if subTr is not None: + subTotalsRows.append(subTr) for subTotalsRow in reversed(subTotalsRows): res.append(subTotalsRow) result = res