[11546] | 1 | ## $Id: export.py 14595 2017-02-27 08:17:23Z henrik $ |
---|
| 2 | ## |
---|
| 3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
| 4 | ## This program is free software; you can redistribute it and/or modify |
---|
| 5 | ## it under the terms of the GNU General Public License as published by |
---|
| 6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
| 7 | ## (at your option) any later version. |
---|
| 8 | ## |
---|
| 9 | ## This program is distributed in the hope that it will be useful, |
---|
| 10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | ## GNU General Public License for more details. |
---|
| 13 | ## |
---|
| 14 | ## You should have received a copy of the GNU General Public License |
---|
| 15 | ## along with this program; if not, write to the Free Software |
---|
| 16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 17 | ## |
---|
| 18 | """Exporters for student related stuff. |
---|
| 19 | """ |
---|
[14593] | 20 | import grok |
---|
| 21 | from zope.component import getUtility |
---|
[13569] | 22 | from waeup.kofa.utils.batching import ExporterBase |
---|
[13768] | 23 | from waeup.kofa.utils.helpers import iface_names |
---|
[14593] | 24 | from waeup.kofa.interfaces import IKofaUtils |
---|
| 25 | from waeup.kofa.students.export import (get_levels, |
---|
| 26 | DataForLecturerExporter, StudentExporterBase,) |
---|
[11546] | 27 | from waeup.aaue.students.interfaces import ( |
---|
| 28 | ICustomStudent, ICustomStudentStudyCourse, |
---|
| 29 | ICustomStudentStudyLevel, |
---|
| 30 | ICustomCourseTicket, |
---|
| 31 | ICustomStudentOnlinePayment) |
---|
| 32 | from kofacustom.nigeria.students.export import ( |
---|
[12081] | 33 | NigeriaStudentExporter, NigeriaStudentStudyCourseExporter, |
---|
[11546] | 34 | NigeriaStudentStudyLevelExporter, |
---|
[12876] | 35 | NigeriaCourseTicketExporter, NigeriaStudentPaymentExporter) |
---|
[11546] | 36 | |
---|
[13768] | 37 | |
---|
[12081] | 38 | class CustomStudentExporter(NigeriaStudentExporter): |
---|
[11546] | 39 | """Exporter for Students. |
---|
| 40 | """ |
---|
| 41 | |
---|
| 42 | fields = tuple(sorted(iface_names( |
---|
| 43 | ICustomStudent, omit=['loggerInfo']))) + ( |
---|
| 44 | 'password', 'state', 'history', 'certcode', 'is_postgrad', |
---|
| 45 | 'current_level', 'current_session') |
---|
| 46 | |
---|
| 47 | class CustomStudentStudyCourseExporter(NigeriaStudentStudyCourseExporter): |
---|
| 48 | """Exporter for StudentStudyCourses. |
---|
| 49 | """ |
---|
| 50 | |
---|
| 51 | fields = tuple( |
---|
| 52 | sorted(iface_names(ICustomStudentStudyCourse))) + ('student_id',) |
---|
| 53 | |
---|
| 54 | class CustomCourseTicketExporter(NigeriaCourseTicketExporter): |
---|
| 55 | """Exporter for CourseTickets. |
---|
| 56 | """ |
---|
| 57 | |
---|
| 58 | fields = tuple(sorted(iface_names(ICustomCourseTicket) + |
---|
| 59 | ['level', 'code', 'level_session'])) + ('student_id', |
---|
[13569] | 60 | 'certcode', 'display_fullname', 'matric_number') |
---|
[11546] | 61 | |
---|
[13569] | 62 | def mangle_value(self, value, name, context=None): |
---|
| 63 | """The mangler determines the student's id and fullname. |
---|
| 64 | """ |
---|
| 65 | if context is not None: |
---|
| 66 | student = context.student |
---|
| 67 | if name in ('student_id', 'display_fullname', 'matric_number') \ |
---|
| 68 | and student is not None: |
---|
| 69 | value = getattr(student, name, None) |
---|
| 70 | return ExporterBase().mangle_value(value, name, context=context) |
---|
| 71 | |
---|
[11546] | 72 | class CustomStudentStudyLevelExporter(NigeriaStudentStudyLevelExporter): |
---|
| 73 | """Exporter for StudentStudyLevels. |
---|
| 74 | """ |
---|
| 75 | #: Fieldnames considered by this exporter |
---|
| 76 | fields = tuple(sorted(iface_names( |
---|
[12876] | 77 | ICustomStudentStudyLevel))) + ( |
---|
[14442] | 78 | 'student_id', 'matric_number', 'number_of_tickets','certcode', 'cgpa') |
---|
[11546] | 79 | |
---|
[14436] | 80 | def mangle_value(self, value, name, context=None): |
---|
| 81 | """The mangler determines the student id, nothing else. |
---|
| 82 | """ |
---|
| 83 | if name in ('student_id', 'matric_number') and context is not None: |
---|
| 84 | student = context.student |
---|
| 85 | value = getattr(student, name, None) |
---|
[14442] | 86 | elif name == 'cgpa': |
---|
| 87 | value = context.cumulative_params[0] |
---|
[14436] | 88 | return super( |
---|
| 89 | CustomStudentStudyLevelExporter, self).mangle_value( |
---|
| 90 | value, name, context=context) |
---|
| 91 | |
---|
[12876] | 92 | class CustomStudentPaymentExporter(NigeriaStudentPaymentExporter): |
---|
[11546] | 93 | """Exporter for OnlinePayment instances. |
---|
| 94 | """ |
---|
| 95 | |
---|
| 96 | fields = tuple( |
---|
| 97 | sorted(iface_names( |
---|
| 98 | ICustomStudentOnlinePayment, exclude_attribs=False, |
---|
| 99 | omit=['display_item']))) + ( |
---|
| 100 | 'student_id','state','current_session') |
---|
| 101 | |
---|
[13768] | 102 | class CustomDataForLecturerExporter(DataForLecturerExporter): |
---|
| 103 | """ |
---|
| 104 | """ |
---|
| 105 | |
---|
[14360] | 106 | fields = ('matric_number', 'student_id','display_fullname', |
---|
[13963] | 107 | 'level', 'code', 'level_session', 'ca', 'score') |
---|
[13768] | 108 | |
---|
[14593] | 109 | class LevelReportDataExporter(grok.GlobalUtility, StudentExporterBase): |
---|
| 110 | """ |
---|
| 111 | """ |
---|
| 112 | grok.name('levelreportdata') |
---|
| 113 | |
---|
[14595] | 114 | fields = ('matric_number', 'display_fullname','level','level_session', |
---|
[14593] | 115 | 'credits_counted', 'credits_passed','level_gpa', |
---|
| 116 | 'failed_courses','not_taken_courses','cum_credits_taken', |
---|
| 117 | 'cum_credits_passed','cgpa','remark') |
---|
| 118 | title = u'Summary of Result Data' |
---|
| 119 | |
---|
| 120 | def filter_func(self, x, **kw): |
---|
| 121 | return get_levels(x) |
---|
| 122 | |
---|
| 123 | def mangle_value(self, value, name, context=None): |
---|
| 124 | """The mangler determines the student id, nothing else. |
---|
| 125 | """ |
---|
| 126 | if context is not None: |
---|
| 127 | student = context.student |
---|
| 128 | format_float = getUtility(IKofaUtils).format_float |
---|
| 129 | if name in ('matric_number', |
---|
| 130 | 'display_fullname',) and student is not None: |
---|
| 131 | value = getattr(student, name, None) |
---|
| 132 | elif name == 'credits_counted': |
---|
| 133 | value = context.gpa_params[1] |
---|
| 134 | elif name == 'credits_passed': |
---|
| 135 | value = context.passed_params[2] |
---|
| 136 | elif name == 'level_gpa': |
---|
| 137 | value = format_float(context.gpa_params[0], 3) |
---|
| 138 | elif name == 'failed_courses': |
---|
| 139 | value = context.passed_params[4] |
---|
| 140 | elif name == 'not_taken_courses': |
---|
| 141 | value = context.passed_params[5] |
---|
| 142 | elif name == 'cum_credits_taken': |
---|
| 143 | value = context.cumulative_params[1] |
---|
| 144 | elif name == 'cum_credits_passed': |
---|
| 145 | value = context.cumulative_params[4] |
---|
| 146 | elif name == 'cgpa': |
---|
| 147 | value = format_float(context.cumulative_params[0], 3) |
---|
| 148 | elif name == 'remark': |
---|
| 149 | value = getattr(context, 'remark', '') |
---|
| 150 | return super( |
---|
| 151 | LevelReportDataExporter, self).mangle_value( |
---|
| 152 | value, name, context=context) |
---|
| 153 | |
---|