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" | ||||
|         permission="zope.View" /> | ||||
| 
 | ||||
|   <browser:page | ||||
|         name="concept_results.csv" | ||||
|         for="loops.organize.interfaces.IConceptSchema" | ||||
|         class="loops.expert.browser.export.ResultsConceptCSVExport" | ||||
|         permission="zope.View" /> | ||||
| 
 | ||||
| </configure> | ||||
|  |  | |||
|  | @ -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 '???' | ||||
| 
 | ||||
|  |  | |||
|  | @ -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] | ||||
| 
 | ||||
|  |  | |||
|  | @ -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 | ||||
| 
 | ||||
|  |  | |||
|  | @ -23,12 +23,6 @@ | |||
|         factory="loops.knowledge.qualification.browser.Qualifications" | ||||
|         permission="zope.View" /> | ||||
| 
 | ||||
|   <browser:page | ||||
|       name="qualifications.csv" | ||||
|       for="loops.organize.interfaces.IConceptSchema" | ||||
|       class="loops.knowledge.qualification.browser.QualificationsCSVExport" | ||||
|       permission="zope.View" /> | ||||
| 
 | ||||
|   <!-- reports --> | ||||
| 
 | ||||
|   <zope:adapter  | ||||
|  |  | |||
		Loading…
	
	Add table
		
		Reference in a new issue