Changeset 8411


Ignore:
Timestamp:
10 May 2012, 16:38:15 (13 years ago)
Author:
uli
Message:

Dirty fix for problem with export of student subobjects.

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

Legend:

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

    r8400 r8411  
    2121from zope.catalog.interfaces import ICatalog
    2222from zope.component import queryUtility
    23 from waeup.kofa.interfaces import ICSVExporter
    2423from waeup.kofa.interfaces import MessageFactory as _
    2524from waeup.kofa.students.interfaces import (
    2625    IStudent, IStudentStudyCourse, IStudentStudyLevel, ICourseTicket,
    27     IStudentOnlinePayment)
     26    IStudentOnlinePayment, ICSVStudentExporter)
    2827from waeup.kofa.utils.batching import ExporterBase
    2928from waeup.kofa.utils.helpers import iface_names
     
    3736    """Exporter for Students.
    3837    """
    39     grok.implements(ICSVExporter)
     38    grok.implements(ICSVStudentExporter)
     39    grok.provides(ICSVStudentExporter)
    4040    grok.name('students')
    4141
     
    6969        return self.export(students, filepath)
    7070
     71    def export_student(self, student, filepath=None):
     72        return self.export([student], filepath=filepath)
     73
    7174class StudentStudyCourseExporter(grok.GlobalUtility, ExporterBase):
    7275    """Exporter for StudentStudyCourses.
    7376    """
    74     grok.implements(ICSVExporter)
     77    grok.implements(ICSVStudentExporter)
     78    grok.provides(ICSVStudentExporter)
    7579    grok.name('studentstudycourses')
    7680
     
    120124        return self.export(study_courses, filepath)
    121125
     126    def export_student(self, student, filepath=None):
     127        if 'studycourse' in student.keys():
     128            return self.export([student['studycourse']], filepath=filepath)
     129        return self.export([], filepath=filepath)
     130
     131
    122132class StudentStudyLevelExporter(grok.GlobalUtility, ExporterBase):
    123133    """Exporter for StudentStudyLevels.
    124134    """
    125     grok.implements(ICSVExporter)
     135    grok.implements(ICSVStudentExporter)
     136    grok.provides(ICSVStudentExporter)
    126137    grok.name('studentstudylevels')
    127138
     
    181192        return self.export(levels, filepath)
    182193
     194    def export_student(self, student, filepath=None):
     195        if 'studycourse' in student.keys():
     196            return self.export(student['studycourse'].values(),
     197                               filepath=filepath)
     198        return self.export([], filepath=filepath)
     199
    183200class CourseTicketExporter(grok.GlobalUtility, ExporterBase):
    184201    """Exporter for CourseTickets.
    185202    """
    186     grok.implements(ICSVExporter)
     203    grok.implements(ICSVStudentExporter)
     204    grok.provides(ICSVStudentExporter)
    187205    grok.name('coursetickets')
    188206
     
    242260        return self.export(tickets, filepath)
    243261
     262    def export_student(self, student, filepath=None):
     263        if 'studycourse' not in student.keys():
     264            return self.export([], filepath=filepath)
     265        levels = student['studycourse'].values()
     266        tickets = []
     267        for level in levels:
     268            for ticket in level.values():
     269                tickets.append(ticket)
     270        return self.export(tickets, filepath=filepath)
     271
    244272class PaymentsExporter(grok.GlobalUtility, ExporterBase):
    245273    """Exporter for OnlinePayment instances.
    246274    """
    247     grok.implements(ICSVExporter)
     275    grok.implements(ICSVStudentExporter)
     276    grok.provides(ICSVStudentExporter)
    248277    grok.name('studentpayments')
    249278
     
    295324                payments.append(payment)
    296325        return self.export(payments, filepath)
     326
     327    def export_student(self, student, filepath=None):
     328        if not 'payments' in student.keys():
     329            return self.export([], filepath=filepath)
     330        return self.export(student['payments'].values(), filepath=filepath)
  • main/waeup.kofa/trunk/src/waeup/kofa/students/student.py

    r8403 r8411  
    3232from waeup.kofa.interfaces import (
    3333    IObjectHistory, IUserAccount, IFileStoreNameChooser, IFileStoreHandler,
    34     IKofaUtils, CLEARANCE, registration_states_vocab, IExtFileStore,
    35     ICSVExporter)
     34    IKofaUtils, CLEARANCE, registration_states_vocab, IExtFileStore,)
    3635from waeup.kofa.students.accommodation import StudentAccommodation
    3736from waeup.kofa.students.export import EXPORTER_NAMES
    38 from waeup.kofa.students.interfaces import IStudent, IStudentNavigation
     37from waeup.kofa.students.interfaces import (
     38    IStudent, IStudentNavigation, ICSVStudentExporter)
    3939from waeup.kofa.students.payments import StudentPaymentsContainer
    4040from waeup.kofa.students.utils import generate_student_id
     
    220220    """
    221221    for name in EXPORTER_NAMES:
    222         exporter = getUtility(ICSVExporter, name=name)
    223         csv_data = exporter.export([student])
     222        exporter = getUtility(ICSVStudentExporter, name=name)
     223        csv_data = exporter.export_student(student)
    224224        csv_data = csv_data.split('\r\n')
    225225
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_batching.py

    r8354 r8411  
    3434    StudentStudyLevelProcessor, CourseTicketProcessor,
    3535    StudentOnlinePaymentProcessor, StudentVerdictProcessor)
     36from waeup.kofa.students.payments import StudentOnlinePayment
    3637from waeup.kofa.students.student import Student
    3738from waeup.kofa.students.studylevel import StudentStudyLevel, CourseTicket
     
    208209        ticket.semester = 2
    209210        study_level.addCourseTicket(ticket)
    210 
     211        self.add_payment(student)
    211212        return student
     213
     214    def add_payment(self, student):
     215        # get a payment with all fields set
     216        payment = StudentOnlinePayment()
     217        payment.creation_date = datetime.datetime(2012, 4, 1, 13, 12, 1)
     218        payment.p_id = 'my-id'
     219        payment.ac = u'666'
     220        payment.p_item = u'p-item'
     221        payment.p_level = 100
     222        payment.p_session = 2012
     223        payment.payment_date = datetime.datetime(2012, 4, 1, 14, 12, 1)
     224        payment.r_amount_approved = 12.12
     225        payment.r_code = u'r-code'
     226        # XXX: there is no addPayment method to give predictable names
     227        student['payments']['my-payment'] = payment
     228        return payment
     229
    212230
    213231
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py

    r8402 r8411  
    7272        return
    7373
     74    def test_export_student(self):
     75        # we can export a single student
     76        self.setup_student(self.student)
     77        exporter = StudentsExporter()
     78        exporter.export_student(self.student, self.outfile)
     79        result = open(self.outfile, 'rb').read()
     80        self.assertEqual(
     81            result,
     82            'adm_code,clearance_locked,clr_code,date_of_birth,email,employer,'
     83            'firstname,lastname,matric_number,middlename,nationality,'
     84            'perm_address,phone,reg_number,sex,student_id\r\n'
     85
     86            'my adm code,0,my clr code,1981-02-04#,anna@sample.com,,Anna,'
     87            'Tester,M123456,M.,NG,"Studentroad 21\nLagos 123456\n",'
     88            '+234-123-12345,123456,f,A111111\r\n'
     89            )
     90        return
     91
     92
    7493class StudentStudyCourseExporterTest(StudentImportExportSetup):
    7594
     
    142161        return
    143162
     163    def test_export_student(self):
     164        # we can export studycourse of a certain student
     165        self.setup_student(self.student)
     166        exporter = StudentStudyCourseExporter()
     167        exporter.export_student(self.student, self.outfile)
     168        result = open(self.outfile, 'rb').read()
     169        self.assertEqual(
     170            result,
     171            'certificate,current_level,current_session,current_verdict,'
     172            'entry_mode,entry_session,previous_verdict\r\n'
     173
     174            'CERT1,200,2012,0,ug_ft,2010,0\r\n'
     175            )
     176        return
     177
    144178class StudentStudyLevelExporterTest(StudentImportExportSetup):
    145179
     
    207241        return
    208242
     243    def test_export_student(self):
     244        # we can really export study levels of a certain student
     245        self.setup_student(self.student)
     246        exporter = StudentStudyLevelExporter()
     247        exporter.export_student(self.student, self.outfile)
     248        result = open(self.outfile, 'rb').read()
     249        self.assertEqual(
     250            result,
     251            'level,level_session,level_verdict,matric_number,reg_number\r\n'
     252            '100,2012,A,M123456,123456\r\n'
     253            )
     254        return
     255
    209256class CourseTicketExporterTest(StudentImportExportSetup):
    210257
     
    276323        return
    277324
     325    def test_export_student(self):
     326        # we can really export all course tickets of a certain student
     327        self.setup_student(self.student)
     328        exporter = CourseTicketExporter()
     329        exporter.export_student(self.student, self.outfile)
     330        result = open(self.outfile, 'rb').read()
     331        self.assertEqual(
     332            result,
     333            'automatic,carry_over,code,credits,dcode,fcode,level,mandatory,'
     334            'matric_number,passmark,reg_number,score,semester,title\r\n'
     335            '1,1,CRS1,100,DEP1,FAC1,100,0,M123456,100,123456,0,2,Course 1\r\n'
     336            )
     337        return
     338
    278339class PaymentsExporterTest(StudentImportExportSetup):
    279340
     
    284345        self.setup_for_export()
    285346        return
    286 
    287     def get_payment(self):
    288         # get a payment with all fields set
    289         payment = StudentOnlinePayment()
    290         payment.creation_date = datetime.datetime(2012, 4, 1, 13, 12, 1)
    291         payment.p_id = 'my-id'
    292         payment.ac = u'666'
    293         payment.p_item = u'p-item'
    294         payment.p_level = 100
    295         payment.p_session = 2012
    296         payment.payment_date = datetime.datetime(2012, 4, 1, 14, 12, 1)
    297         payment.r_amount_approved = 12.12
    298         payment.r_code = u'r-code'
    299         # XXX: there is no addPayment method to give predictable names
    300         self.student['payments']['my-payment'] = payment
    301         return payment
    302347
    303348    def test_ifaces(self):
     
    335380        # set values we can expect in export file
    336381        self.setup_student(self.student)
    337         payment = self.get_payment()
     382        payment = self.student['payments']['my-payment']
    338383        exporter = PaymentsExporter()
    339384        exporter.export([payment], self.outfile)
     
    355400        # set values we can expect in export file
    356401        self.setup_student(self.student)
    357         self.get_payment() # adds new payment to student
    358402        exporter = PaymentsExporter()
    359403        exporter.export_all(self.app, self.outfile)
     
    370414            )
    371415        return
     416
     417    def test_export_student(self):
     418        # we can really export all payments of a certain student
     419        # set values we can expect in export file
     420        self.setup_student(self.student)
     421        exporter = PaymentsExporter()
     422        exporter.export_student(self.student, self.outfile)
     423        result = open(self.outfile, 'rb').read()
     424        self.assertEqual(
     425            result,
     426            'ac,amount_auth,creation_date,matric_number,p_category,p_id,'
     427            'p_item,p_level,p_session,p_state,payment_date,r_amount_approved,'
     428            'r_code,reg_number\r\n'
     429
     430            '666,0.0,2012-04-01 13:12:01,M123456,schoolfee,my-id,'
     431            'p-item,100,2012,unpaid,2012-04-01 14:12:01,12.12,'
     432            'r-code,123456\r\n'
     433            )
     434        return
Note: See TracChangeset for help on using the changeset viewer.