Changeset 12516
- Timestamp:
- 27 Jan 2015, 08:31:34 (10 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
r12232 r12516 211 211 exporter = getUtility(ICSVExporter, name=exporter_name) 212 212 exporter_title = getattr(exporter, 'title', 'Unknown') 213 args = ', '.join(['%s=%s' % (item[0], item[1]) 214 for item in job.kwargs.items()]) 213 if not job.kwargs.has_key('selected'): 214 args = ', '.join(['%s=%s' % (item[0], item[1]) 215 for item in job.kwargs.items()]) 216 else: 217 args = 'selection' 215 218 status = job.finished and 'ready' or 'running' 216 219 status = job.failed and 'FAILED' or status -
main/waeup.kofa/trunk/src/waeup/kofa/interfaces.py
r12415 r12516 344 344 """ 345 345 346 def get_selected(site, selected): 347 """Get datasets in `site` to be exported. 348 349 The set of data is specified by a list of identifiers. 350 351 Returns an iterable. 352 """ 353 346 354 def export(iterable, filepath=None): 347 355 """Export iterables as rows in a CSV file. … … 369 377 Which special keywords are supported is up to the respective 370 378 exporter. 379 """ 380 381 def export_selected(site, filepath=None, **kw): 382 """Export items in `site` specified by a list of identifiers 383 called `selected`. 384 385 If `filepath` is not given, a string with the data should be 386 returned. 371 387 """ 372 388 -
main/waeup.kofa/trunk/src/waeup/kofa/utils/batching.py
r12513 r12516 497 497 raise NotImplementedError 498 498 499 def get_selected(self, site, selected): 500 """Get datasets to export for selected items 501 specified by a list of identifiers. 502 503 Returns an iterable. 504 """ 505 raise NotImplementedError 506 499 507 def export(self, iterable, filepath=None): 500 508 """Export `iterable` as CSV file. … … 521 529 """ 522 530 data = self.get_filtered(site, **kw) 531 return self.export(data, filepath=filepath) 532 533 def export_selected(self, site, filepath=None, **kw): 534 """Export those items specified by a list of identifiers 535 called `selected`. 536 537 If `filepath` is ``None``, a raw string with CSV data should 538 be returned. 539 """ 540 selected = kw.get('selected', []) 541 data = self.get_selected(site, selected) 523 542 return self.export(data, filepath=filepath) 524 543 … … 551 570 if kw == {}: 552 571 exporter.export_all(site, filepath=output_path) 572 elif kw.has_key('selected'): 573 exporter.export_selected(site, filepath=output_path, **kw) 553 574 else: 554 575 exporter.export_filtered(site, filepath=output_path, **kw) -
main/waeup.kofa/trunk/src/waeup/kofa/utils/tests/test_batching.py
r11737 r12516 342 342 # we can pass in positional and keyword args 343 343 exporter = ExporterBase() 344 writer, outfile = exporter.get_csv_writer(filepath=self.workfile)345 344 self.assertRaises(NotImplementedError, exporter.export_filtered, 346 345 'foo', bar='bar') 346 347 def test_export_selected(self): 348 # we can pass in a list of identifiers 349 exporter = ExporterBase() 350 self.assertRaises(NotImplementedError, exporter.export_selected, 351 'foo', selected=[]) 347 352 return 348 353 … … 360 365 def export_filtered(self, site, filepath=None, foo=None, bar=None): 361 366 if foo or bar: 367 open(filepath, 'wb').write(SAMPLE_FILTERED_DATA) 368 return 369 self.export_all(site, filepath=filepath) 370 return 371 372 def export_selected(self, site, filepath=None, selected=None): 373 if selected: 362 374 open(filepath, 'wb').write(SAMPLE_FILTERED_DATA) 363 375 return … … 399 411 # we export filtered sets 400 412 result_path = export_job(None, 'cave_exporter', foo='foo') 413 contents = open(result_path, 'rb').read() 414 shutil.rmtree(os.path.dirname(result_path)) 415 self.assertEqual(contents, SAMPLE_FILTERED_DATA) 416 return 417 418 def test_export_job_selected(self): 419 # we export subsets 420 result_path = export_job(None, 'cave_exporter', selected=['foo']) 401 421 contents = open(result_path, 'rb').read() 402 422 shutil.rmtree(os.path.dirname(result_path))
Note: See TracChangeset for help on using the changeset viewer.