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