[9042] | 1 | ## $Id: export.py 16197 2020-08-11 12:42:09Z 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 | """ |
---|
[12107] | 20 | import grok |
---|
| 21 | from waeup.kofa.interfaces import REQUESTED |
---|
[9042] | 22 | from kofacustom.nigeria.students.interfaces import ( |
---|
[11544] | 23 | INigeriaStudent, |
---|
| 24 | INigeriaStudentStudyCourse, |
---|
| 25 | INigeriaStudentStudyLevel, |
---|
| 26 | INigeriaCourseTicket, |
---|
[10757] | 27 | INigeriaStudentOnlinePayment) |
---|
[9042] | 28 | from waeup.kofa.students.export import ( |
---|
[12080] | 29 | StudentExporter, |
---|
[11544] | 30 | StudentStudyCourseExporter, |
---|
| 31 | StudentStudyLevelExporter, |
---|
| 32 | CourseTicketExporter, |
---|
[13944] | 33 | StudentPaymentExporter, |
---|
[16195] | 34 | DataForBursaryExporter, |
---|
| 35 | TrimmedDataExporter) |
---|
[9042] | 36 | from waeup.kofa.utils.helpers import iface_names |
---|
[12107] | 37 | from kofacustom.nigeria.interfaces import MessageFactory as _ |
---|
[9042] | 38 | |
---|
[12080] | 39 | class NigeriaStudentExporter(StudentExporter): |
---|
[9042] | 40 | """Exporter for Students. |
---|
| 41 | """ |
---|
| 42 | |
---|
| 43 | fields = tuple(sorted(iface_names( |
---|
| 44 | INigeriaStudent, omit=['loggerInfo']))) + ( |
---|
[9254] | 45 | 'password', 'state', 'history', 'certcode', 'is_postgrad', |
---|
| 46 | 'current_level', 'current_session') |
---|
[9042] | 47 | |
---|
[9044] | 48 | def mangle_value(self, value, name, context=None): |
---|
| 49 | if '_result' in name and value: |
---|
| 50 | value = [eval(entry.to_string()) for entry in value] |
---|
| 51 | return super( |
---|
[12080] | 52 | NigeriaStudentExporter, self).mangle_value( |
---|
[9044] | 53 | value, name, context=context) |
---|
[9042] | 54 | |
---|
[16195] | 55 | class NigeriaTrimmedDataExporter(TrimmedDataExporter): |
---|
| 56 | """The Student Trimmed Data Exporter first filters the set of students |
---|
| 57 | by searching the students catalog. Then it exports a trimmed data set |
---|
| 58 | of this set of students. |
---|
| 59 | """ |
---|
| 60 | |
---|
| 61 | fields = ( |
---|
| 62 | 'student_id', |
---|
| 63 | 'matric_number', |
---|
| 64 | 'reg_number', |
---|
| 65 | 'firstname', |
---|
| 66 | 'middlename', |
---|
| 67 | 'lastname', |
---|
| 68 | 'sex', |
---|
| 69 | 'email', |
---|
| 70 | 'phone', |
---|
| 71 | 'nationality', |
---|
| 72 | 'date_of_birth', |
---|
| 73 | 'state', |
---|
| 74 | 'current_mode', |
---|
| 75 | 'certcode', |
---|
| 76 | 'faccode', |
---|
| 77 | 'depcode', |
---|
| 78 | 'current_level', |
---|
| 79 | 'current_session', |
---|
| 80 | 'current_verdict', |
---|
| 81 | 'entry_session', |
---|
| 82 | 'lg_state', |
---|
| 83 | 'lg_area') |
---|
| 84 | |
---|
| 85 | def mangle_value(self, value, name, context=None): |
---|
[16197] | 86 | if name == 'lg_state' and context.lga: |
---|
[16195] | 87 | value = context.lga.split('_')[0] |
---|
[16197] | 88 | if name == 'lg_area' and context.lga: |
---|
[16195] | 89 | value = '-'.join(context.lga.split('_')[1:]) |
---|
| 90 | return super( |
---|
| 91 | NigeriaTrimmedDataExporter, self).mangle_value( |
---|
| 92 | value, name, context=context) |
---|
| 93 | |
---|
[9042] | 94 | class NigeriaStudentStudyCourseExporter(StudentStudyCourseExporter): |
---|
| 95 | """Exporter for StudentStudyCourses. |
---|
| 96 | """ |
---|
| 97 | |
---|
| 98 | fields = tuple( |
---|
| 99 | sorted(iface_names(INigeriaStudentStudyCourse))) + ('student_id',) |
---|
| 100 | |
---|
[11544] | 101 | class NigeriaStudentStudyLevelExporter(StudentStudyLevelExporter): |
---|
| 102 | """Exporter for StudentStudyLevels. |
---|
| 103 | """ |
---|
| 104 | fields = tuple(sorted(iface_names( |
---|
[12875] | 105 | INigeriaStudentStudyLevel))) + ( |
---|
[11544] | 106 | 'student_id', 'number_of_tickets','certcode') |
---|
[9042] | 107 | |
---|
| 108 | class NigeriaCourseTicketExporter(CourseTicketExporter): |
---|
| 109 | """Exporter for CourseTickets. |
---|
| 110 | """ |
---|
| 111 | |
---|
| 112 | fields = tuple(sorted(iface_names(INigeriaCourseTicket) + |
---|
[11491] | 113 | ['level', 'code', 'level_session'])) + ('student_id', |
---|
| 114 | 'certcode', 'display_fullname') |
---|
[10757] | 115 | |
---|
[12875] | 116 | class NigeriaStudentPaymentExporter(StudentPaymentExporter): |
---|
[10757] | 117 | """Exporter for OnlinePayment instances. |
---|
| 118 | """ |
---|
| 119 | |
---|
| 120 | fields = tuple( |
---|
| 121 | sorted(iface_names( |
---|
| 122 | INigeriaStudentOnlinePayment, exclude_attribs=False, |
---|
[13623] | 123 | omit=['display_item','formatted_p_date']))) + ( |
---|
[10757] | 124 | 'student_id','state','current_session') |
---|
[12107] | 125 | |
---|
[13944] | 126 | class NigeriaDataForBursaryExporter(DataForBursaryExporter): |
---|
| 127 | """Exporter for bursary data. |
---|
| 128 | """ |
---|
| 129 | |
---|
| 130 | fields = tuple( |
---|
| 131 | sorted(iface_names( |
---|
| 132 | INigeriaStudentOnlinePayment, exclude_attribs=False, |
---|
| 133 | omit=['display_item', 'certificate', 'student']))) + ( |
---|
| 134 | 'student_id','matric_number','reg_number', |
---|
| 135 | 'firstname', 'middlename', 'lastname', |
---|
| 136 | 'state','current_session', |
---|
| 137 | 'entry_session', 'entry_mode', |
---|
[15351] | 138 | 'faccode', 'depcode','certcode','lga') |
---|
[13944] | 139 | |
---|
[15351] | 140 | def mangle_value(self, value, name, context=None): |
---|
| 141 | """The mangler fetches the student data. |
---|
| 142 | """ |
---|
| 143 | if context is not None: |
---|
| 144 | student = context.student |
---|
| 145 | if name in [ |
---|
| 146 | 'student_id','matric_number', 'reg_number', |
---|
| 147 | 'firstname', 'middlename', 'lastname', |
---|
| 148 | 'state', 'current_session', |
---|
| 149 | 'entry_session', 'entry_mode', |
---|
| 150 | 'faccode', 'depcode', 'certcode', |
---|
| 151 | 'lga'] and student is not None: |
---|
| 152 | value = getattr(student, name, None) |
---|
| 153 | return super( |
---|
| 154 | StudentPaymentExporter, self).mangle_value( |
---|
| 155 | value, name, context=context) |
---|
| 156 | |
---|
[12107] | 157 | class ClearanceRequestedStudentExporter(StudentExporter): |
---|
[12120] | 158 | """Exporter of data used to assign physical clearance dates. |
---|
[12107] | 159 | """ |
---|
| 160 | |
---|
| 161 | grok.name('clearancerequested') |
---|
| 162 | |
---|
| 163 | fields = ('student_id', 'reg_number', 'display_fullname', |
---|
[12392] | 164 | 'state', 'current_session', 'history', 'physical_clearance_date', |
---|
| 165 | 'email','phone') |
---|
[12107] | 166 | |
---|
| 167 | title = _(u'Clearance Invitation Data') |
---|
| 168 | |
---|
| 169 | def filter_func(self, x, **kw): |
---|
| 170 | # We use this method to post-filter students in state |
---|
| 171 | # 'clearance_requested' |
---|
| 172 | return [student for student in x if student.state == REQUESTED] |
---|
| 173 | |
---|
| 174 | def mangle_value(self, value, name, context=None): |
---|
| 175 | if name == 'history': |
---|
| 176 | # Only show last mesage |
---|
| 177 | value = value.messages[-1] |
---|
| 178 | return super( |
---|
| 179 | StudentExporter, self).mangle_value( |
---|
| 180 | value, name, context=context) |
---|