[7419] | 1 | ## $Id: utils.py 12188 2014-12-10 09:33:27Z 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 | ## |
---|
[7151] | 18 | import grok |
---|
[9190] | 19 | import random |
---|
[8599] | 20 | from time import time |
---|
[9950] | 21 | from zope.component import createObject, getUtility |
---|
[8475] | 22 | from waeup.kofa.interfaces import CLEARED, RETURNING, PAID |
---|
[8834] | 23 | from kofacustom.nigeria.students.utils import NigeriaStudentsUtils |
---|
[8247] | 24 | from waeup.kofa.accesscodes import create_accesscode |
---|
[9143] | 25 | from waeup.kofa.interfaces import CLEARED, RETURNING |
---|
[8460] | 26 | from waeup.fceokene.interfaces import MessageFactory as _ |
---|
[9950] | 27 | from waeup.kofa.browser.interfaces import IPDFCreator |
---|
[9982] | 28 | from waeup.kofa.students.utils import trans |
---|
[10388] | 29 | from waeup.fceokene.interswitch.browser import GATEWAY_AMT |
---|
[6902] | 30 | |
---|
[11919] | 31 | # Very special school fee configuration, should be moved to |
---|
| 32 | # a seperate file. |
---|
| 33 | |
---|
| 34 | ARTS = ('CRS','ISS','HIS','MUS','ECO','GEO','POL','SOS','CCA','ECU', |
---|
| 35 | 'THA','GED','GSE','PES','SPC','ENG','FRE','ARB','HAU','IGB', |
---|
| 36 | 'YOR','NCRS','NISS','NHIS','NMUS','NECO','NGEO','NPOL', |
---|
| 37 | 'NCCA','NECU','NTHA','NGED','NGSE','NPES','NSPC','NENG', |
---|
| 38 | 'NFRE','NARB','NHAU','NIGB','NYOR','NSOS') |
---|
| 39 | |
---|
[8834] | 40 | class CustomStudentsUtils(NigeriaStudentsUtils): |
---|
[7151] | 41 | """A collection of customized methods. |
---|
| 42 | |
---|
| 43 | """ |
---|
| 44 | |
---|
[10661] | 45 | VERDICTS_DICT = { |
---|
| 46 | '0': 'not yet', |
---|
| 47 | 'A': 'Successful student', |
---|
| 48 | 'B': 'Student with carryover courses', |
---|
| 49 | 'C': 'Student on probation', |
---|
| 50 | 'D': 'Withdrawn from the faculty', |
---|
| 51 | #'E': 'Student who were previously on probation', |
---|
| 52 | #'F': 'Medical case', |
---|
| 53 | 'G': 'Absent from examination', |
---|
| 54 | #'H': 'Withheld results', |
---|
| 55 | 'I': 'Expelled/rusticated/suspended student', |
---|
| 56 | 'J': 'Temporary withdrawn from the university', |
---|
| 57 | #'K': 'Unregistered student', |
---|
| 58 | 'L': 'Referred student', |
---|
| 59 | 'M': 'Reinstatement', |
---|
| 60 | #'N': 'Student on transfer', |
---|
| 61 | 'O': 'NCE-III repeater', |
---|
| 62 | #'Y': 'No previous verdict', |
---|
| 63 | #'X': 'New 300 level student (Uniben)', |
---|
| 64 | #'Z': 'Successful student (provisional)', |
---|
| 65 | 'A1': 'First Class', |
---|
| 66 | 'A2': 'Second Class Upper', |
---|
| 67 | 'A3': 'Second Class Lower', |
---|
| 68 | 'A4': 'Third Class', |
---|
| 69 | 'A5': 'Pass', |
---|
| 70 | 'A6': 'Distinction', |
---|
| 71 | 'A7': 'Credit', |
---|
| 72 | 'A8': 'Merit', |
---|
| 73 | 'OPDE': 'PDE repeater', |
---|
| 74 | } |
---|
| 75 | |
---|
[9190] | 76 | def selectBed(self, available_beds): |
---|
| 77 | """Randomly select a bed from a list of available beds. |
---|
| 78 | |
---|
| 79 | """ |
---|
| 80 | return random.choice(available_beds) |
---|
| 81 | |
---|
[8270] | 82 | def getReturningData(self, student): |
---|
| 83 | """ This method defines what happens after school fee payment |
---|
[8319] | 84 | of returning students depending on the student's senate verdict. |
---|
[8270] | 85 | """ |
---|
[8319] | 86 | prev_level = student['studycourse'].current_level |
---|
| 87 | cur_verdict = student['studycourse'].current_verdict |
---|
| 88 | if cur_verdict in ('A','B','L','M','N','Z',): |
---|
| 89 | # Successful student |
---|
| 90 | new_level = divmod(int(prev_level),100)[0]*100 + 100 |
---|
[9923] | 91 | elif cur_verdict in ('C','O'): |
---|
[8319] | 92 | # Student on probation |
---|
| 93 | new_level = int(prev_level) + 10 |
---|
| 94 | else: |
---|
| 95 | # Student is somehow in an undefined state. |
---|
| 96 | # Level has to be set manually. |
---|
| 97 | new_level = prev_level |
---|
[9923] | 98 | if cur_verdict == 'O': |
---|
| 99 | new_session = student['studycourse'].current_session |
---|
| 100 | else: |
---|
| 101 | new_session = student['studycourse'].current_session + 1 |
---|
[8270] | 102 | return new_session, new_level |
---|
| 103 | |
---|
[9153] | 104 | def setPaymentDetails(self, category, student, |
---|
| 105 | previous_session=None, previous_level=None): |
---|
[8599] | 106 | """Create Payment object and set the payment data of a student for |
---|
| 107 | the payment category specified. |
---|
| 108 | |
---|
| 109 | """ |
---|
[8306] | 110 | details = {} |
---|
[8599] | 111 | p_item = u'' |
---|
| 112 | amount = 0.0 |
---|
| 113 | error = u'' |
---|
[9153] | 114 | if previous_session: |
---|
| 115 | return _('Previous session payment not yet implemented.'), None |
---|
[8599] | 116 | p_session = student['studycourse'].current_session |
---|
| 117 | p_level = student['studycourse'].current_level |
---|
[9153] | 118 | p_current = True |
---|
[9525] | 119 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 120 | if academic_session == None: |
---|
[8599] | 121 | return _(u'Session configuration object is not available.'), None |
---|
[9525] | 122 | # Determine fee. |
---|
[7151] | 123 | if category == 'transfer': |
---|
[8599] | 124 | amount = academic_session.transfer_fee |
---|
[7151] | 125 | elif category == 'gown': |
---|
[8599] | 126 | amount = academic_session.gown_fee |
---|
[7151] | 127 | elif category == 'bed_allocation': |
---|
[8599] | 128 | amount = academic_session.booking_fee |
---|
[7151] | 129 | elif category == 'hostel_maintenance': |
---|
[9611] | 130 | current_session = student['studycourse'].current_session |
---|
| 131 | bedticket = student['accommodation'].get(str(current_session), None) |
---|
| 132 | if bedticket is not None and bedticket.bed is not None: |
---|
| 133 | p_item = bedticket.bed_coordinates |
---|
| 134 | else: |
---|
| 135 | return _(u'You have not yet booked accommodation.'), None |
---|
| 136 | acc_details = self.getAccommodationDetails(student) |
---|
| 137 | if current_session != acc_details['booking_session']: |
---|
| 138 | return _(u'Current session does not match accommodation session.'), None |
---|
[9612] | 139 | if student.current_mode.endswith('_sw') or student.current_mode == 'pd_ft': |
---|
[10520] | 140 | amount = 2500.0 #removed interswitch fee |
---|
[9612] | 141 | else: |
---|
[12188] | 142 | amount = 5000.0 #removed interswitch fee |
---|
[7151] | 143 | elif category == 'clearance': |
---|
[9143] | 144 | amount = academic_session.clearance_fee |
---|
[8599] | 145 | try: |
---|
| 146 | p_item = student['studycourse'].certificate.code |
---|
| 147 | except (AttributeError, TypeError): |
---|
| 148 | return _('Study course data are incomplete.'), None |
---|
[11932] | 149 | elif category == 'third_semester' and student.current_mode == 'nce_ft': |
---|
[11919] | 150 | if student.depcode in ARTS: |
---|
[11932] | 151 | amount = 6835 |
---|
[11919] | 152 | else: |
---|
[11932] | 153 | amount = 7763 |
---|
[7151] | 154 | elif category == 'schoolfee': |
---|
[8599] | 155 | try: |
---|
| 156 | certificate = student['studycourse'].certificate |
---|
| 157 | p_item = certificate.code |
---|
| 158 | except (AttributeError, TypeError): |
---|
| 159 | return _('Study course data are incomplete.'), None |
---|
[9143] | 160 | |
---|
[10012] | 161 | if student.state not in (CLEARED, RETURNING): |
---|
| 162 | return _('Wrong state.'), None |
---|
| 163 | |
---|
[10661] | 164 | # PDE repeater |
---|
| 165 | if student.current_verdict == 'OPDE': |
---|
[11850] | 166 | amount = 23000 |
---|
[10660] | 167 | # PDE |
---|
| 168 | elif student.current_mode == 'pd_ft': |
---|
[11850] | 169 | amount = 35300 |
---|
[10012] | 170 | # UG |
---|
| 171 | elif student.current_mode == 'ug_ft': |
---|
[10876] | 172 | # Introducing returning students fee for 'ug_ft' for 1st time |
---|
| 173 | # on 07/01/2014 |
---|
| 174 | if student.state == CLEARED: |
---|
| 175 | amount = 65650 |
---|
| 176 | else: |
---|
| 177 | amount = 56150 |
---|
[10012] | 178 | # NCE |
---|
[9143] | 179 | elif not student.current_mode.endswith('_sw'): |
---|
| 180 | # PRENCE |
---|
| 181 | if student.current_level == 10 and student.state == CLEARED: |
---|
| 182 | if student.depcode in ARTS: |
---|
[12188] | 183 | amount = 17500 |
---|
[9143] | 184 | else: |
---|
[12188] | 185 | amount = 18000 |
---|
[10012] | 186 | # NCE I fresh |
---|
[9143] | 187 | elif student.current_level == 100 and student.state == CLEARED: |
---|
| 188 | if student.depcode in ARTS: |
---|
[12188] | 189 | amount = 14325 |
---|
[9143] | 190 | else: |
---|
[12188] | 191 | amount = 14825 |
---|
[10012] | 192 | # NCE II |
---|
[9143] | 193 | elif student.current_level in (100, 110, 120) and \ |
---|
| 194 | student.state == RETURNING: |
---|
| 195 | if student.depcode in ARTS: |
---|
[12188] | 196 | amount = 13375 |
---|
[9143] | 197 | else: |
---|
[12188] | 198 | amount = 13875 |
---|
[10012] | 199 | # NCE III |
---|
[9143] | 200 | elif student.current_level in (200, 210, 220): |
---|
| 201 | if student.depcode in ARTS: |
---|
[12188] | 202 | amount = 13375 |
---|
[9143] | 203 | else: |
---|
[12188] | 204 | amount = 13875 |
---|
[10012] | 205 | # NCE III repeater |
---|
[9143] | 206 | elif student.current_level in (300, 310, 320) and \ |
---|
| 207 | student.current_verdict == 'O': |
---|
| 208 | if student.depcode in ARTS: |
---|
[12188] | 209 | amount = 11475 |
---|
[9143] | 210 | else: |
---|
[12188] | 211 | amount = 11975 |
---|
[10012] | 212 | # NCE III spillover |
---|
[9143] | 213 | elif student.current_level in (300, 310, 320) and \ |
---|
| 214 | student.current_verdict == 'B': |
---|
| 215 | if student.depcode in ARTS: |
---|
[12188] | 216 | amount = 11975 |
---|
[9143] | 217 | else: |
---|
[12188] | 218 | amount = 11975 |
---|
[10012] | 219 | # NCE III second spillover |
---|
[9143] | 220 | elif student.current_level in (400, 410, 420) and \ |
---|
| 221 | student.current_verdict == 'B': |
---|
| 222 | if student.depcode in ARTS: |
---|
[12188] | 223 | amount = 11975 |
---|
[9143] | 224 | else: |
---|
[12188] | 225 | amount = 11975 |
---|
[9143] | 226 | else: |
---|
| 227 | if student.current_level == 100 and student.state == CLEARED: |
---|
| 228 | if student.depcode in ARTS: |
---|
[11850] | 229 | amount = 22500 |
---|
[9143] | 230 | else: |
---|
[11850] | 231 | amount = 23000 |
---|
[10012] | 232 | # NCE II sw |
---|
[9143] | 233 | elif student.current_level in (100, 110, 120) and \ |
---|
| 234 | student.state == RETURNING: |
---|
| 235 | if student.depcode in ARTS: |
---|
[11850] | 236 | amount = 19000 |
---|
[9143] | 237 | else: |
---|
[11882] | 238 | amount = 19500 |
---|
[10012] | 239 | # NCE III sw |
---|
[9143] | 240 | elif student.current_level in (200, 210, 220): |
---|
| 241 | if student.depcode in ARTS: |
---|
[11850] | 242 | amount = 21000 |
---|
[9143] | 243 | else: |
---|
[11850] | 244 | amount = 21000 |
---|
[10012] | 245 | # NCE IV sw |
---|
[9143] | 246 | elif student.current_level in (300, 310, 320): |
---|
| 247 | if student.depcode in ARTS: |
---|
[11850] | 248 | amount = 19000 |
---|
[9143] | 249 | else: |
---|
[11850] | 250 | amount = 19500 |
---|
[10012] | 251 | # NCE V sw |
---|
[9143] | 252 | elif student.current_level in (400, 410, 420): |
---|
| 253 | if student.depcode in ARTS: |
---|
[11850] | 254 | amount = 19000 |
---|
[9143] | 255 | else: |
---|
[11850] | 256 | amount = 19500 |
---|
[10012] | 257 | # NCE V spillover sw |
---|
[9143] | 258 | elif student.current_level in (500, 510, 520) and \ |
---|
| 259 | student.current_verdict == 'B': |
---|
| 260 | if student.depcode in ARTS: |
---|
[11850] | 261 | amount = 17500 |
---|
[9143] | 262 | else: |
---|
[11850] | 263 | amount = 18000 |
---|
[10012] | 264 | # NCE V second spillover sw |
---|
[9143] | 265 | elif student.current_level in (600, 610, 620) and \ |
---|
| 266 | student.current_verdict == 'B': |
---|
| 267 | if student.depcode in ARTS: |
---|
[11850] | 268 | amount = 17500 |
---|
[9143] | 269 | else: |
---|
[11850] | 270 | amount = 18000 |
---|
[10009] | 271 | # NCE student payment can be disabled by |
---|
| 272 | # setting the base school fee to -1 |
---|
| 273 | if academic_session.school_fee_base == -1 and \ |
---|
| 274 | student.current_mode.startswith('nce'): |
---|
[10010] | 275 | return _(u'School fee payment is disabled.'), None |
---|
[9297] | 276 | if student.state == RETURNING: |
---|
[9525] | 277 | # Override p_session and p_level |
---|
[9297] | 278 | p_session, p_level = self.getReturningData(student) |
---|
[9525] | 279 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 280 | if academic_session == None: |
---|
| 281 | return _(u'Session configuration object is not available.'), None |
---|
[9143] | 282 | |
---|
[8599] | 283 | if amount in (0.0, None): |
---|
| 284 | return _(u'Amount could not be determined.'), None |
---|
[11649] | 285 | if self.samePaymentMade(student, category, p_item, p_session): |
---|
| 286 | return _('This type of payment has already been made.'), None |
---|
[11457] | 287 | if self._isPaymentDisabled(p_session, category, student): |
---|
| 288 | return _('Payment temporarily disabled.'), None |
---|
[8713] | 289 | payment = createObject(u'waeup.StudentOnlinePayment') |
---|
[8953] | 290 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
[8599] | 291 | payment.p_id = "p%s" % timestamp |
---|
| 292 | payment.p_category = category |
---|
| 293 | payment.p_item = p_item |
---|
| 294 | payment.p_session = p_session |
---|
| 295 | payment.p_level = p_level |
---|
[9153] | 296 | payment.p_current = p_current |
---|
[10388] | 297 | # On June 26, 2013 FCEOkene realized that the Interswitch fee |
---|
| 298 | # is deducted from their amount. Therefore, we add this fee here. |
---|
| 299 | payment.amount_auth = float(amount) + GATEWAY_AMT |
---|
[8599] | 300 | return None, payment |
---|
[7621] | 301 | |
---|
[9207] | 302 | def getAccommodationDetails(self, student): |
---|
| 303 | """Determine the accommodation data of a student. |
---|
| 304 | """ |
---|
| 305 | d = {} |
---|
| 306 | d['error'] = u'' |
---|
| 307 | hostels = grok.getSite()['hostels'] |
---|
| 308 | d['booking_session'] = hostels.accommodation_session |
---|
| 309 | d['allowed_states'] = hostels.accommodation_states |
---|
| 310 | d['startdate'] = hostels.startdate |
---|
| 311 | d['enddate'] = hostels.enddate |
---|
| 312 | d['expired'] = hostels.expired |
---|
| 313 | # Determine bed type |
---|
| 314 | studycourse = student['studycourse'] |
---|
| 315 | certificate = getattr(studycourse,'certificate',None) |
---|
| 316 | current_level = studycourse.current_level |
---|
| 317 | if None in (current_level, certificate): |
---|
| 318 | return d |
---|
| 319 | end_level = certificate.end_level |
---|
| 320 | if current_level == 10: |
---|
| 321 | bt = 'pr' |
---|
| 322 | elif current_level == 100: |
---|
| 323 | bt = 'fr' |
---|
| 324 | elif current_level >= 300: |
---|
| 325 | bt = 'fi' |
---|
| 326 | else: |
---|
| 327 | bt = 're' |
---|
| 328 | if student.sex == 'f': |
---|
| 329 | sex = 'female' |
---|
| 330 | else: |
---|
| 331 | sex = 'male' |
---|
| 332 | special_handling = 'regular' |
---|
| 333 | d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt) |
---|
| 334 | return d |
---|
| 335 | |
---|
[9903] | 336 | def maxCredits(self, studylevel): |
---|
| 337 | """Return maximum credits. |
---|
| 338 | |
---|
| 339 | """ |
---|
| 340 | return 58 |
---|
| 341 | |
---|
[9950] | 342 | def getPDFCreator(self, context): |
---|
| 343 | """Get a pdf creator suitable for `context`. |
---|
| 344 | |
---|
| 345 | The default implementation always returns the default creator. |
---|
| 346 | """ |
---|
| 347 | mode = getattr(context, 'current_mode', None) |
---|
| 348 | if mode and mode.startswith('ug'): |
---|
| 349 | return getUtility(IPDFCreator, name='ibadan_pdfcreator') |
---|
| 350 | return getUtility(IPDFCreator) |
---|
| 351 | |
---|
[9982] | 352 | def _admissionText(self, student, portal_language): |
---|
| 353 | mode = getattr(student, 'current_mode', None) |
---|
| 354 | if mode and mode.startswith('ug'): |
---|
| 355 | text = trans(_( |
---|
| 356 | 'With reference to your application for admission into Bachelor Degree ' |
---|
| 357 | 'Programme of the University of Ibadan, this is to inform you that you have ' |
---|
| 358 | 'been provisionally admitted to pursue a full-time Bachelor of Arts in ' |
---|
| 359 | 'Education Degree Programme as follows:'), |
---|
| 360 | portal_language) |
---|
| 361 | else: |
---|
| 362 | inst_name = grok.getSite()['configuration'].name |
---|
| 363 | text = trans(_( |
---|
| 364 | 'This is to inform you that you have been provisionally' |
---|
| 365 | ' admitted into ${a} as follows:', mapping = {'a': inst_name}), |
---|
| 366 | portal_language) |
---|
| 367 | return text |
---|
| 368 | |
---|
[9989] | 369 | def getBedCoordinates(self, bedticket): |
---|
| 370 | """Return bed coordinates. |
---|
| 371 | |
---|
| 372 | Bed coordinates are invisible in FCEOkene. |
---|
| 373 | """ |
---|
| 374 | return _('(see payment slip)') |
---|
| 375 | |
---|
[10019] | 376 | SEPARATORS_DICT = { |
---|
| 377 | 'form.fst_sit_fname': _(u'First Sitting Record'), |
---|
| 378 | 'form.scd_sit_fname': _(u'Second Sitting Record'), |
---|
| 379 | #'form.alr_fname': _(u'Advanced Level Record'), |
---|
| 380 | 'form.hq_type': _(u'Advanced Level Record'), |
---|
| 381 | 'form.hq2_type': _(u'Second Higher Education Record'), |
---|
| 382 | 'form.nysc_year': _(u'NYSC Information'), |
---|
| 383 | 'form.employer': _(u'Employment History'), |
---|
| 384 | 'form.former_matric': _(u'Former Student'), |
---|
| 385 | } |
---|
| 386 | |
---|
[10023] | 387 | SKIP_UPLOAD_VIEWLETS = ( |
---|
| 388 | 'higherqualificationresultupload', |
---|
| 389 | 'secondHigherqualificationresultupload', |
---|
| 390 | 'certificateupload', |
---|
| 391 | 'secondcertificateupload', |
---|
| 392 | 'thirdcertificateupload', |
---|
| 393 | 'resultstatementupload', |
---|
| 394 | 'secondrefereeletterupload', |
---|
| 395 | 'thirdrefereeletterupload',) |
---|
| 396 | |
---|
[8460] | 397 | # FCEOkene prefix |
---|
[10520] | 398 | STUDENT_ID_PREFIX = u'K' |
---|