[11543] | 1 | ## $Id: export.py 17622 2023-10-26 12:55:48Z 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 | """ |
---|
[16706] | 20 | from waeup.kofa.students.export import ( |
---|
| 21 | SchoolFeePaymentsOverviewExporter, StudentExporter) |
---|
[15563] | 22 | from kofacustom.iuokada.students.interfaces import ( |
---|
[11545] | 23 | ICustomStudent, |
---|
| 24 | ICustomStudentStudyCourse, |
---|
| 25 | ICustomStudentStudyLevel, |
---|
| 26 | ICustomCourseTicket, |
---|
[11543] | 27 | ICustomStudentOnlinePayment) |
---|
| 28 | from kofacustom.nigeria.students.export import ( |
---|
[12084] | 29 | NigeriaStudentExporter, |
---|
[11545] | 30 | NigeriaStudentStudyCourseExporter, |
---|
| 31 | NigeriaStudentStudyLevelExporter, |
---|
| 32 | NigeriaCourseTicketExporter, |
---|
[17622] | 33 | NigeriaStudentPaymentExporter, |
---|
| 34 | NigeriaDataForBursaryExporter, |
---|
| 35 | ) |
---|
| 36 | from waeup.kofa.students.export import StudentPaymentExporter |
---|
[11543] | 37 | from waeup.kofa.utils.helpers import iface_names |
---|
| 38 | |
---|
[12084] | 39 | class CustomStudentExporter(NigeriaStudentExporter): |
---|
[11543] | 40 | """Exporter for Students. |
---|
| 41 | """ |
---|
| 42 | |
---|
| 43 | fields = tuple(sorted(iface_names( |
---|
| 44 | ICustomStudent, omit=['loggerInfo']))) + ( |
---|
| 45 | 'password', 'state', 'history', 'certcode', 'is_postgrad', |
---|
[16403] | 46 | 'current_level', 'current_session', 'entry_session') |
---|
[11543] | 47 | |
---|
| 48 | class CustomStudentStudyCourseExporter(NigeriaStudentStudyCourseExporter): |
---|
| 49 | """Exporter for StudentStudyCourses. |
---|
| 50 | """ |
---|
| 51 | |
---|
| 52 | fields = tuple( |
---|
| 53 | sorted(iface_names(ICustomStudentStudyCourse))) + ('student_id',) |
---|
| 54 | |
---|
[11545] | 55 | class CustomStudentStudyLevelExporter(NigeriaStudentStudyLevelExporter): |
---|
| 56 | """Exporter for StudentStudyLevels. |
---|
| 57 | """ |
---|
| 58 | #: Fieldnames considered by this exporter |
---|
| 59 | fields = tuple(sorted(iface_names( |
---|
[12878] | 60 | ICustomStudentStudyLevel))) + ( |
---|
[11545] | 61 | 'student_id', 'number_of_tickets','certcode') |
---|
| 62 | |
---|
[11543] | 63 | class CustomCourseTicketExporter(NigeriaCourseTicketExporter): |
---|
| 64 | """Exporter for CourseTickets. |
---|
| 65 | """ |
---|
| 66 | |
---|
| 67 | fields = tuple(sorted(iface_names(ICustomCourseTicket) + |
---|
| 68 | ['level', 'code', 'level_session'])) + ('student_id', |
---|
| 69 | 'certcode', 'display_fullname') |
---|
| 70 | |
---|
[12878] | 71 | class CustomStudentPaymentExporter(NigeriaStudentPaymentExporter): |
---|
[11543] | 72 | """Exporter for OnlinePayment instances. |
---|
| 73 | """ |
---|
| 74 | |
---|
| 75 | fields = tuple( |
---|
| 76 | sorted(iface_names( |
---|
| 77 | ICustomStudentOnlinePayment, exclude_attribs=False, |
---|
| 78 | omit=['display_item']))) + ( |
---|
[16665] | 79 | 'student_id','state','current_session', 'entry_session', |
---|
| 80 | 'faculty', 'department') |
---|
[11543] | 81 | |
---|
[16665] | 82 | def mangle_value(self, value, name, context=None): |
---|
| 83 | """The mangler determines the student's id, registration |
---|
| 84 | state and current session. |
---|
| 85 | """ |
---|
| 86 | if context is not None: |
---|
| 87 | student = context.student |
---|
| 88 | if name in ['faculty', 'department'] and student is not None: |
---|
| 89 | try: |
---|
| 90 | if name == 'department': |
---|
| 91 | value = student['studycourse'].certificate.__parent__.__parent__.title |
---|
| 92 | else: |
---|
| 93 | value = student['studycourse'].certificate.__parent__.__parent__.__parent__.title |
---|
| 94 | except AttributeError: |
---|
| 95 | value = 'N/A' |
---|
| 96 | return super( |
---|
| 97 | CustomStudentPaymentExporter, self).mangle_value( |
---|
| 98 | value, name, context=context) |
---|
| 99 | |
---|
[16706] | 100 | class CustomSchoolFeePaymentsOverviewExporter(SchoolFeePaymentsOverviewExporter): |
---|
| 101 | """ |
---|
| 102 | """ |
---|
| 103 | |
---|
| 104 | def mangle_value(self, value, name, context=None): |
---|
| 105 | """ |
---|
| 106 | """ |
---|
| 107 | if name in self.year_range_tuple and context is not None: |
---|
| 108 | value = 0 |
---|
| 109 | for ticket in context['payments'].values(): |
---|
| 110 | if ticket.p_category in ( |
---|
| 111 | 'schoolfee', |
---|
| 112 | 'schoolfee40', |
---|
| 113 | 'secondinstal ', |
---|
| 114 | 'clearance',) and ticket.p_session == int(name): |
---|
| 115 | if ticket.p_state == 'waived': |
---|
| 116 | value = 'waived' |
---|
| 117 | break |
---|
| 118 | if ticket.p_state == 'scholarship': |
---|
| 119 | value = 'scholarship' |
---|
| 120 | break |
---|
| 121 | if ticket.p_state == 'paid': |
---|
| 122 | try: |
---|
| 123 | value += ticket.amount_auth |
---|
| 124 | except TypeError: |
---|
| 125 | pass |
---|
| 126 | if value == 0: |
---|
| 127 | value = '' |
---|
| 128 | elif isinstance(value, float): |
---|
| 129 | value = round(value, 2) |
---|
| 130 | return super( |
---|
| 131 | StudentExporter, self).mangle_value( |
---|
| 132 | value, name, context=context) |
---|
| 133 | |
---|
[17622] | 134 | class CustomDataForBursaryExporter(NigeriaDataForBursaryExporter): |
---|
| 135 | """ |
---|
| 136 | """ |
---|
| 137 | |
---|
| 138 | fields = tuple( |
---|
| 139 | sorted(iface_names( |
---|
| 140 | ICustomStudentOnlinePayment, exclude_attribs=False, |
---|
| 141 | omit=['display_item', 'certificate', 'student']))) + ( |
---|
| 142 | 'student_id','matric_number','reg_number', |
---|
| 143 | 'firstname', 'middlename', 'lastname','sex', |
---|
| 144 | 'state','current_session', |
---|
| 145 | 'entry_session', 'entry_mode', |
---|
| 146 | 'faculty','department','certcode','lga') |
---|
| 147 | |
---|
| 148 | |
---|
| 149 | def mangle_value(self, value, name, context=None): |
---|
| 150 | """The mangler fetches the student data. |
---|
| 151 | """ |
---|
| 152 | if context is not None: |
---|
| 153 | student = context.student |
---|
| 154 | if name in [ |
---|
| 155 | 'student_id','matric_number', 'reg_number', |
---|
| 156 | 'firstname', 'middlename', 'lastname','sex', |
---|
| 157 | 'state', 'current_session', |
---|
| 158 | 'entry_session', 'entry_mode', |
---|
| 159 | 'certcode', |
---|
| 160 | 'lga'] and student is not None: |
---|
| 161 | value = getattr(student, name, None) |
---|
| 162 | certificate = student['studycourse'].certificate |
---|
| 163 | if name == 'department' and certificate is not None: |
---|
| 164 | value = certificate.__parent__.__parent__.longtitle |
---|
| 165 | if name == 'faculty' and certificate is not None: |
---|
| 166 | value = certificate.__parent__.__parent__.__parent__.longtitle |
---|
| 167 | return super( |
---|
| 168 | StudentPaymentExporter, self).mangle_value( |
---|
| 169 | value, name, context=context) |
---|