[12856] | 1 | ## $Id: export.py 12084 2014-11-28 09:54:10Z henrik $ |
---|
| 2 | ## |
---|
| 3 | ## Copyright (C) 2015 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 | """ |
---|
[16390] | 20 | import grok |
---|
[15025] | 21 | from datetime import datetime |
---|
[17862] | 22 | from waeup.kofa.interfaces import IKofaUtils |
---|
| 23 | from zope.component import getUtility |
---|
[12856] | 24 | from waeup.uniben.students.interfaces import ( |
---|
| 25 | ICustomStudent, |
---|
| 26 | ICustomStudentStudyCourse, |
---|
| 27 | ICustomStudentStudyLevel, |
---|
| 28 | ICustomCourseTicket, |
---|
[16390] | 29 | ICustomStudentOnlinePayment, |
---|
| 30 | IMedicalHistory) |
---|
[12856] | 31 | from kofacustom.nigeria.students.export import ( |
---|
| 32 | NigeriaStudentExporter, |
---|
| 33 | NigeriaStudentStudyCourseExporter, |
---|
| 34 | NigeriaStudentStudyLevelExporter, |
---|
| 35 | NigeriaCourseTicketExporter, |
---|
[14856] | 36 | NigeriaStudentPaymentExporter, |
---|
[15025] | 37 | NigeriaDataForBursaryExporter, |
---|
[16498] | 38 | NigeriaTrimmedDataExporter, |
---|
[15025] | 39 | ) |
---|
[16390] | 40 | from waeup.kofa.students.export import ( |
---|
| 41 | SchoolFeePaymentsOverviewExporter, StudentExporterBase) |
---|
[12856] | 42 | from waeup.kofa.utils.helpers import iface_names |
---|
| 43 | |
---|
| 44 | class CustomStudentExporter(NigeriaStudentExporter): |
---|
| 45 | """Exporter for Students. |
---|
| 46 | """ |
---|
| 47 | |
---|
| 48 | fields = tuple(sorted(iface_names( |
---|
| 49 | ICustomStudent, omit=['loggerInfo']))) + ( |
---|
| 50 | 'password', 'state', 'history', 'certcode', 'is_postgrad', |
---|
| 51 | 'current_level', 'current_session') |
---|
| 52 | |
---|
[16498] | 53 | class CustomTrimmedDataExporter(NigeriaTrimmedDataExporter): |
---|
| 54 | """The Student Trimmed Data Exporter first filters the set of students |
---|
| 55 | by searching the students catalog. Then it exports a trimmed data set |
---|
| 56 | of this set of students. |
---|
| 57 | """ |
---|
| 58 | fields = ( |
---|
| 59 | 'student_id', |
---|
| 60 | 'matric_number', |
---|
| 61 | 'reg_number', |
---|
| 62 | 'firstname', |
---|
| 63 | 'middlename', |
---|
| 64 | 'lastname', |
---|
| 65 | 'sex', |
---|
| 66 | 'email', |
---|
| 67 | 'email2', |
---|
| 68 | 'phone', |
---|
[17776] | 69 | 'perm_address', |
---|
[16498] | 70 | 'nationality', |
---|
| 71 | 'date_of_birth', |
---|
| 72 | 'state', |
---|
| 73 | 'current_mode', |
---|
| 74 | 'certcode', |
---|
| 75 | 'faccode', |
---|
| 76 | 'depcode', |
---|
| 77 | 'current_level', |
---|
| 78 | 'current_session', |
---|
| 79 | 'current_verdict', |
---|
| 80 | 'entry_session', |
---|
| 81 | 'lg_state', |
---|
[17624] | 82 | 'lg_area', |
---|
[17785] | 83 | 'flash_notice', |
---|
[17806] | 84 | 'physical_clearance_date', |
---|
| 85 | 'former_matric', |
---|
| 86 | 'hq_matric_no', |
---|
| 87 | 'hq2_matric_no') |
---|
[16498] | 88 | |
---|
[12856] | 89 | class CustomStudentStudyCourseExporter(NigeriaStudentStudyCourseExporter): |
---|
| 90 | """Exporter for StudentStudyCourses. |
---|
| 91 | """ |
---|
| 92 | |
---|
| 93 | fields = tuple( |
---|
[16837] | 94 | sorted(iface_names(ICustomStudentStudyCourse))) + ( |
---|
| 95 | 'student_id', 'previous') |
---|
[12856] | 96 | |
---|
| 97 | class CustomStudentStudyLevelExporter(NigeriaStudentStudyLevelExporter): |
---|
| 98 | """Exporter for StudentStudyLevels. |
---|
| 99 | """ |
---|
| 100 | #: Fieldnames considered by this exporter |
---|
| 101 | fields = tuple(sorted(iface_names( |
---|
[12879] | 102 | ICustomStudentStudyLevel))) + ( |
---|
[16837] | 103 | 'student_id', 'number_of_tickets','certcode', 'previous') |
---|
[12856] | 104 | |
---|
| 105 | class CustomCourseTicketExporter(NigeriaCourseTicketExporter): |
---|
| 106 | """Exporter for CourseTickets. |
---|
| 107 | """ |
---|
| 108 | |
---|
| 109 | fields = tuple(sorted(iface_names(ICustomCourseTicket) + |
---|
| 110 | ['level', 'code', 'level_session'])) + ('student_id', |
---|
[17558] | 111 | 'certcode', 'display_fullname', 'previous', 'matric_number') |
---|
[12856] | 112 | |
---|
[12879] | 113 | class CustomStudentPaymentExporter(NigeriaStudentPaymentExporter): |
---|
[12856] | 114 | """Exporter for OnlinePayment instances. |
---|
| 115 | """ |
---|
| 116 | |
---|
| 117 | fields = tuple( |
---|
| 118 | sorted(iface_names( |
---|
| 119 | ICustomStudentOnlinePayment, exclude_attribs=False, |
---|
[13621] | 120 | omit=['display_item']))) + ( |
---|
[12856] | 121 | 'student_id','state','current_session') |
---|
| 122 | |
---|
[14856] | 123 | class CustomDataForBursaryExporter(NigeriaDataForBursaryExporter): |
---|
| 124 | """ |
---|
| 125 | """ |
---|
| 126 | |
---|
| 127 | fields = tuple( |
---|
| 128 | sorted(iface_names( |
---|
| 129 | ICustomStudentOnlinePayment, exclude_attribs=False, |
---|
| 130 | omit=['display_item', 'certificate', 'student']))) + ( |
---|
| 131 | 'student_id','matric_number','reg_number', |
---|
| 132 | 'firstname', 'middlename', 'lastname', |
---|
| 133 | 'state','current_session', |
---|
| 134 | 'entry_session', 'entry_mode', |
---|
| 135 | 'faccode', 'depcode','certcode') |
---|
[15025] | 136 | |
---|
[15048] | 137 | class CustomSchoolFeePaymentsOverviewExporter(SchoolFeePaymentsOverviewExporter): |
---|
[15025] | 138 | |
---|
| 139 | curr_year = datetime.now().year |
---|
[15044] | 140 | year_range = range(curr_year - 14, curr_year + 1) # 3 more years in Uniben |
---|
[15025] | 141 | year_range_tuple = tuple([str(year) for year in year_range]) |
---|
| 142 | |
---|
[16476] | 143 | fields = ('student_id', 'matric_number', 'firstname', 'middlename', |
---|
| 144 | 'lastname', 'state', 'certcode', 'faccode', 'depcode', 'is_postgrad', |
---|
[15025] | 145 | 'current_level', 'current_session', 'current_mode', |
---|
[16498] | 146 | 'entry_session', 'reg_number', 'email2', 'sex' |
---|
[15025] | 147 | ) + year_range_tuple |
---|
[16390] | 148 | |
---|
| 149 | class MedicalHistoryExporter(grok.GlobalUtility, StudentExporterBase): |
---|
| 150 | """ |
---|
| 151 | """ |
---|
| 152 | grok.name('medicalhistory') |
---|
| 153 | |
---|
| 154 | fields = tuple( |
---|
| 155 | sorted(iface_names( |
---|
| 156 | IMedicalHistory, exclude_attribs=False,))) + ( |
---|
| 157 | 'student_id','display_fullname', 'matric_number', 'faccode', |
---|
[17395] | 158 | 'depcode', 'state','current_session', 'current_level', 'genotype', 'bloodgroup') |
---|
[16390] | 159 | title = 'Medical Questionnaire Data' |
---|
| 160 | |
---|
| 161 | def mangle_value(self, value, name, context=None): |
---|
| 162 | """The mangler determines the titles of faculty, department |
---|
| 163 | and certificate. It also computes the path of passport image file |
---|
| 164 | stored in the filesystem. |
---|
| 165 | """ |
---|
| 166 | if context is not None: |
---|
| 167 | student = context.student |
---|
| 168 | if name in ('student_id','display_fullname', |
---|
| 169 | 'matric_number', 'faccode', |
---|
| 170 | 'depcode', 'state','current_session', |
---|
[17395] | 171 | 'current_level', |
---|
| 172 | 'genotype', 'bloodgroup') and student is not None: |
---|
[16390] | 173 | value = getattr(student, name, None) |
---|
| 174 | return super( |
---|
| 175 | MedicalHistoryExporter, self).mangle_value( |
---|
| 176 | value, name, context=context) |
---|
[17396] | 177 | |
---|
| 178 | |
---|
| 179 | class NYSCExporter(SchoolFeePaymentsOverviewExporter): |
---|
| 180 | """ |
---|
| 181 | """ |
---|
| 182 | grok.name('nysc') |
---|
| 183 | curr_year = datetime.now().year |
---|
| 184 | year_range = range(curr_year - 11, curr_year + 1) |
---|
| 185 | year_range_tuple = tuple([str(year) for year in year_range]) |
---|
| 186 | fields = ('student_id', |
---|
| 187 | 'matric_number', |
---|
| 188 | 'reg_number', |
---|
| 189 | 'firstname', |
---|
| 190 | 'middlename', |
---|
| 191 | 'lastname', |
---|
| 192 | 'sex', |
---|
[17897] | 193 | 'email', |
---|
| 194 | 'email2', |
---|
| 195 | 'phone', |
---|
[17396] | 196 | 'nationality', |
---|
| 197 | 'date_of_birth', |
---|
| 198 | 'state', |
---|
[17834] | 199 | 'lg_state', |
---|
| 200 | 'lg_area', |
---|
[17396] | 201 | 'current_mode', |
---|
[17862] | 202 | 'certificate', |
---|
[17396] | 203 | 'faccode', |
---|
| 204 | 'depcode', |
---|
| 205 | 'current_level', |
---|
| 206 | 'current_session', |
---|
| 207 | 'current_verdict', |
---|
[17831] | 208 | 'entry_session', |
---|
[17852] | 209 | 'nysc_verdict', |
---|
[17827] | 210 | 'nysc_senate_info', |
---|
| 211 | 'nysc_date_of_graduation', |
---|
| 212 | 'nysc_updated', |
---|
[17835] | 213 | 'nysc_processed', |
---|
[17396] | 214 | ) + year_range_tuple |
---|
| 215 | title = u'NYSC Indication' |
---|
| 216 | |
---|
| 217 | def filter_func(self, x, **kw): |
---|
| 218 | students = list() |
---|
| 219 | for student in x: |
---|
[17835] | 220 | if student.nysc == True and student.nysc_processed == False: |
---|
[17396] | 221 | students.append(student) |
---|
[17834] | 222 | return students |
---|
| 223 | |
---|
| 224 | def mangle_value(self, value, name, context=None): |
---|
[17862] | 225 | verdicts = getUtility(IKofaUtils).VERDICTS_DICT |
---|
[17849] | 226 | if name in ('lg_state', 'lg_area') and context.lga: |
---|
| 227 | value = context.lga |
---|
| 228 | if value.startswith('cross_river') or value.startswith('akwa_ibom'): |
---|
| 229 | value = context.lga.replace('_', '-', 1) |
---|
| 230 | if name == 'lg_state': |
---|
| 231 | value = value.split('_')[0] |
---|
| 232 | if name == 'lg_area': |
---|
| 233 | value = '-'.join(value.split('_')[1:]) |
---|
[17862] | 234 | if name == 'certificate': |
---|
| 235 | cert = getattr(context.get('studycourse', None), 'certificate', None) |
---|
| 236 | if cert is not None: |
---|
| 237 | value = cert.title |
---|
| 238 | if name == 'nysc_verdict' and value: |
---|
| 239 | value = verdicts[value] |
---|
[17834] | 240 | return super( |
---|
| 241 | NYSCExporter, self).mangle_value( |
---|
| 242 | value, name, context=context) |
---|