Ignore:
Timestamp:
29 Jan 2020, 08:52:54 (5 years ago)
Author:
Henrik Bettermann
Message:

Add TrimmedDataExporter?.

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

Legend:

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

    r15963 r15966  
    345345            value, name, context=context)
    346346
     347class TrimmedDataExporter(grok.GlobalUtility, StudentExporterBase):
     348    """The Student Trimmed Data Exporter first filters the set of students
     349    by searching the students catalog. Then it exports a trimmed data set
     350    of this set of students.
     351    """
     352    grok.name('trimmed')
     353
     354    fields = (
     355        'student_id',
     356        'matric_number',
     357        'reg_number',
     358        'firstname',
     359        'middlename',
     360        'lastname',
     361        'sex',
     362        'email',
     363        'phone',
     364        'nationality',
     365        'date_of_birth',
     366        'state',
     367        'current_mode',
     368        'certcode',
     369        'faccode',
     370        'depcode',
     371        'current_level',
     372        'current_session',
     373        'current_verdict')
     374    title = _(u'Students (Trimmed Data)')
     375
     376    def mangle_value(self, value, name, context=None):
     377        """The mangler prepares the history messages and adds a hash symbol at
     378        the end of the phone number to avoid annoying automatic number
     379        transformation by Excel or Calc."""
     380        if 'phone' in name and value is not None:
     381            # Append hash '#' to phone numbers to circumvent
     382            # unwanted excel automatic
     383            value = str('%s#' % value)
     384        return super(
     385            TrimmedDataExporter, self).mangle_value(
     386            value, name, context=context)
    347387
    348388class StudentStudyCourseExporter(grok.GlobalUtility, StudentExporterBase):
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py

    r15963 r15966  
    3838    AccommodationPaymentsExporter,
    3939    TranscriptDataExporter,
     40    TrimmedDataExporter,
    4041    get_students,)
    4142from waeup.kofa.students.accommodation import BedTicket
     
    172173            '"Studentroad 21\nLagos 123456\n",,+234-123-12345#,123,f,'
    173174            'A111111,0,,,created'
     175            in result
     176            )
     177        return
     178
     179
     180class StudentTrimmedDataExporterTest(StudentImportExportSetup):
     181
     182    layer = FunctionalLayer
     183
     184    std_csv_entry = (
     185        'my adm code,my clr code,1981-02-04#,anna@sample.com,,'
     186        'Anna,,Tester,234,M.,NG,,,"Studentroad 21\nLagos 123456\n",,'
     187        '+234-123-12345#,123,f,A111111,0,,,created'
     188        )
     189
     190    def setUp(self):
     191        super(StudentTrimmedDataExporterTest, self).setUp()
     192        self.setup_for_export()
     193        return
     194
     195    def test_ifaces(self):
     196        # make sure we fullfill interface contracts
     197        obj = TrimmedDataExporter()
     198        verifyObject(ICSVStudentExporter, obj)
     199        verifyClass(ICSVStudentExporter, TrimmedDataExporter)
     200        return
     201
     202    def test_get_as_utility(self):
     203        # we can get an student exporter as utility
     204        result = queryUtility(ICSVExporter, name="trimmed")
     205        self.assertTrue(result is not None)
     206        return
     207
     208    def test_export(self):
     209        # we can really export students
     210        # set values we can expect in export file
     211        self.setup_student(self.student)
     212        exporter = TrimmedDataExporter()
     213        exporter.export([self.student], self.outfile)
     214        result = open(self.outfile, 'rb').read()
     215        self.assertTrue(
     216            'student_id,matric_number,reg_number,firstname,middlename,'
     217            'lastname,sex,email,phone,nationality,date_of_birth,state,'
     218            'current_mode,certcode,faccode,depcode,current_level,'
     219            'current_session,current_verdict\r\n'
     220            'A111111,234,123,Anna,M.,Tester,f,anna@sample.com,+234-123-12345#,'
     221            'NG,1981-02-04#,created,ug_ft,CERT1,NA,NA,200,2012,0'
    174222            in result
    175223            )
  • main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py

    r15920 r15966  
    11571157            'studentpayments',
    11581158            'bedtickets',
     1159            'trimmed',
    11591160            'outstandingcourses',
    11601161            'unpaidpayments',
Note: See TracChangeset for help on using the changeset viewer.