[7419] | 1 | ## $Id: utils.py 12629 2015-02-24 05:56:37Z 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)', |
---|
[12629] | 64 | 'Z': 'Successful student (provisional)', |
---|
[10661] | 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: |
---|
[12628] | 142 | amount = 4000.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': |
---|
[12602] | 155 | p_item = student.certcode |
---|
| 156 | if not p_item: |
---|
[8599] | 157 | return _('Study course data are incomplete.'), None |
---|
[9143] | 158 | |
---|
[10012] | 159 | if student.state not in (CLEARED, RETURNING): |
---|
| 160 | return _('Wrong state.'), None |
---|
| 161 | |
---|
[10661] | 162 | # PDE repeater |
---|
| 163 | if student.current_verdict == 'OPDE': |
---|
[11850] | 164 | amount = 23000 |
---|
[10660] | 165 | # PDE |
---|
| 166 | elif student.current_mode == 'pd_ft': |
---|
[11850] | 167 | amount = 35300 |
---|
[12602] | 168 | |
---|
| 169 | #Short Duration ICT Programs |
---|
| 170 | elif p_item in ('CCO','DPMTS','DTPGD') and \ |
---|
| 171 | student.state == CLEARED: |
---|
| 172 | amount = 15000 |
---|
| 173 | elif p_item in ('ADTPGD','ADPMTS') and \ |
---|
| 174 | student.state == CLEARED: |
---|
| 175 | amount = 16000 |
---|
| 176 | elif p_item in ('ADPMTSI','ADTPGDI','DPMTSI','DTPGDI') and \ |
---|
| 177 | student.state == CLEARED: |
---|
| 178 | amount = 25000 |
---|
| 179 | elif p_item in ('ADPMTSA','ADTPGDA') and \ |
---|
| 180 | student.state == CLEARED: |
---|
| 181 | amount = 35000 |
---|
| 182 | |
---|
[10012] | 183 | # UG |
---|
| 184 | elif student.current_mode == 'ug_ft': |
---|
[10876] | 185 | # Introducing returning students fee for 'ug_ft' for 1st time |
---|
| 186 | # on 07/01/2014 |
---|
| 187 | if student.state == CLEARED: |
---|
| 188 | amount = 65650 |
---|
| 189 | else: |
---|
| 190 | amount = 56150 |
---|
[10012] | 191 | # NCE |
---|
[9143] | 192 | elif not student.current_mode.endswith('_sw'): |
---|
| 193 | # PRENCE |
---|
| 194 | if student.current_level == 10 and student.state == CLEARED: |
---|
| 195 | if student.depcode in ARTS: |
---|
[12188] | 196 | amount = 17500 |
---|
[9143] | 197 | else: |
---|
[12188] | 198 | amount = 18000 |
---|
[10012] | 199 | # NCE I fresh |
---|
[9143] | 200 | elif student.current_level == 100 and student.state == CLEARED: |
---|
| 201 | if student.depcode in ARTS: |
---|
[12188] | 202 | amount = 14325 |
---|
[9143] | 203 | else: |
---|
[12188] | 204 | amount = 14825 |
---|
[10012] | 205 | # NCE II |
---|
[9143] | 206 | elif student.current_level in (100, 110, 120) and \ |
---|
| 207 | student.state == RETURNING: |
---|
| 208 | if student.depcode in ARTS: |
---|
[12188] | 209 | amount = 13375 |
---|
[9143] | 210 | else: |
---|
[12188] | 211 | amount = 13875 |
---|
[10012] | 212 | # NCE III |
---|
[9143] | 213 | elif student.current_level in (200, 210, 220): |
---|
| 214 | if student.depcode in ARTS: |
---|
[12188] | 215 | amount = 13375 |
---|
[9143] | 216 | else: |
---|
[12188] | 217 | amount = 13875 |
---|
[10012] | 218 | # NCE III repeater |
---|
[9143] | 219 | elif student.current_level in (300, 310, 320) and \ |
---|
| 220 | student.current_verdict == 'O': |
---|
| 221 | if student.depcode in ARTS: |
---|
[12188] | 222 | amount = 11475 |
---|
[9143] | 223 | else: |
---|
[12188] | 224 | amount = 11975 |
---|
[10012] | 225 | # NCE III spillover |
---|
[9143] | 226 | elif student.current_level in (300, 310, 320) and \ |
---|
| 227 | student.current_verdict == 'B': |
---|
| 228 | if student.depcode in ARTS: |
---|
[12188] | 229 | amount = 11975 |
---|
[9143] | 230 | else: |
---|
[12188] | 231 | amount = 11975 |
---|
[10012] | 232 | # NCE III second spillover |
---|
[9143] | 233 | elif student.current_level in (400, 410, 420) and \ |
---|
| 234 | student.current_verdict == 'B': |
---|
| 235 | if student.depcode in ARTS: |
---|
[12188] | 236 | amount = 11975 |
---|
[9143] | 237 | else: |
---|
[12188] | 238 | amount = 11975 |
---|
[9143] | 239 | else: |
---|
| 240 | if student.current_level == 100 and student.state == CLEARED: |
---|
| 241 | if student.depcode in ARTS: |
---|
[11850] | 242 | amount = 22500 |
---|
[9143] | 243 | else: |
---|
[11850] | 244 | amount = 23000 |
---|
[10012] | 245 | # NCE II sw |
---|
[9143] | 246 | elif student.current_level in (100, 110, 120) and \ |
---|
| 247 | student.state == RETURNING: |
---|
| 248 | if student.depcode in ARTS: |
---|
[11850] | 249 | amount = 19000 |
---|
[9143] | 250 | else: |
---|
[11882] | 251 | amount = 19500 |
---|
[10012] | 252 | # NCE III sw |
---|
[9143] | 253 | elif student.current_level in (200, 210, 220): |
---|
| 254 | if student.depcode in ARTS: |
---|
[11850] | 255 | amount = 21000 |
---|
[9143] | 256 | else: |
---|
[11850] | 257 | amount = 21000 |
---|
[10012] | 258 | # NCE IV sw |
---|
[9143] | 259 | elif student.current_level in (300, 310, 320): |
---|
| 260 | if student.depcode in ARTS: |
---|
[11850] | 261 | amount = 19000 |
---|
[9143] | 262 | else: |
---|
[11850] | 263 | amount = 19500 |
---|
[10012] | 264 | # NCE V sw |
---|
[9143] | 265 | elif student.current_level in (400, 410, 420): |
---|
| 266 | if student.depcode in ARTS: |
---|
[11850] | 267 | amount = 19000 |
---|
[9143] | 268 | else: |
---|
[11850] | 269 | amount = 19500 |
---|
[10012] | 270 | # NCE V spillover sw |
---|
[9143] | 271 | elif student.current_level in (500, 510, 520) and \ |
---|
| 272 | student.current_verdict == 'B': |
---|
| 273 | if student.depcode in ARTS: |
---|
[11850] | 274 | amount = 17500 |
---|
[9143] | 275 | else: |
---|
[11850] | 276 | amount = 18000 |
---|
[10012] | 277 | # NCE V second spillover sw |
---|
[9143] | 278 | elif student.current_level in (600, 610, 620) and \ |
---|
| 279 | student.current_verdict == 'B': |
---|
| 280 | if student.depcode in ARTS: |
---|
[11850] | 281 | amount = 17500 |
---|
[9143] | 282 | else: |
---|
[11850] | 283 | amount = 18000 |
---|
[10009] | 284 | # NCE student payment can be disabled by |
---|
| 285 | # setting the base school fee to -1 |
---|
| 286 | if academic_session.school_fee_base == -1 and \ |
---|
| 287 | student.current_mode.startswith('nce'): |
---|
[10010] | 288 | return _(u'School fee payment is disabled.'), None |
---|
[9297] | 289 | if student.state == RETURNING: |
---|
[9525] | 290 | # Override p_session and p_level |
---|
[9297] | 291 | p_session, p_level = self.getReturningData(student) |
---|
[9525] | 292 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 293 | if academic_session == None: |
---|
| 294 | return _(u'Session configuration object is not available.'), None |
---|
[9143] | 295 | |
---|
[8599] | 296 | if amount in (0.0, None): |
---|
| 297 | return _(u'Amount could not be determined.'), None |
---|
[11649] | 298 | if self.samePaymentMade(student, category, p_item, p_session): |
---|
| 299 | return _('This type of payment has already been made.'), None |
---|
[11457] | 300 | if self._isPaymentDisabled(p_session, category, student): |
---|
| 301 | return _('Payment temporarily disabled.'), None |
---|
[8713] | 302 | payment = createObject(u'waeup.StudentOnlinePayment') |
---|
[8953] | 303 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
[8599] | 304 | payment.p_id = "p%s" % timestamp |
---|
| 305 | payment.p_category = category |
---|
| 306 | payment.p_item = p_item |
---|
| 307 | payment.p_session = p_session |
---|
| 308 | payment.p_level = p_level |
---|
[9153] | 309 | payment.p_current = p_current |
---|
[10388] | 310 | # On June 26, 2013 FCEOkene realized that the Interswitch fee |
---|
| 311 | # is deducted from their amount. Therefore, we add this fee here. |
---|
| 312 | payment.amount_auth = float(amount) + GATEWAY_AMT |
---|
[8599] | 313 | return None, payment |
---|
[7621] | 314 | |
---|
[9207] | 315 | def getAccommodationDetails(self, student): |
---|
| 316 | """Determine the accommodation data of a student. |
---|
| 317 | """ |
---|
| 318 | d = {} |
---|
| 319 | d['error'] = u'' |
---|
| 320 | hostels = grok.getSite()['hostels'] |
---|
| 321 | d['booking_session'] = hostels.accommodation_session |
---|
| 322 | d['allowed_states'] = hostels.accommodation_states |
---|
| 323 | d['startdate'] = hostels.startdate |
---|
| 324 | d['enddate'] = hostels.enddate |
---|
| 325 | d['expired'] = hostels.expired |
---|
| 326 | # Determine bed type |
---|
| 327 | studycourse = student['studycourse'] |
---|
| 328 | certificate = getattr(studycourse,'certificate',None) |
---|
| 329 | current_level = studycourse.current_level |
---|
| 330 | if None in (current_level, certificate): |
---|
| 331 | return d |
---|
| 332 | end_level = certificate.end_level |
---|
| 333 | if current_level == 10: |
---|
| 334 | bt = 'pr' |
---|
| 335 | elif current_level == 100: |
---|
| 336 | bt = 'fr' |
---|
| 337 | elif current_level >= 300: |
---|
| 338 | bt = 'fi' |
---|
| 339 | else: |
---|
| 340 | bt = 're' |
---|
| 341 | if student.sex == 'f': |
---|
| 342 | sex = 'female' |
---|
| 343 | else: |
---|
| 344 | sex = 'male' |
---|
| 345 | special_handling = 'regular' |
---|
| 346 | d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt) |
---|
| 347 | return d |
---|
| 348 | |
---|
[9903] | 349 | def maxCredits(self, studylevel): |
---|
| 350 | """Return maximum credits. |
---|
| 351 | |
---|
| 352 | """ |
---|
| 353 | return 58 |
---|
| 354 | |
---|
[9950] | 355 | def getPDFCreator(self, context): |
---|
| 356 | """Get a pdf creator suitable for `context`. |
---|
| 357 | |
---|
| 358 | The default implementation always returns the default creator. |
---|
| 359 | """ |
---|
| 360 | mode = getattr(context, 'current_mode', None) |
---|
| 361 | if mode and mode.startswith('ug'): |
---|
| 362 | return getUtility(IPDFCreator, name='ibadan_pdfcreator') |
---|
| 363 | return getUtility(IPDFCreator) |
---|
| 364 | |
---|
[9982] | 365 | def _admissionText(self, student, portal_language): |
---|
| 366 | mode = getattr(student, 'current_mode', None) |
---|
| 367 | if mode and mode.startswith('ug'): |
---|
| 368 | text = trans(_( |
---|
| 369 | 'With reference to your application for admission into Bachelor Degree ' |
---|
| 370 | 'Programme of the University of Ibadan, this is to inform you that you have ' |
---|
| 371 | 'been provisionally admitted to pursue a full-time Bachelor of Arts in ' |
---|
| 372 | 'Education Degree Programme as follows:'), |
---|
| 373 | portal_language) |
---|
| 374 | else: |
---|
| 375 | inst_name = grok.getSite()['configuration'].name |
---|
| 376 | text = trans(_( |
---|
| 377 | 'This is to inform you that you have been provisionally' |
---|
| 378 | ' admitted into ${a} as follows:', mapping = {'a': inst_name}), |
---|
| 379 | portal_language) |
---|
| 380 | return text |
---|
| 381 | |
---|
[9989] | 382 | def getBedCoordinates(self, bedticket): |
---|
| 383 | """Return bed coordinates. |
---|
| 384 | |
---|
| 385 | Bed coordinates are invisible in FCEOkene. |
---|
| 386 | """ |
---|
| 387 | return _('(see payment slip)') |
---|
| 388 | |
---|
[10019] | 389 | SEPARATORS_DICT = { |
---|
| 390 | 'form.fst_sit_fname': _(u'First Sitting Record'), |
---|
| 391 | 'form.scd_sit_fname': _(u'Second Sitting Record'), |
---|
| 392 | #'form.alr_fname': _(u'Advanced Level Record'), |
---|
| 393 | 'form.hq_type': _(u'Advanced Level Record'), |
---|
| 394 | 'form.hq2_type': _(u'Second Higher Education Record'), |
---|
| 395 | 'form.nysc_year': _(u'NYSC Information'), |
---|
| 396 | 'form.employer': _(u'Employment History'), |
---|
| 397 | 'form.former_matric': _(u'Former Student'), |
---|
| 398 | } |
---|
| 399 | |
---|
[10023] | 400 | SKIP_UPLOAD_VIEWLETS = ( |
---|
| 401 | 'higherqualificationresultupload', |
---|
| 402 | 'secondHigherqualificationresultupload', |
---|
| 403 | 'certificateupload', |
---|
| 404 | 'secondcertificateupload', |
---|
| 405 | 'thirdcertificateupload', |
---|
| 406 | 'resultstatementupload', |
---|
| 407 | 'secondrefereeletterupload', |
---|
| 408 | 'thirdrefereeletterupload',) |
---|
| 409 | |
---|
[8460] | 410 | # FCEOkene prefix |
---|
[10520] | 411 | STUDENT_ID_PREFIX = u'K' |
---|