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