Changeset 15873 for main


Ignore:
Timestamp:
9 Dec 2019, 10:44:57 (5 years ago)
Author:
Henrik Bettermann
Message:

Add StudentOutstandingCoursesExporter.

Location:
main/waeup.kofa/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/CHANGES.txt

    r15865 r15873  
    441.6.1.dev0 (unreleased)
    55=======================
     6
     7* Add `StudentOutstandingCoursesExporter`.
    68
    79* Sort lecturers on scores slip.
  • main/waeup.kofa/trunk/docs/source/userdocs/datacenter/export.rst

    r15277 r15873  
    221221  .. automethod:: waeup.kofa.students.export.CourseTicketExporter.mangle_value()
    222222
     223Student Outstanding Courses Exporter
     224----------------------
     225
     226.. autoclass:: waeup.kofa.students.export.StudentOutstandingCoursesExporter()
     227
     228  .. autoattribute:: waeup.kofa.students.export.StudentOutstandingCoursesExporter.fields
     229  .. autoattribute:: waeup.kofa.students.export.StudentOutstandingCoursesExporter.title
     230  .. automethod:: waeup.kofa.students.export.StudentOutstandingCoursesExporter.mangle_value()
     231
    223232Student Payment Exporter
    224233------------------------
  • main/waeup.kofa/trunk/src/waeup/kofa/students/export.py

    r15792 r15873  
    2525    IExtFileStore, IFileStoreNameChooser, IKofaUtils)
    2626from waeup.kofa.interfaces import MessageFactory as _
     27from waeup.kofa.university.interfaces import ICertificateCourse, ICourse
    2728from waeup.kofa.students.catalog import StudentsQuery, CourseTicketsQuery
    2829from waeup.kofa.students.interfaces import (
     
    133134    return tickets
    134135
     136def get_outstanding(students, **kw):
     137    """Get students with outstanding certificate courses.
     138    """
     139    students_wo = []
     140    for student in students:
     141        certificate = getattr(
     142            student.get('studycourse', None), 'certificate', None)
     143        if certificate:
     144            allticketcodes = []
     145            failedticketcodes = '' # taken but failed
     146            nottakenticketcodes = '' # registered but not taken
     147            missedticketcodes = '' # not registered
     148            for level in student['studycourse'].values():
     149                failedticketcodes += level.passed_params[4]
     150                nottakenticketcodes += level.passed_params[5]
     151                for ticket in level.values():
     152                    allticketcodes.append(ticket.code)
     153            for certcourse in certificate.values():
     154                if certcourse.getCourseCode() not in allticketcodes:
     155                    missedticketcodes += '%s ' % certcourse.__name__
     156            student_wo = (student, missedticketcodes,
     157                          failedticketcodes, nottakenticketcodes)
     158            students_wo.append(student_wo)
     159    return students_wo
     160
    135161def get_payments(students, p_states=None, **kw):
    136162    """Get all payments of `students` within given payment_date period.
     
    430456            value, name, context=context)
    431457
     458class StudentOutstandingCoursesExporter(grok.GlobalUtility, StudentExporterBase):
     459    """The Student Outstanding Courses Exporter first filters the set of
     460    students by searching the students catalog. Then it exports students with
     461    lists of outstanding courses, i.e. courses which the student has
     462    missed (not registered at all), failed (registered but not passed)
     463    or nottaken (registered but not taken).
     464    """
     465    grok.name('studentoutstandingcourses')
     466
     467    fields = ('student_id', 'certcode', 'display_fullname','missed',
     468              'failed', 'nottaken')
     469    title = _(u'Student Outstanding Courses')
     470
     471    def filter_func(self, x, **kw):
     472        return get_outstanding(x, **kw)
     473
     474    def mangle_value(self, value, name, context=None):
     475        """The mangler determines the student's id, fullname and certcode,
     476        and it collects the lists of outstanding courses.
     477        """
     478        if context is not None:
     479            if name in ('student_id', 'display_fullname', 'certcode'):
     480                value = getattr(context[0], name, None)
     481            elif name == 'missed':
     482                value = context[1]
     483            elif name == 'failed':
     484                value = context[2]
     485            elif name == 'nottaken':
     486                value = context[3]
     487        return super(
     488            StudentOutstandingCoursesExporter, self).mangle_value(
     489            value, name, context=context)
     490
    432491class StudentPaymentExporter(grok.GlobalUtility, StudentExporterBase):
    433492    """The Student Payment Exporter first filters the set of students
  • main/waeup.kofa/trunk/src/waeup/kofa/students/tests/test_export.py

    r15664 r15873  
    2727    ICSVExporter, IExtFileStore, IFileStoreNameChooser)
    2828from waeup.kofa.students.catalog import StudentsQuery
     29from waeup.kofa.university.course import Course
     30from waeup.kofa.university.certificate import CertificateCourse
    2931from waeup.kofa.students.export import (
    3032    StudentExporter, StudentStudyCourseExporter, StudentStudyLevelExporter,
     
    3335    ComboCardDataExporter, DataForBursaryExporter,
    3436    StudentUnpaidPaymentExporter, SessionPaymentsOverviewExporter,
     37    StudentOutstandingCoursesExporter,
    3538    AccommodationPaymentsExporter, get_students,)
    3639from waeup.kofa.students.accommodation import BedTicket
     
    789792            '1,1,CRS1,,100,DEP1,FAC1,110,2012,0,0,100,,2,,Course 1,A111111,CERT1,'
    790793            'Anna M. Tester\r\n'
     794            )
     795        return
     796
     797class StudentOutstandingCoursesExporterTest(StudentImportExportSetup):
     798
     799    layer = FunctionalLayer
     800
     801    def setUp(self):
     802        super(StudentOutstandingCoursesExporterTest, self).setUp()
     803        self.setup_for_export()
     804        return
     805
     806    def test_ifaces(self):
     807        # make sure we fullfill interface contracts
     808        obj = StudentOutstandingCoursesExporter()
     809        verifyObject(ICSVStudentExporter, obj)
     810        verifyClass(ICSVStudentExporter, StudentOutstandingCoursesExporter)
     811        return
     812
     813    def test_get_as_utility(self):
     814        # we can get an student exporter as utility
     815        result = queryUtility(ICSVExporter, name="studentoutstandingcourses")
     816        self.assertTrue(result is not None)
     817        return
     818
     819    def test_export_all(self):
     820        course1 = Course(u'Cheese Basics', 'C1')
     821        course2 = Course(u'Advanced Cheese Making', 'C2')
     822        course3 = Course(u'Selling Cheese', 'C3')
     823        self.app['faculties']['fac1']['dep1'].courses.addCourse(course1)
     824        self.app['faculties']['fac1']['dep1'].courses.addCourse(course2)
     825        self.app['faculties']['fac1']['dep1'].courses.addCourse(course3)
     826        self.certificate.addCertCourse(course1, 100, True)
     827        self.certificate.addCertCourse(course2, 400, False)
     828        self.certificate.addCertCourse(course3, 100, False)
     829        self.setup_student(self.student)
     830        self.student['studycourse']['100']['C3'].score = 25
     831        exporter = StudentOutstandingCoursesExporter()
     832        exporter.export_all(self.app, self.outfile)
     833        result = open(self.outfile, 'rb').read()
     834        # The only student has registered C1, C3 and CRS1
     835        # She missed C2, has failed C3 and  did not
     836        # take C1 and CRS1
     837        self.assertEqual(
     838            result,
     839            'student_id,certcode,display_fullname,missed,failed,nottaken\r\n'
     840            'A111111,CERT1,Anna M. Tester,C2_400 ,C3 ,C1 CRS1 \r\n'
    791841            )
    792842        return
  • main/waeup.kofa/trunk/src/waeup/kofa/students/utils.py

    r15823 r15873  
    11421142    #: subobjects thereof.
    11431143    STUDENT_EXPORTER_NAMES = ('students', 'studentstudycourses',
    1144             'studentstudylevels', 'coursetickets',
     1144            'studentstudylevels', 'coursetickets','studentoutstandingcourses',
    11451145            'studentpayments', 'studentunpaidpayments',
    1146             'bedtickets', 'sfpaymentsoverview', 'sessionpaymentsoverview',
    1147             'studylevelsoverview', 'combocard', 'bursary',
    1148             'accommodationpayments')
     1146            'sfpaymentsoverview', 'sessionpaymentsoverview',
     1147            'studylevelsoverview','bedtickets',
     1148            'combocard', 'bursary',
     1149            'accommodationpayments',)
    11491150
    11501151    #: A tuple containing all exporter names needed for backing
Note: See TracChangeset for help on using the changeset viewer.