[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 |
---|
[17905] | 21 | import os |
---|
[15025] | 22 | from datetime import datetime |
---|
[17905] | 23 | from waeup.kofa.interfaces import ( |
---|
| 24 | IExtFileStore, IFileStoreNameChooser, IKofaUtils) |
---|
[17862] | 25 | from zope.component import getUtility |
---|
[12856] | 26 | from waeup.uniben.students.interfaces import ( |
---|
| 27 | ICustomStudent, |
---|
| 28 | ICustomStudentStudyCourse, |
---|
| 29 | ICustomStudentStudyLevel, |
---|
| 30 | ICustomCourseTicket, |
---|
[16390] | 31 | ICustomStudentOnlinePayment, |
---|
| 32 | IMedicalHistory) |
---|
[12856] | 33 | from kofacustom.nigeria.students.export import ( |
---|
| 34 | NigeriaStudentExporter, |
---|
| 35 | NigeriaStudentStudyCourseExporter, |
---|
| 36 | NigeriaStudentStudyLevelExporter, |
---|
| 37 | NigeriaCourseTicketExporter, |
---|
[14856] | 38 | NigeriaStudentPaymentExporter, |
---|
[15025] | 39 | NigeriaDataForBursaryExporter, |
---|
[16498] | 40 | NigeriaTrimmedDataExporter, |
---|
[15025] | 41 | ) |
---|
[16390] | 42 | from waeup.kofa.students.export import ( |
---|
[18098] | 43 | get_tickets_for_lecturer, |
---|
| 44 | SchoolFeePaymentsOverviewExporter, |
---|
| 45 | StudentExporterBase, |
---|
| 46 | DataForLecturerExporter) |
---|
[12856] | 47 | from waeup.kofa.utils.helpers import iface_names |
---|
| 48 | |
---|
| 49 | class CustomStudentExporter(NigeriaStudentExporter): |
---|
| 50 | """Exporter for Students. |
---|
| 51 | """ |
---|
| 52 | |
---|
| 53 | fields = tuple(sorted(iface_names( |
---|
| 54 | ICustomStudent, omit=['loggerInfo']))) + ( |
---|
| 55 | 'password', 'state', 'history', 'certcode', 'is_postgrad', |
---|
| 56 | 'current_level', 'current_session') |
---|
| 57 | |
---|
[16498] | 58 | class CustomTrimmedDataExporter(NigeriaTrimmedDataExporter): |
---|
| 59 | """The Student Trimmed Data Exporter first filters the set of students |
---|
| 60 | by searching the students catalog. Then it exports a trimmed data set |
---|
| 61 | of this set of students. |
---|
| 62 | """ |
---|
| 63 | fields = ( |
---|
| 64 | 'student_id', |
---|
| 65 | 'matric_number', |
---|
| 66 | 'reg_number', |
---|
| 67 | 'firstname', |
---|
| 68 | 'middlename', |
---|
| 69 | 'lastname', |
---|
| 70 | 'sex', |
---|
| 71 | 'email', |
---|
| 72 | 'email2', |
---|
| 73 | 'phone', |
---|
[17776] | 74 | 'perm_address', |
---|
[16498] | 75 | 'nationality', |
---|
| 76 | 'date_of_birth', |
---|
| 77 | 'state', |
---|
| 78 | 'current_mode', |
---|
| 79 | 'certcode', |
---|
| 80 | 'faccode', |
---|
| 81 | 'depcode', |
---|
| 82 | 'current_level', |
---|
| 83 | 'current_session', |
---|
| 84 | 'current_verdict', |
---|
| 85 | 'entry_session', |
---|
| 86 | 'lg_state', |
---|
[17624] | 87 | 'lg_area', |
---|
[17785] | 88 | 'flash_notice', |
---|
[17806] | 89 | 'physical_clearance_date', |
---|
| 90 | 'former_matric', |
---|
| 91 | 'hq_matric_no', |
---|
[17905] | 92 | 'hq2_matric_no', |
---|
[17919] | 93 | ) |
---|
[16498] | 94 | |
---|
[17919] | 95 | #def mangle_value(self, value, name, context=None): |
---|
| 96 | # if name == 'routing_slip_path': |
---|
| 97 | # file_id = IFileStoreNameChooser(context).chooseName( |
---|
| 98 | # attr='routingslip.pdf') |
---|
| 99 | # os_path = getUtility(IExtFileStore)._pathFromFileID(file_id) |
---|
| 100 | # if not os.path.exists(os_path): |
---|
| 101 | # value = None |
---|
| 102 | # else: |
---|
| 103 | # value = '/'.join(os_path.split('/')[-4:]) |
---|
| 104 | # return super( |
---|
| 105 | # CustomTrimmedDataExporter, self).mangle_value( |
---|
| 106 | # value, name, context=context) |
---|
[17905] | 107 | |
---|
| 108 | |
---|
[12856] | 109 | class CustomStudentStudyCourseExporter(NigeriaStudentStudyCourseExporter): |
---|
| 110 | """Exporter for StudentStudyCourses. |
---|
| 111 | """ |
---|
| 112 | |
---|
| 113 | fields = tuple( |
---|
[16837] | 114 | sorted(iface_names(ICustomStudentStudyCourse))) + ( |
---|
| 115 | 'student_id', 'previous') |
---|
[12856] | 116 | |
---|
| 117 | class CustomStudentStudyLevelExporter(NigeriaStudentStudyLevelExporter): |
---|
| 118 | """Exporter for StudentStudyLevels. |
---|
| 119 | """ |
---|
| 120 | #: Fieldnames considered by this exporter |
---|
| 121 | fields = tuple(sorted(iface_names( |
---|
[12879] | 122 | ICustomStudentStudyLevel))) + ( |
---|
[16837] | 123 | 'student_id', 'number_of_tickets','certcode', 'previous') |
---|
[12856] | 124 | |
---|
| 125 | class CustomCourseTicketExporter(NigeriaCourseTicketExporter): |
---|
| 126 | """Exporter for CourseTickets. |
---|
| 127 | """ |
---|
| 128 | |
---|
| 129 | fields = tuple(sorted(iface_names(ICustomCourseTicket) + |
---|
| 130 | ['level', 'code', 'level_session'])) + ('student_id', |
---|
[17558] | 131 | 'certcode', 'display_fullname', 'previous', 'matric_number') |
---|
[12856] | 132 | |
---|
[12879] | 133 | class CustomStudentPaymentExporter(NigeriaStudentPaymentExporter): |
---|
[12856] | 134 | """Exporter for OnlinePayment instances. |
---|
| 135 | """ |
---|
| 136 | |
---|
| 137 | fields = tuple( |
---|
| 138 | sorted(iface_names( |
---|
| 139 | ICustomStudentOnlinePayment, exclude_attribs=False, |
---|
[13621] | 140 | omit=['display_item']))) + ( |
---|
[12856] | 141 | 'student_id','state','current_session') |
---|
| 142 | |
---|
[14856] | 143 | class CustomDataForBursaryExporter(NigeriaDataForBursaryExporter): |
---|
| 144 | """ |
---|
| 145 | """ |
---|
| 146 | |
---|
| 147 | fields = tuple( |
---|
| 148 | sorted(iface_names( |
---|
| 149 | ICustomStudentOnlinePayment, exclude_attribs=False, |
---|
| 150 | omit=['display_item', 'certificate', 'student']))) + ( |
---|
| 151 | 'student_id','matric_number','reg_number', |
---|
| 152 | 'firstname', 'middlename', 'lastname', |
---|
| 153 | 'state','current_session', |
---|
| 154 | 'entry_session', 'entry_mode', |
---|
| 155 | 'faccode', 'depcode','certcode') |
---|
[15025] | 156 | |
---|
[18098] | 157 | class CustomDataForLecturerExporter(DataForLecturerExporter): |
---|
| 158 | """ |
---|
| 159 | """ |
---|
| 160 | |
---|
| 161 | fields = ('matric_number', 'student_id', 'display_fullname', |
---|
| 162 | 'level', 'code', 'level_session', |
---|
| 163 | 'ca', 'exam', |
---|
| 164 | 'score', |
---|
| 165 | ) |
---|
| 166 | |
---|
| 167 | def filter_func(self, x, **kw): |
---|
| 168 | tickets = get_tickets_for_lecturer(x, **kw) |
---|
| 169 | return sorted([ticket for ticket in tickets], |
---|
| 170 | key=lambda ticket: str(ticket.fcode) + str(ticket.dcode) |
---|
| 171 | + str(ticket.certcode) |
---|
| 172 | + str(ticket.student.matric_number)) |
---|
| 173 | |
---|
| 174 | def mangle_value(self, value, name, context=None): |
---|
| 175 | """The mangler determines the student's id and fullname. |
---|
| 176 | """ |
---|
| 177 | if context is not None: |
---|
| 178 | student = context.student |
---|
| 179 | if name in ('matric_number', |
---|
| 180 | 'reg_number', |
---|
| 181 | 'student_id', |
---|
| 182 | 'display_fullname',) and student is not None: |
---|
| 183 | value = getattr(student, name, None) |
---|
| 184 | if name in ('ca','exam',): |
---|
| 185 | value ='' |
---|
| 186 | return super( |
---|
| 187 | DataForLecturerExporter, self).mangle_value( |
---|
| 188 | value, name, context=context) |
---|
| 189 | |
---|
[15048] | 190 | class CustomSchoolFeePaymentsOverviewExporter(SchoolFeePaymentsOverviewExporter): |
---|
[15025] | 191 | |
---|
| 192 | curr_year = datetime.now().year |
---|
[15044] | 193 | year_range = range(curr_year - 14, curr_year + 1) # 3 more years in Uniben |
---|
[15025] | 194 | year_range_tuple = tuple([str(year) for year in year_range]) |
---|
| 195 | |
---|
[16476] | 196 | fields = ('student_id', 'matric_number', 'firstname', 'middlename', |
---|
| 197 | 'lastname', 'state', 'certcode', 'faccode', 'depcode', 'is_postgrad', |
---|
[15025] | 198 | 'current_level', 'current_session', 'current_mode', |
---|
[16498] | 199 | 'entry_session', 'reg_number', 'email2', 'sex' |
---|
[15025] | 200 | ) + year_range_tuple |
---|
[16390] | 201 | |
---|
| 202 | class MedicalHistoryExporter(grok.GlobalUtility, StudentExporterBase): |
---|
| 203 | """ |
---|
| 204 | """ |
---|
| 205 | grok.name('medicalhistory') |
---|
| 206 | |
---|
| 207 | fields = tuple( |
---|
| 208 | sorted(iface_names( |
---|
| 209 | IMedicalHistory, exclude_attribs=False,))) + ( |
---|
| 210 | 'student_id','display_fullname', 'matric_number', 'faccode', |
---|
[17395] | 211 | 'depcode', 'state','current_session', 'current_level', 'genotype', 'bloodgroup') |
---|
[16390] | 212 | title = 'Medical Questionnaire Data' |
---|
| 213 | |
---|
| 214 | def mangle_value(self, value, name, context=None): |
---|
| 215 | """The mangler determines the titles of faculty, department |
---|
| 216 | and certificate. It also computes the path of passport image file |
---|
| 217 | stored in the filesystem. |
---|
| 218 | """ |
---|
| 219 | if context is not None: |
---|
| 220 | student = context.student |
---|
| 221 | if name in ('student_id','display_fullname', |
---|
| 222 | 'matric_number', 'faccode', |
---|
| 223 | 'depcode', 'state','current_session', |
---|
[17395] | 224 | 'current_level', |
---|
| 225 | 'genotype', 'bloodgroup') and student is not None: |
---|
[16390] | 226 | value = getattr(student, name, None) |
---|
| 227 | return super( |
---|
| 228 | MedicalHistoryExporter, self).mangle_value( |
---|
| 229 | value, name, context=context) |
---|
[17396] | 230 | |
---|
[17915] | 231 | def get_routingslip_exists(students, **kw): |
---|
| 232 | """Get students with outstanding certificate courses. |
---|
| 233 | """ |
---|
| 234 | students_with_slip = [] |
---|
| 235 | for student in students: |
---|
| 236 | file_id = IFileStoreNameChooser(student).chooseName( |
---|
| 237 | attr='routingslip.pdf') |
---|
| 238 | os_path = getUtility(IExtFileStore)._pathFromFileID(file_id) |
---|
| 239 | if os.path.exists(os_path): |
---|
| 240 | students_with_slip.append(student) |
---|
| 241 | return students_with_slip |
---|
[17396] | 242 | |
---|
[17915] | 243 | class RoutingSlipExporter(grok.GlobalUtility, StudentExporterBase): |
---|
| 244 | """ |
---|
| 245 | """ |
---|
| 246 | grok.name('routingslip') |
---|
| 247 | |
---|
[17929] | 248 | fields = ('student_id', 'matric_number',) |
---|
[17915] | 249 | title = 'Routing Slip Exists' |
---|
| 250 | |
---|
| 251 | def filter_func(self, x, **kw): |
---|
| 252 | return get_routingslip_exists(x, **kw) |
---|
| 253 | |
---|
| 254 | #def mangle_value(self, value, name, context=None): |
---|
| 255 | # if name == 'routing_slip': |
---|
| 256 | # file_id = IFileStoreNameChooser(context).chooseName( |
---|
| 257 | # attr='routingslip.pdf') |
---|
| 258 | # os_path = getUtility(IExtFileStore)._pathFromFileID(file_id) |
---|
| 259 | # if not os.path.exists(os_path): |
---|
| 260 | # value = None |
---|
| 261 | # else: |
---|
| 262 | # value = '1' |
---|
| 263 | # return super( |
---|
| 264 | # RoutingSlipExporter, self).mangle_value( |
---|
| 265 | # value, name, context=context) |
---|
| 266 | |
---|
| 267 | |
---|
[17396] | 268 | class NYSCExporter(SchoolFeePaymentsOverviewExporter): |
---|
| 269 | """ |
---|
| 270 | """ |
---|
| 271 | grok.name('nysc') |
---|
| 272 | curr_year = datetime.now().year |
---|
| 273 | year_range = range(curr_year - 11, curr_year + 1) |
---|
| 274 | year_range_tuple = tuple([str(year) for year in year_range]) |
---|
| 275 | fields = ('student_id', |
---|
| 276 | 'matric_number', |
---|
| 277 | 'reg_number', |
---|
| 278 | 'firstname', |
---|
| 279 | 'middlename', |
---|
| 280 | 'lastname', |
---|
| 281 | 'sex', |
---|
[17897] | 282 | 'email', |
---|
| 283 | 'email2', |
---|
| 284 | 'phone', |
---|
[17396] | 285 | 'nationality', |
---|
| 286 | 'date_of_birth', |
---|
| 287 | 'state', |
---|
[17834] | 288 | 'lg_state', |
---|
| 289 | 'lg_area', |
---|
[17396] | 290 | 'current_mode', |
---|
[17862] | 291 | 'certificate', |
---|
[17396] | 292 | 'faccode', |
---|
| 293 | 'depcode', |
---|
| 294 | 'current_level', |
---|
| 295 | 'current_session', |
---|
| 296 | 'current_verdict', |
---|
[17831] | 297 | 'entry_session', |
---|
[17852] | 298 | 'nysc_verdict', |
---|
[17827] | 299 | 'nysc_senate_info', |
---|
| 300 | 'nysc_date_of_graduation', |
---|
| 301 | 'nysc_updated', |
---|
[17835] | 302 | 'nysc_processed', |
---|
[17396] | 303 | ) + year_range_tuple |
---|
| 304 | title = u'NYSC Indication' |
---|
| 305 | |
---|
| 306 | def filter_func(self, x, **kw): |
---|
| 307 | students = list() |
---|
| 308 | for student in x: |
---|
[17835] | 309 | if student.nysc == True and student.nysc_processed == False: |
---|
[17396] | 310 | students.append(student) |
---|
[17834] | 311 | return students |
---|
| 312 | |
---|
| 313 | def mangle_value(self, value, name, context=None): |
---|
[17862] | 314 | verdicts = getUtility(IKofaUtils).VERDICTS_DICT |
---|
[17849] | 315 | if name in ('lg_state', 'lg_area') and context.lga: |
---|
| 316 | value = context.lga |
---|
| 317 | if value.startswith('cross_river') or value.startswith('akwa_ibom'): |
---|
| 318 | value = context.lga.replace('_', '-', 1) |
---|
| 319 | if name == 'lg_state': |
---|
| 320 | value = value.split('_')[0] |
---|
| 321 | if name == 'lg_area': |
---|
| 322 | value = '-'.join(value.split('_')[1:]) |
---|
[17862] | 323 | if name == 'certificate': |
---|
| 324 | cert = getattr(context.get('studycourse', None), 'certificate', None) |
---|
| 325 | if cert is not None: |
---|
| 326 | value = cert.title |
---|
| 327 | if name == 'nysc_verdict' and value: |
---|
| 328 | value = verdicts[value] |
---|
[17834] | 329 | return super( |
---|
| 330 | NYSCExporter, self).mangle_value( |
---|
| 331 | value, name, context=context) |
---|