Ignore:
Timestamp:
7 Feb 2013, 08:21:05 (12 years ago)
Author:
Henrik Bettermann
Message:

Implement combo card data exporter.

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

Legend:

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

    r9933 r9936  
    3434        'studentstudylevels', 'coursetickets',
    3535        'studentpayments', 'bedtickets', 'paymentsoverview',
    36         'studylevelsoverview')
     36        'studylevelsoverview', 'combocard')
    3737
    3838def get_students(site, stud_filter=StudentsQuery()):
     
    168168
    169169    #: Fieldnames considered by this exporter
    170     fields = tuple(sorted(iface_names(
    171         IStudent, omit=['loggerInfo']))) + (
     170    fields = tuple(sorted(iface_names(IStudent))) + (
    172171        'password', 'state', 'history', 'certcode', 'is_postgrad',
    173172        'current_level', 'current_session')
     
    395394            StudentsExporter, self).mangle_value(
    396395            value, name, context=context)
     396
     397class ComboCardDataExporter(grok.GlobalUtility, StudentExporterBase):
     398    """Exporter for Interswitch Combo Card Data.
     399    """
     400    grok.name('combocard')
     401
     402    #: Fieldnames considered by this exporter
     403    fields = ('display_fullname',
     404              'matric_number',
     405              'certificate', 'faculty', 'department')
     406
     407    #: The title under which this exporter will be displayed
     408    title = _(u'Combo Card Data')
     409
     410    def mangle_value(self, value, name, context=None):
     411        certificate = context['studycourse'].certificate
     412        if name == 'certificate' and certificate is not None:
     413            value = certificate.title
     414        if name == 'department' and certificate is not None:
     415            value = certificate.__parent__.__parent__.longtitle()
     416        if name == 'faculty' and certificate is not None:
     417            value = certificate.__parent__.__parent__.__parent__.longtitle()
     418        return super(
     419            ComboCardDataExporter, self).mangle_value(
     420            value, name, context=context)
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py

    r9861 r9936  
    1010    CourseTicketExporter, StudentPaymentsExporter, BedTicketsExporter,
    1111    StudentPaymentsOverviewExporter, StudentStudyLevelsOverviewExporter,
     12    ComboCardDataExporter,
    1213    get_students,)
    1314from waeup.kofa.students.accommodation import BedTicket
     
    930931            )
    931932        return
     933
     934class ComboCardExporterTest(StudentImportExportSetup):
     935
     936    layer = FunctionalLayer
     937
     938    def setUp(self):
     939        super(ComboCardExporterTest, self).setUp()
     940        self.setup_for_export()
     941        return
     942
     943    def test_export_all(self):
     944        self.setup_student(self.student)
     945        exporter = ComboCardDataExporter()
     946        exporter.export_all(self.app, self.outfile)
     947        result = open(self.outfile, 'rb').read()
     948        self.assertTrue(
     949            'display_fullname,matric_number,certificate,faculty,department\r\n'
     950            'Anna M. Tester,234,Unnamed Certificate,Faculty of Unnamed '
     951            'Faculty (NA),Department of Unnamed Department (NA)'
     952            in result
     953            )
     954        return
Note: See TracChangeset for help on using the changeset viewer.