consequently use reporting view base class instead of specialized class; + other improvements
This commit is contained in:
		
							parent
							
								
									74eb054bc9
								
							
						
					
					
						commit
						82645fb574
					
				
					 5 changed files with 29 additions and 12 deletions
				
			
		|  | @ -99,4 +99,10 @@ | ||||||
|         factory="loops.expert.browser.report.EmbeddedResultsConceptView" |         factory="loops.expert.browser.report.EmbeddedResultsConceptView" | ||||||
|         permission="zope.View" /> |         permission="zope.View" /> | ||||||
| 
 | 
 | ||||||
|  |   <browser:page | ||||||
|  |         name="concept_results.csv" | ||||||
|  |         for="loops.organize.interfaces.IConceptSchema" | ||||||
|  |         class="loops.expert.browser.export.ResultsConceptCSVExport" | ||||||
|  |         permission="zope.View" /> | ||||||
|  | 
 | ||||||
| </configure> | </configure> | ||||||
|  |  | ||||||
|  | @ -69,8 +69,7 @@ class ResultsConceptCSVExport(ResultsConceptView): | ||||||
|                 value = f.getValue(row) |                 value = f.getValue(row) | ||||||
|                 if ILoopsObject.providedBy(value): |                 if ILoopsObject.providedBy(value): | ||||||
|                     value = value.title |                     value = value.title | ||||||
|                 if isinstance(value, unicode): |                 value = encode(value, self.encoding) | ||||||
|                     value = value.encode(self.encoding) |  | ||||||
|                 data[f.name] = value |                 data[f.name] = value | ||||||
|             writer.writerow(data) |             writer.writerow(data) | ||||||
|         text = output.getvalue() |         text = output.getvalue() | ||||||
|  | @ -86,3 +85,20 @@ class ResultsConceptCSVExport(ResultsConceptView): | ||||||
|         response.setHeader('Pragma', '') |         response.setHeader('Pragma', '') | ||||||
|         response.setHeader('Content-Type', 'text/csv') |         response.setHeader('Content-Type', 'text/csv') | ||||||
|         response.setHeader('Content-Length', len(text)) |         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 '???' | ||||||
|  | 
 | ||||||
|  |  | ||||||
|  | @ -193,6 +193,8 @@ class ResultsConceptView(ConceptView): | ||||||
|     @Lazy |     @Lazy | ||||||
|     def downloadLink(self, format='csv'): |     def downloadLink(self, format='csv'): | ||||||
|         opt = self.options('download_' + format) |         opt = self.options('download_' + format) | ||||||
|  |         if not opt: | ||||||
|  |             opt = self.typeOptions('download_' + format) | ||||||
|         if opt: |         if opt: | ||||||
|             return opt[0] |             return opt[0] | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -34,10 +34,9 @@ from loops.util import _ | ||||||
| 
 | 
 | ||||||
| class Qualifications(ResultsConceptView): | class Qualifications(ResultsConceptView): | ||||||
| 
 | 
 | ||||||
|     reportName = 'qualification_overview' |     # obsolete because we can directly use ResultsConceptView | ||||||
| 
 | 
 | ||||||
|  |     #reportName = 'qualification_overview' | ||||||
| 
 | 
 | ||||||
| class QualificationsCSVExport(ResultsConceptCSVExport): |     pass    # report assigned to query via hasReport relation | ||||||
| 
 |  | ||||||
|     reportName = 'qualification_overview' |  | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -23,12 +23,6 @@ | ||||||
|         factory="loops.knowledge.qualification.browser.Qualifications" |         factory="loops.knowledge.qualification.browser.Qualifications" | ||||||
|         permission="zope.View" /> |         permission="zope.View" /> | ||||||
| 
 | 
 | ||||||
|   <browser:page |  | ||||||
|       name="qualifications.csv" |  | ||||||
|       for="loops.organize.interfaces.IConceptSchema" |  | ||||||
|       class="loops.knowledge.qualification.browser.QualificationsCSVExport" |  | ||||||
|       permission="zope.View" /> |  | ||||||
| 
 |  | ||||||
|   <!-- reports --> |   <!-- reports --> | ||||||
| 
 | 
 | ||||||
|   <zope:adapter  |   <zope:adapter  | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue