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