From 82645fb574e106093b29d33d3e3fb3a828cbb41a Mon Sep 17 00:00:00 2001 From: Helmut Merz Date: Fri, 20 Mar 2015 11:38:47 +0100 Subject: [PATCH] consequently use reporting view base class instead of specialized class; + other improvements --- expert/browser/configure.zcml | 6 ++++++ expert/browser/export.py | 20 ++++++++++++++++++-- expert/browser/report.py | 2 ++ knowledge/qualification/browser.py | 7 +++---- knowledge/qualification/configure.zcml | 6 ------ 5 files changed, 29 insertions(+), 12 deletions(-) diff --git a/expert/browser/configure.zcml b/expert/browser/configure.zcml index e5804f2..95244a8 100644 --- a/expert/browser/configure.zcml +++ b/expert/browser/configure.zcml @@ -99,4 +99,10 @@ factory="loops.expert.browser.report.EmbeddedResultsConceptView" permission="zope.View" /> + + diff --git a/expert/browser/export.py b/expert/browser/export.py index 85f2305..41870d4 100644 --- a/expert/browser/export.py +++ b/expert/browser/export.py @@ -69,8 +69,7 @@ class ResultsConceptCSVExport(ResultsConceptView): value = f.getValue(row) if ILoopsObject.providedBy(value): value = value.title - if isinstance(value, unicode): - value = value.encode(self.encoding) + value = encode(value, self.encoding) data[f.name] = value writer.writerow(data) text = output.getvalue() @@ -86,3 +85,20 @@ class ResultsConceptCSVExport(ResultsConceptView): response.setHeader('Pragma', '') response.setHeader('Content-Type', 'text/csv') response.setHeader('Content-Length', len(text)) + + +def encode(text, encoding): + if not isinstance(text, unicode): + return text + try: + return text.encode(encoding) + except UnicodeEncodeError: + result = [] + for c in text: + try: + result.append(c.encode(encoding)) + except UnicodeEncodeError: + result.append('?') + return ''.join(result) + return '???' + diff --git a/expert/browser/report.py b/expert/browser/report.py index 395d5f3..b8e1216 100644 --- a/expert/browser/report.py +++ b/expert/browser/report.py @@ -193,6 +193,8 @@ class ResultsConceptView(ConceptView): @Lazy def downloadLink(self, format='csv'): opt = self.options('download_' + format) + if not opt: + opt = self.typeOptions('download_' + format) if opt: return opt[0] diff --git a/knowledge/qualification/browser.py b/knowledge/qualification/browser.py index 5c0a061..4a98f70 100644 --- a/knowledge/qualification/browser.py +++ b/knowledge/qualification/browser.py @@ -34,10 +34,9 @@ from loops.util import _ class Qualifications(ResultsConceptView): - reportName = 'qualification_overview' + # obsolete because we can directly use ResultsConceptView + #reportName = 'qualification_overview' -class QualificationsCSVExport(ResultsConceptCSVExport): - - reportName = 'qualification_overview' + pass # report assigned to query via hasReport relation diff --git a/knowledge/qualification/configure.zcml b/knowledge/qualification/configure.zcml index b6a1a5e..e4f02c9 100644 --- a/knowledge/qualification/configure.zcml +++ b/knowledge/qualification/configure.zcml @@ -23,12 +23,6 @@ factory="loops.knowledge.qualification.browser.Qualifications" permission="zope.View" /> - -