[7419] | 1 | ## $Id: utils.py 9989 2013-02-24 17:41:41Z 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 |
---|
[6902] | 29 | |
---|
[8834] | 30 | class CustomStudentsUtils(NigeriaStudentsUtils): |
---|
[7151] | 31 | """A collection of customized methods. |
---|
| 32 | |
---|
| 33 | """ |
---|
| 34 | |
---|
[9190] | 35 | def selectBed(self, available_beds): |
---|
| 36 | """Randomly select a bed from a list of available beds. |
---|
| 37 | |
---|
| 38 | """ |
---|
| 39 | return random.choice(available_beds) |
---|
| 40 | |
---|
[8270] | 41 | def getReturningData(self, student): |
---|
| 42 | """ This method defines what happens after school fee payment |
---|
[8319] | 43 | of returning students depending on the student's senate verdict. |
---|
[8270] | 44 | """ |
---|
[8319] | 45 | prev_level = student['studycourse'].current_level |
---|
| 46 | cur_verdict = student['studycourse'].current_verdict |
---|
| 47 | if cur_verdict in ('A','B','L','M','N','Z',): |
---|
| 48 | # Successful student |
---|
| 49 | new_level = divmod(int(prev_level),100)[0]*100 + 100 |
---|
[9923] | 50 | elif cur_verdict in ('C','O'): |
---|
[8319] | 51 | # Student on probation |
---|
| 52 | new_level = int(prev_level) + 10 |
---|
| 53 | else: |
---|
| 54 | # Student is somehow in an undefined state. |
---|
| 55 | # Level has to be set manually. |
---|
| 56 | new_level = prev_level |
---|
[9923] | 57 | if cur_verdict == 'O': |
---|
| 58 | new_session = student['studycourse'].current_session |
---|
| 59 | else: |
---|
| 60 | new_session = student['studycourse'].current_session + 1 |
---|
[8270] | 61 | return new_session, new_level |
---|
| 62 | |
---|
[9153] | 63 | def setPaymentDetails(self, category, student, |
---|
| 64 | previous_session=None, previous_level=None): |
---|
[8599] | 65 | """Create Payment object and set the payment data of a student for |
---|
| 66 | the payment category specified. |
---|
| 67 | |
---|
| 68 | """ |
---|
[8306] | 69 | details = {} |
---|
[8599] | 70 | p_item = u'' |
---|
| 71 | amount = 0.0 |
---|
| 72 | error = u'' |
---|
[9153] | 73 | if previous_session: |
---|
| 74 | return _('Previous session payment not yet implemented.'), None |
---|
[8599] | 75 | p_session = student['studycourse'].current_session |
---|
| 76 | p_level = student['studycourse'].current_level |
---|
[9153] | 77 | p_current = True |
---|
[9525] | 78 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 79 | if academic_session == None: |
---|
[8599] | 80 | return _(u'Session configuration object is not available.'), None |
---|
[9525] | 81 | # Determine fee. |
---|
[7151] | 82 | if category == 'transfer': |
---|
[8599] | 83 | amount = academic_session.transfer_fee |
---|
[7151] | 84 | elif category == 'gown': |
---|
[8599] | 85 | amount = academic_session.gown_fee |
---|
[7151] | 86 | elif category == 'bed_allocation': |
---|
[8599] | 87 | amount = academic_session.booking_fee |
---|
[7151] | 88 | elif category == 'hostel_maintenance': |
---|
[9611] | 89 | current_session = student['studycourse'].current_session |
---|
| 90 | bedticket = student['accommodation'].get(str(current_session), None) |
---|
| 91 | if bedticket is not None and bedticket.bed is not None: |
---|
| 92 | p_item = bedticket.bed_coordinates |
---|
| 93 | else: |
---|
| 94 | return _(u'You have not yet booked accommodation.'), None |
---|
| 95 | acc_details = self.getAccommodationDetails(student) |
---|
| 96 | if current_session != acc_details['booking_session']: |
---|
| 97 | return _(u'Current session does not match accommodation session.'), None |
---|
[9612] | 98 | if student.current_mode.endswith('_sw') or student.current_mode == 'pd_ft': |
---|
[9629] | 99 | amount = 2650.0 |
---|
[9612] | 100 | else: |
---|
[9628] | 101 | amount = 4150.0 |
---|
[7151] | 102 | elif category == 'clearance': |
---|
[9143] | 103 | amount = academic_session.clearance_fee |
---|
[8599] | 104 | try: |
---|
| 105 | p_item = student['studycourse'].certificate.code |
---|
| 106 | except (AttributeError, TypeError): |
---|
| 107 | return _('Study course data are incomplete.'), None |
---|
[7151] | 108 | elif category == 'schoolfee': |
---|
[8599] | 109 | try: |
---|
| 110 | certificate = student['studycourse'].certificate |
---|
| 111 | p_item = certificate.code |
---|
| 112 | except (AttributeError, TypeError): |
---|
| 113 | return _('Study course data are incomplete.'), None |
---|
[9143] | 114 | |
---|
| 115 | # Very special school fee configuration, should be moved to |
---|
| 116 | # a seperate file. |
---|
| 117 | |
---|
| 118 | ARTS = ('CRS','ISS','HIS','MUS','ECO','GEO','POL','SOS','CCA','ECU', |
---|
| 119 | 'THA','GED','GSE','PES','SPC','ENG','FRE','ARB','HAU','IGB', |
---|
| 120 | 'YOR','NCRS','NISS','NHIS','NMUS','NECO','NGEO','NPOL', |
---|
| 121 | 'NCCA','NECU','NTHA','NGED','NGSE','NPES','NSPC','NENG', |
---|
| 122 | 'NFRE','NARB','NHAU','NIGB','NYOR','NSOS') |
---|
| 123 | |
---|
| 124 | #PDE Students |
---|
| 125 | if student.current_mode == 'pd_ft': |
---|
| 126 | amount = 35000 |
---|
| 127 | elif not student.current_mode.endswith('_sw'): |
---|
| 128 | # PRENCE |
---|
| 129 | if student.current_level == 10 and student.state == CLEARED: |
---|
| 130 | if student.depcode in ARTS: |
---|
| 131 | amount = 14900 |
---|
| 132 | else: |
---|
| 133 | amount = 15400 |
---|
[9953] | 134 | # NCE/UG I fresh |
---|
[9143] | 135 | elif student.current_level == 100 and student.state == CLEARED: |
---|
| 136 | if student.depcode in ARTS: |
---|
| 137 | amount = 12020 |
---|
| 138 | else: |
---|
| 139 | amount = 12495 |
---|
[9953] | 140 | # NCE/UG II |
---|
[9143] | 141 | elif student.current_level in (100, 110, 120) and \ |
---|
| 142 | student.state == RETURNING: |
---|
| 143 | if student.depcode in ARTS: |
---|
| 144 | amount = 11070 |
---|
| 145 | else: |
---|
| 146 | amount = 11545 |
---|
[9953] | 147 | # NCE/UG III |
---|
[9143] | 148 | elif student.current_level in (200, 210, 220): |
---|
| 149 | if student.depcode in ARTS: |
---|
| 150 | amount = 11070 |
---|
| 151 | else: |
---|
| 152 | amount = 11545 |
---|
[9953] | 153 | # NCE/UG III repeater |
---|
[9143] | 154 | elif student.current_level in (300, 310, 320) and \ |
---|
| 155 | student.current_verdict == 'O': |
---|
| 156 | if student.depcode in ARTS: |
---|
| 157 | amount = 6535 |
---|
| 158 | else: |
---|
| 159 | amount = 6773 |
---|
[9953] | 160 | # NCE/UG III spillover |
---|
[9143] | 161 | elif student.current_level in (300, 310, 320) and \ |
---|
| 162 | student.current_verdict == 'B': |
---|
| 163 | if student.depcode in ARTS: |
---|
| 164 | amount = 9170 |
---|
| 165 | else: |
---|
| 166 | amount = 9645 |
---|
[9953] | 167 | # NCE/UG III second spillover |
---|
[9143] | 168 | elif student.current_level in (400, 410, 420) and \ |
---|
| 169 | student.current_verdict == 'B': |
---|
| 170 | if student.depcode in ARTS: |
---|
| 171 | amount = 9170 |
---|
| 172 | else: |
---|
| 173 | amount = 9645 |
---|
| 174 | else: |
---|
| 175 | if student.current_level == 100 and student.state == CLEARED: |
---|
| 176 | if student.depcode in ARTS: |
---|
| 177 | amount = 21900 |
---|
| 178 | else: |
---|
| 179 | amount = 22400 |
---|
[9953] | 180 | # NCE/UG II |
---|
[9143] | 181 | elif student.current_level in (100, 110, 120) and \ |
---|
| 182 | student.state == RETURNING: |
---|
| 183 | if student.depcode in ARTS: |
---|
| 184 | amount = 18400 |
---|
| 185 | else: |
---|
| 186 | amount = 18900 |
---|
[9953] | 187 | # NCE/UG III |
---|
[9143] | 188 | elif student.current_level in (200, 210, 220): |
---|
| 189 | if student.depcode in ARTS: |
---|
| 190 | amount = 20400 |
---|
| 191 | else: |
---|
| 192 | amount = 20900 |
---|
[9953] | 193 | # NCE/UG IV |
---|
[9143] | 194 | elif student.current_level in (300, 310, 320): |
---|
| 195 | if student.depcode in ARTS: |
---|
| 196 | amount = 18400 |
---|
| 197 | else: |
---|
| 198 | amount = 18900 |
---|
[9953] | 199 | # NCE/UG V |
---|
[9143] | 200 | elif student.current_level in (400, 410, 420): |
---|
| 201 | if student.depcode in ARTS: |
---|
| 202 | amount = 18400 |
---|
| 203 | else: |
---|
| 204 | amount = 18900 |
---|
[9953] | 205 | # NCE/UG V spillover |
---|
[9143] | 206 | elif student.current_level in (500, 510, 520) and \ |
---|
| 207 | student.current_verdict == 'B': |
---|
| 208 | if student.depcode in ARTS: |
---|
| 209 | amount = 16900 |
---|
| 210 | else: |
---|
| 211 | amount = 17400 |
---|
[9953] | 212 | # NCE/UG V second spillover |
---|
[9143] | 213 | elif student.current_level in (600, 610, 620) and \ |
---|
| 214 | student.current_verdict == 'B': |
---|
| 215 | if student.depcode in ARTS: |
---|
| 216 | amount = 16900 |
---|
| 217 | else: |
---|
| 218 | amount = 17400 |
---|
[9297] | 219 | if student.state == RETURNING: |
---|
[9525] | 220 | # Override p_session and p_level |
---|
[9297] | 221 | p_session, p_level = self.getReturningData(student) |
---|
[9525] | 222 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 223 | if academic_session == None: |
---|
| 224 | return _(u'Session configuration object is not available.'), None |
---|
[9143] | 225 | |
---|
[8599] | 226 | if amount in (0.0, None): |
---|
| 227 | return _(u'Amount could not be determined.'), None |
---|
| 228 | for key in student['payments'].keys(): |
---|
| 229 | ticket = student['payments'][key] |
---|
| 230 | if ticket.p_state == 'paid' and\ |
---|
| 231 | ticket.p_category == category and \ |
---|
| 232 | ticket.p_item == p_item and \ |
---|
| 233 | ticket.p_session == p_session: |
---|
| 234 | return _('This type of payment has already been made.'), None |
---|
[8713] | 235 | payment = createObject(u'waeup.StudentOnlinePayment') |
---|
[8953] | 236 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
[8599] | 237 | payment.p_id = "p%s" % timestamp |
---|
| 238 | payment.p_category = category |
---|
| 239 | payment.p_item = p_item |
---|
| 240 | payment.p_session = p_session |
---|
| 241 | payment.p_level = p_level |
---|
[9153] | 242 | payment.p_current = p_current |
---|
[9143] | 243 | payment.amount_auth = float(amount) |
---|
[8599] | 244 | return None, payment |
---|
[7621] | 245 | |
---|
[9207] | 246 | def getAccommodationDetails(self, student): |
---|
| 247 | """Determine the accommodation data of a student. |
---|
| 248 | """ |
---|
| 249 | d = {} |
---|
| 250 | d['error'] = u'' |
---|
| 251 | hostels = grok.getSite()['hostels'] |
---|
| 252 | d['booking_session'] = hostels.accommodation_session |
---|
| 253 | d['allowed_states'] = hostels.accommodation_states |
---|
| 254 | d['startdate'] = hostels.startdate |
---|
| 255 | d['enddate'] = hostels.enddate |
---|
| 256 | d['expired'] = hostels.expired |
---|
| 257 | # Determine bed type |
---|
| 258 | studycourse = student['studycourse'] |
---|
| 259 | certificate = getattr(studycourse,'certificate',None) |
---|
| 260 | current_level = studycourse.current_level |
---|
| 261 | if None in (current_level, certificate): |
---|
| 262 | return d |
---|
| 263 | end_level = certificate.end_level |
---|
| 264 | if current_level == 10: |
---|
| 265 | bt = 'pr' |
---|
| 266 | elif current_level == 100: |
---|
| 267 | bt = 'fr' |
---|
| 268 | elif current_level >= 300: |
---|
| 269 | bt = 'fi' |
---|
| 270 | else: |
---|
| 271 | bt = 're' |
---|
| 272 | if student.sex == 'f': |
---|
| 273 | sex = 'female' |
---|
| 274 | else: |
---|
| 275 | sex = 'male' |
---|
| 276 | special_handling = 'regular' |
---|
| 277 | d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt) |
---|
| 278 | return d |
---|
| 279 | |
---|
[9903] | 280 | def maxCredits(self, studylevel): |
---|
| 281 | """Return maximum credits. |
---|
| 282 | |
---|
| 283 | """ |
---|
| 284 | return 58 |
---|
| 285 | |
---|
[9950] | 286 | def getPDFCreator(self, context): |
---|
| 287 | """Get a pdf creator suitable for `context`. |
---|
| 288 | |
---|
| 289 | The default implementation always returns the default creator. |
---|
| 290 | """ |
---|
| 291 | mode = getattr(context, 'current_mode', None) |
---|
| 292 | if mode and mode.startswith('ug'): |
---|
| 293 | return getUtility(IPDFCreator, name='ibadan_pdfcreator') |
---|
| 294 | return getUtility(IPDFCreator) |
---|
| 295 | |
---|
[9982] | 296 | def _admissionText(self, student, portal_language): |
---|
| 297 | mode = getattr(student, 'current_mode', None) |
---|
| 298 | if mode and mode.startswith('ug'): |
---|
| 299 | text = trans(_( |
---|
| 300 | 'With reference to your application for admission into Bachelor Degree ' |
---|
| 301 | 'Programme of the University of Ibadan, this is to inform you that you have ' |
---|
| 302 | 'been provisionally admitted to pursue a full-time Bachelor of Arts in ' |
---|
| 303 | 'Education Degree Programme as follows:'), |
---|
| 304 | portal_language) |
---|
| 305 | else: |
---|
| 306 | inst_name = grok.getSite()['configuration'].name |
---|
| 307 | text = trans(_( |
---|
| 308 | 'This is to inform you that you have been provisionally' |
---|
| 309 | ' admitted into ${a} as follows:', mapping = {'a': inst_name}), |
---|
| 310 | portal_language) |
---|
| 311 | return text |
---|
| 312 | |
---|
[9989] | 313 | def getBedCoordinates(self, bedticket): |
---|
| 314 | """Return bed coordinates. |
---|
| 315 | |
---|
| 316 | Bed coordinates are invisible in FCEOkene. |
---|
| 317 | """ |
---|
| 318 | return _('(see payment slip)') |
---|
| 319 | |
---|
[8460] | 320 | # FCEOkene prefix |
---|
[8528] | 321 | STUDENT_ID_PREFIX = u'K' |
---|