Changeset 12516


Ignore:
Timestamp:
27 Jan 2015, 08:31:34 (10 years ago)
Author:
Henrik Bettermann
Message:

Export datasets of selected items specified by a list of identifiers. Will be used in students and applicants modules.

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  
    211211        exporter = getUtility(ICSVExporter, name=exporter_name)
    212212        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'
    215218        status = job.finished and 'ready' or 'running'
    216219        status = job.failed and 'FAILED' or status
  • main/waeup.kofa/trunk/src/waeup/kofa/interfaces.py

    r12415 r12516  
    344344        """
    345345
     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
    346354    def export(iterable, filepath=None):
    347355        """Export iterables as rows in a CSV file.
     
    369377        Which special keywords are supported is up to the respective
    370378        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.
    371387        """
    372388
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/batching.py

    r12513 r12516  
    497497        raise NotImplementedError
    498498
     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
    499507    def export(self, iterable, filepath=None):
    500508        """Export `iterable` as CSV file.
     
    521529        """
    522530        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)
    523542        return self.export(data, filepath=filepath)
    524543
     
    551570    if kw == {}:
    552571        exporter.export_all(site, filepath=output_path)
     572    elif kw.has_key('selected'):
     573        exporter.export_selected(site, filepath=output_path, **kw)
    553574    else:
    554575        exporter.export_filtered(site, filepath=output_path, **kw)
  • main/waeup.kofa/trunk/src/waeup/kofa/utils/tests/test_batching.py

    r11737 r12516  
    342342        # we can pass in positional and keyword args
    343343        exporter = ExporterBase()
    344         writer, outfile = exporter.get_csv_writer(filepath=self.workfile)
    345344        self.assertRaises(NotImplementedError, exporter.export_filtered,
    346345                          '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=[])
    347352        return
    348353
     
    360365    def export_filtered(self, site, filepath=None, foo=None, bar=None):
    361366        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:
    362374            open(filepath, 'wb').write(SAMPLE_FILTERED_DATA)
    363375            return
     
    399411        # we export filtered sets
    400412        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'])
    401421        contents = open(result_path, 'rb').read()
    402422        shutil.rmtree(os.path.dirname(result_path))
Note: See TracChangeset for help on using the changeset viewer.