Ignore:
Timestamp:
10 May 2024, 09:11:48 (6 months ago)
Author:
Henrik Bettermann
Message:

Add exporter and importer for session configuration objects (tests will follow).

Location:
main/waeup.kofa/trunk/src/waeup/kofa
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/configuration.py

    r13118 r17755  
    2121import grok
    2222from zope.component.interfaces import IFactory
    23 from zope.interface import implementedBy
     23from zope.interface import implementedBy, Interface
     24from waeup.kofa.utils.batching import ExporterBase
     25from waeup.kofa.interfaces import ICSVExporter
    2426from waeup.kofa.interfaces import (
    2527    ISessionConfiguration, IConfigurationContainer, ISessionConfigurationAdd,
     28    IBatchProcessor,
    2629    academic_sessions_vocab)
    27 from waeup.kofa.utils.helpers import attrs_to_fields
     30from waeup.kofa.utils.helpers import attrs_to_fields, iface_names
     31from waeup.kofa.utils.batching import BatchProcessor
     32from waeup.kofa.interfaces import MessageFactory as _
    2833
    2934class ConfigurationContainer(grok.Container):
     
    7479    def getInterfaces(self):
    7580        return implementedBy(SessionConfiguration)
     81
     82class ConfigurationExporter(grok.GlobalUtility, ExporterBase):
     83    """The Configuration Exporter exports all configuration data. It iterates over all
     84    objects of the ``configuration`` container.
     85    """
     86    grok.implements(ICSVExporter)
     87    grok.name('configurations')
     88
     89    title = _(u'Session Configurations')
     90
     91    fields = tuple(sorted(iface_names(ISessionConfiguration)))
     92
     93    def export(self, configurations, filepath=None):
     94        """Export `configurations`, an iterable, as CSV file.
     95
     96        If `filepath` is ``None``, a raw string with CSV data is returned.
     97        """
     98        writer, outfile = self.get_csv_writer(filepath)
     99        for configuration in configurations:
     100            self.write_item(configuration, writer)
     101        return self.close_outfile(filepath, outfile)
     102
     103    def export_all(self, site, filepath=None):
     104        """Export configurations into filepath as CSV data.
     105
     106        If `filepath` is ``None``, a raw string with CSV data is returned.
     107        """
     108        configurations = site.get('configuration', {})
     109        return self.export(configurations.values(), filepath)
     110
     111class ConfigurationProcessor(BatchProcessor):
     112    """The Configuration Processor processes session configuration objects in
     113    the ``configuration`` container.
     114
     115    """
     116    grok.implements(IBatchProcessor)
     117    grok.provides(IBatchProcessor)
     118    grok.context(Interface)
     119    util_name = 'configurationprocessor'
     120    grok.name(util_name)
     121
     122    name = u'SessionConfiguration Processor'
     123    iface = ISessionConfiguration
     124    factory_name = 'waeup.SessionConfiguration'
     125
     126    mode = None
     127
     128    def parentsExist(self, row, site):
     129        return 'configuration' in site.keys()
     130
     131    def entryExists(self, row, site):
     132        return row['academic_session'] in site['configuration'].keys()
     133
     134    def getParent(self, row, site):
     135        return site['configuration']
     136
     137    def getEntry(self, row, site):
     138        if not self.entryExists(row, site):
     139            return None
     140        parent = self.getParent(row, site)
     141        return parent.get(row['academic_session'])
     142
     143    def addEntry(self, obj, row, site):
     144        parent = self.getParent(row, site)
     145        parent.addSessionConfiguration(obj)
     146        return
     147
     148    def delEntry(self, row, site):
     149        configuration = self.getEntry(row, site)
     150        if user is not None:
     151            parent = self.getParent(row, site)
     152            grok.getSite().logger.info(
     153                '%s - %s - Session configuration removed' % (self.name, row['academic_session']))
     154            del parent[configuration.academic_session]
     155        pass
     156
  • main/waeup.kofa/trunk/src/waeup/kofa/doctests/batchprocessing_browser.txt

    r16834 r17755  
    104104    'CertificateCourse Processor',
    105105    'Certificate Processor',
     106    'SessionConfiguration Processor',
    106107    'Course Processor',
    107108    'CourseTicket Processor',
Note: See TracChangeset for help on using the changeset viewer.