Changeset 9032
- Timestamp:
- 21 Jul 2012, 08:16:03 (12 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/browser/pages.py
r9025 r9032 914 914 return open(fullpath, 'rb').read() 915 915 916 class SkeletonDownloadView(UtilityView, grok.View): 917 grok.context(IDataCenter) 918 grok.name('skeleton') 919 grok.require('waeup.manageDataCenter') 920 921 def update(self, processorname=None): 922 self.processorname = self.request.form['name'] 923 self.filename = ('%s_000.csv' % 924 self.processorname.replace('processor','import')) 925 return 926 927 def render(self): 928 #ob_class = self.__implemented__.__name__.replace('waeup.kofa.','') 929 #self.context.logger.info( 930 # '%s - skeleton downloaded: %s' % (ob_class, self.filename)) 931 self.response.setHeader( 932 'Content-Type', 'text/csv; charset=UTF-8') 933 self.response.setHeader( 934 'Content-Disposition:', 'attachment; filename="%s' % self.filename) 935 processor = getUtility(IBatchProcessor, name=self.processorname) 936 csv_data = processor.get_csv_skeleton() 937 return csv_data 938 916 939 class DatacenterImportStep1(KofaPage): 917 940 """Manual import step 1: choose file … … 1375 1398 self.response.setHeader( 1376 1399 'Content-Type', 'text/csv; charset=UTF-8') 1400 acronym = grok.getSite()['configuration'].acronym.replace(' ','') 1401 filename = "%s%s.csv" % (acronym, exporter.title.title().replace(' ','')) 1402 self.response.setHeader( 1403 'Content-Disposition:', 'attachment; filename="%s' % filename) 1377 1404 return csv_data 1378 1405 -
main/waeup.kofa/trunk/src/waeup/kofa/browser/templates/datacenteruploadpage.pt
r9027 r9032 19 19 <th i18n:translate="">Processor</th> 20 20 <th i18n:translate="">Available Fields</th> 21 <th i18n:translate="">CSV Skeleton File (not yet)</th>21 <th i18n:translate="">CSV Skeleton File</th> 22 22 </tr> 23 23 </thead> … … 31 31 </td> 32 32 <td> 33 <span tal:replace="importer/name"></span>.csv 33 <a tal:attributes="href python: 'skeleton?name=' + importer['name']" 34 tal:content="python: importer['name'].replace('processor', 'import') + '_000.csv'"> 35 FILENAME</a> 34 36 </td> 35 37 </tr> -
main/waeup.kofa/trunk/src/waeup/kofa/browser/tests/test_browser.py
r9024 r9032 160 160 self.assertEqual(self.browser.headers['Content-Type'], 161 161 'text/csv; charset=UTF-8') 162 self.assertTrue ('WAeUP.KofaFaculties.csv' in 163 self.browser.headers['content-disposition']) 162 164 self.assertEqual(self.browser.contents, 163 165 'code,title,title_prefix,users_with_local_roles\r\n' … … 169 171 'exported: faculties' in logcontent) 170 172 return 173 174 def test_skeleton_download(self): 175 self.browser.addHeader('Authorization', 'Basic mgr:mgrpw') 176 self.browser.open(self.datacenter_path) 177 self.browser.getLink("Upload data").click() 178 self.assertTrue( 179 '<a href="skeleton?name=facultyprocessor">facultyimport_000.csv</a>' 180 in self.browser.contents) 181 self.browser.getLink('facultyimport_000.csv').click() 182 self.assertEqual(self.browser.headers['Status'], '200 Ok') 183 self.assertEqual(self.browser.headers['Content-Type'], 184 'text/csv; charset=UTF-8') 185 self.assertEqual(self.browser.contents, 186 'code,local_roles,title,title_prefix\r\n') 187 return -
main/waeup.kofa/trunk/src/waeup/kofa/utils/batching.py
r8905 r9032 394 394 os.path.abspath(finished_path), failed_path) 395 395 396 def get_csv_skeleton(self): 397 """Export CSV file only with a header of available fields. 398 399 A raw string with CSV data should be returned. 400 """ 401 outfile = StringIO() 402 writer = csv.DictWriter(outfile, self.available_fields) 403 writer.writerow(dict(zip(self.available_fields, self.available_fields))) # header 404 outfile.seek(0) 405 return outfile.read() 406 396 407 class ExporterBase(object): 397 408 """A base for exporters.
Note: See TracChangeset for help on using the changeset viewer.