## $Id: export.py 14701 2017-06-24 08:54:57Z henrik $ ## ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## """Exporters for student related stuff. """ import grok from zope.component import getUtility from waeup.kofa.utils.batching import ExporterBase from waeup.kofa.utils.helpers import iface_names from waeup.kofa.interfaces import IKofaUtils from waeup.kofa.students.export import (get_levels, DataForLecturerExporter, StudentExporterBase,) from waeup.aaue.students.interfaces import ( ICustomStudent, ICustomStudentStudyCourse, ICustomStudentStudyLevel, ICustomCourseTicket, ICustomStudentOnlinePayment) from kofacustom.nigeria.students.export import ( NigeriaStudentExporter, NigeriaStudentStudyCourseExporter, NigeriaStudentStudyLevelExporter, NigeriaCourseTicketExporter, NigeriaStudentPaymentExporter) class CustomStudentExporter(NigeriaStudentExporter): """Exporter for Students. """ fields = tuple(sorted(iface_names( ICustomStudent, omit=['loggerInfo']))) + ( 'password', 'state', 'history', 'certcode', 'is_postgrad', 'current_level', 'current_session') class CustomStudentStudyCourseExporter(NigeriaStudentStudyCourseExporter): """Exporter for StudentStudyCourses. """ fields = tuple( sorted(iface_names(ICustomStudentStudyCourse))) + ( 'matric_number', 'state', 'student_id',) def mangle_value(self, value, name, context=None): if name == 'certificate' and value is not None: # XXX: hopefully cert codes are unique site-wide value = value.code if name in ('student_id', 'matric_number', 'state') and context is not None: student = context.student value = getattr(student, name, None) return ExporterBase().mangle_value(value, name, context=context) class CustomCourseTicketExporter(NigeriaCourseTicketExporter): """Exporter for CourseTickets. """ fields = tuple(sorted(iface_names(ICustomCourseTicket) + ['level', 'code', 'level_session'])) + ('student_id', 'certcode', 'display_fullname', 'matric_number') def mangle_value(self, value, name, context=None): """The mangler determines the student's id and fullname. """ if context is not None: student = context.student if name in ('student_id', 'display_fullname', 'matric_number') \ and student is not None: value = getattr(student, name, None) return ExporterBase().mangle_value(value, name, context=context) class CustomStudentStudyLevelExporter(NigeriaStudentStudyLevelExporter): """Exporter for StudentStudyLevels. """ #: Fieldnames considered by this exporter fields = tuple(sorted(iface_names( ICustomStudentStudyLevel))) + ( 'student_id', 'matric_number', 'number_of_tickets','certcode', 'cgpa') def mangle_value(self, value, name, context=None): """The mangler determines the student id, nothing else. """ if name in ('student_id', 'matric_number') and context is not None: student = context.student value = getattr(student, name, None) elif name == 'cgpa': value = context.cumulative_params[0] return super( CustomStudentStudyLevelExporter, self).mangle_value( value, name, context=context) class CustomStudentPaymentExporter(NigeriaStudentPaymentExporter): """Exporter for OnlinePayment instances. """ fields = tuple( sorted(iface_names( ICustomStudentOnlinePayment, exclude_attribs=False, omit=['display_item']))) + ( 'student_id','state','current_session') class CustomDataForLecturerExporter(DataForLecturerExporter): """ """ fields = ('matric_number', 'student_id','display_fullname', 'depcode', 'faccode', 'level', 'code', 'level_session', 'ca', 'score', 'total_score', 'grade') def mangle_value(self, value, name, context=None): """The mangler determines the student's id and fullname. """ if context is not None: student = context.student if name in ('matric_number', 'reg_number', 'student_id', 'display_fullname', 'depcode', 'faccode') and student is not None: value = getattr(student, name, None) return super( DataForLecturerExporter, self).mangle_value( value, name, context=context) class LevelReportDataExporter(grok.GlobalUtility, StudentExporterBase): """ """ grok.name('levelreportdata') fields = ('matric_number', 'display_fullname','level','level_session', 'credits_counted', 'credits_passed','level_gpa', 'failed_courses','not_taken_courses','cum_credits_taken', 'cum_credits_passed','cgpa','remark') title = u'Summary of Result Data' def filter_func(self, x, **kw): return get_levels(x) def mangle_value(self, value, name, context=None): """The mangler determines the student id, nothing else. """ if context is not None: student = context.student format_float = getUtility(IKofaUtils).format_float if name in ('matric_number', 'display_fullname',) and student is not None: value = getattr(student, name, None) elif name == 'credits_counted': value = context.gpa_params[1] elif name == 'credits_passed': value = context.passed_params[2] elif name == 'level_gpa': value = format_float(context.gpa_params[0], 3) elif name == 'failed_courses': value = context.passed_params[4] elif name == 'not_taken_courses': value = context.passed_params[5] elif name == 'cum_credits_taken': value = context.cumulative_params[1] elif name == 'cum_credits_passed': value = context.cumulative_params[4] elif name == 'cgpa': value = format_float(context.cumulative_params[0], 3) elif name == 'remark': value = getattr(context, 'remark', '') return super( LevelReportDataExporter, self).mangle_value( value, name, context=context)