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