From 67b969a481c597cff0c046466a1bfd42e060892a Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Mon, 9 Jul 2012 10:23:03 +0200 Subject: [PATCH 1/2] add attribute 'userSetting' for specifying column specifications that may be edited by the user; extend interface definition to resemble currently used attributes --- composer/report/base.py | 1 + composer/report/interfaces.py | 25 +++++++++++++++++-------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/composer/report/base.py b/composer/report/base.py index eb171f7..712a22f 100644 --- a/composer/report/base.py +++ b/composer/report/base.py @@ -74,6 +74,7 @@ class Report(Template): fields = Jeep((field.label,)) hiddenQueryFields = () + userSettings = (field.label,) defaultOutputFields = (field.label,) defaultSortCriteria = (field.label,) presentationFormat = None diff --git a/composer/report/interfaces.py b/composer/report/interfaces.py index 5d2b42c..0ccd19d 100644 --- a/composer/report/interfaces.py +++ b/composer/report/interfaces.py @@ -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 @@ """ Report management. - -$Id$ """ from zope.interface import Interface, Attribute @@ -60,10 +58,11 @@ class IReportParams(Interface): queryCriteria = Attribute('The criteria to be used for executing the ' 'query step.') - sortSpec = Attribute('A sequence of fields/sort directions to be used for ' - 'executing the sorting step.') - outputSpec = Attribute('A sequence of output fields (column/cell ' - 'specifications) to be used for presenting the result data.') + sortCriteria = Attribute('A sequence of fields/sort directions to be ' + 'used for executing the sorting step.') + outputFields = Attribute('A sequence of output fields (column/cell ' + 'specifications) to be used for presenting the result ' + 'data.') class IReport(ITemplate, IReportParams): @@ -97,11 +96,21 @@ class IReport(ITemplate, IReportParams): required=False,) manager = Attribute('The manager of this message object') - fields = Attribute('An ordered collection of all field definitions ' 'available for this report type.') + hiddenQueryFields = Attribute('Fields used for query criteria ' + 'that are not shown to/editable by the user, ' + 'e.g. because they are determined automatically.') + userSettings = Attribute('Fields that can be set by the user.') + defaultOutputFields = Attribute('Predefined output columns.') + defaultSortCriteria = Attribute('Predefined sort columns.') + presentationFormat = Attribute('Selected presentation format.') renderers = Attribute('An ordered collection of renderers available ' 'for this report type.') + limits = Attribute('A pair of integers that specify the slice ' + '(i.e. start and stop values) that has to be taken ' + 'from the sorted result set for output.') + def getQueryFields(): """ Return a sequence of fields that may be used for setting up From b63b3b3b164c12fc6b5741f4d7d55fd067746540 Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Mon, 9 Jul 2012 16:30:36 +0200 Subject: [PATCH 2/2] make sure query criteria is a number for a 'number' field --- composer/report/base.py | 3 +++ composer/report/field.py | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/composer/report/base.py b/composer/report/base.py index 712a22f..e591be2 100644 --- a/composer/report/base.py +++ b/composer/report/base.py @@ -162,6 +162,9 @@ class LeafQueryCriteria(BaseQueryCriteria, Element): if comparisonValue in (None, '',): return True value = self.field.getSelectValue(row) + if (self.field.fieldType == 'number' and + isinstance(comparisonValue, basestring)): + comparisonValue = int(comparisonValue) op = operators.get(self.operator) if op is None: op = getattr(standard_operators, self.operator, None) diff --git a/composer/report/field.py b/composer/report/field.py index ae689ac..03319d1 100644 --- a/composer/report/field.py +++ b/composer/report/field.py @@ -72,8 +72,8 @@ class Field(Component): return row.getRawValue(self.name) def getSelectValue(self, row): - return getattr(row, self.name, None) - #return self.getRawValue(row) # better let row control selection... + return getattr(row, self.name, None) # backwards compatibility + # return self.getRawValue(row) # overwrite with this in subclass def getValue(self, row): value = self.getRawValue(row)