[7419] | 1 | ## $Id: utils.py 10009 2013-03-04 06:53:59Z 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 | |
---|
[10009] | 124 | #PDE |
---|
[9143] | 125 | if student.current_mode == 'pd_ft': |
---|
| 126 | amount = 35000 |
---|
[10009] | 127 | # NCE/UG |
---|
[9143] | 128 | elif not student.current_mode.endswith('_sw'): |
---|
| 129 | # PRENCE |
---|
| 130 | if student.current_level == 10 and student.state == CLEARED: |
---|
| 131 | if student.depcode in ARTS: |
---|
| 132 | amount = 14900 |
---|
| 133 | else: |
---|
| 134 | amount = 15400 |
---|
[9953] | 135 | # NCE/UG I fresh |
---|
[9143] | 136 | elif student.current_level == 100 and student.state == CLEARED: |
---|
| 137 | if student.depcode in ARTS: |
---|
| 138 | amount = 12020 |
---|
| 139 | else: |
---|
| 140 | amount = 12495 |
---|
[9953] | 141 | # NCE/UG II |
---|
[9143] | 142 | elif student.current_level in (100, 110, 120) and \ |
---|
| 143 | student.state == RETURNING: |
---|
| 144 | if student.depcode in ARTS: |
---|
| 145 | amount = 11070 |
---|
| 146 | else: |
---|
| 147 | amount = 11545 |
---|
[9953] | 148 | # NCE/UG III |
---|
[9143] | 149 | elif student.current_level in (200, 210, 220): |
---|
| 150 | if student.depcode in ARTS: |
---|
| 151 | amount = 11070 |
---|
| 152 | else: |
---|
| 153 | amount = 11545 |
---|
[9953] | 154 | # NCE/UG III repeater |
---|
[9143] | 155 | elif student.current_level in (300, 310, 320) and \ |
---|
| 156 | student.current_verdict == 'O': |
---|
| 157 | if student.depcode in ARTS: |
---|
| 158 | amount = 6535 |
---|
| 159 | else: |
---|
| 160 | amount = 6773 |
---|
[9953] | 161 | # NCE/UG III spillover |
---|
[9143] | 162 | elif student.current_level in (300, 310, 320) and \ |
---|
| 163 | student.current_verdict == 'B': |
---|
| 164 | if student.depcode in ARTS: |
---|
| 165 | amount = 9170 |
---|
| 166 | else: |
---|
| 167 | amount = 9645 |
---|
[9953] | 168 | # NCE/UG III second spillover |
---|
[9143] | 169 | elif student.current_level in (400, 410, 420) and \ |
---|
| 170 | student.current_verdict == 'B': |
---|
| 171 | if student.depcode in ARTS: |
---|
| 172 | amount = 9170 |
---|
| 173 | else: |
---|
| 174 | amount = 9645 |
---|
| 175 | else: |
---|
| 176 | if student.current_level == 100 and student.state == CLEARED: |
---|
| 177 | if student.depcode in ARTS: |
---|
| 178 | amount = 21900 |
---|
| 179 | else: |
---|
| 180 | amount = 22400 |
---|
[10009] | 181 | # NCE/UG II sw |
---|
[9143] | 182 | elif student.current_level in (100, 110, 120) and \ |
---|
| 183 | student.state == RETURNING: |
---|
| 184 | if student.depcode in ARTS: |
---|
| 185 | amount = 18400 |
---|
| 186 | else: |
---|
| 187 | amount = 18900 |
---|
[10009] | 188 | # NCE/UG III sw |
---|
[9143] | 189 | elif student.current_level in (200, 210, 220): |
---|
| 190 | if student.depcode in ARTS: |
---|
| 191 | amount = 20400 |
---|
| 192 | else: |
---|
| 193 | amount = 20900 |
---|
[10009] | 194 | # NCE/UG IV sw |
---|
[9143] | 195 | elif student.current_level in (300, 310, 320): |
---|
| 196 | if student.depcode in ARTS: |
---|
| 197 | amount = 18400 |
---|
| 198 | else: |
---|
| 199 | amount = 18900 |
---|
[10009] | 200 | # NCE/UG V sw |
---|
[9143] | 201 | elif student.current_level in (400, 410, 420): |
---|
| 202 | if student.depcode in ARTS: |
---|
| 203 | amount = 18400 |
---|
| 204 | else: |
---|
| 205 | amount = 18900 |
---|
[10009] | 206 | # NCE/UG V spillover sw |
---|
[9143] | 207 | elif student.current_level in (500, 510, 520) and \ |
---|
| 208 | student.current_verdict == 'B': |
---|
| 209 | if student.depcode in ARTS: |
---|
| 210 | amount = 16900 |
---|
| 211 | else: |
---|
| 212 | amount = 17400 |
---|
[10009] | 213 | # NCE/UG V second spillover sw |
---|
[9143] | 214 | elif student.current_level in (600, 610, 620) and \ |
---|
| 215 | student.current_verdict == 'B': |
---|
| 216 | if student.depcode in ARTS: |
---|
| 217 | amount = 16900 |
---|
| 218 | else: |
---|
| 219 | amount = 17400 |
---|
[10009] | 220 | # NCE student payment can be disabled by |
---|
| 221 | # setting the base school fee to -1 |
---|
| 222 | if academic_session.school_fee_base == -1 and \ |
---|
| 223 | student.current_mode.startswith('nce'): |
---|
| 224 | amount = 0 |
---|
[9297] | 225 | if student.state == RETURNING: |
---|
[9525] | 226 | # Override p_session and p_level |
---|
[9297] | 227 | p_session, p_level = self.getReturningData(student) |
---|
[9525] | 228 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 229 | if academic_session == None: |
---|
| 230 | return _(u'Session configuration object is not available.'), None |
---|
[9143] | 231 | |
---|
[8599] | 232 | if amount in (0.0, None): |
---|
| 233 | return _(u'Amount could not be determined.'), None |
---|
| 234 | for key in student['payments'].keys(): |
---|
| 235 | ticket = student['payments'][key] |
---|
| 236 | if ticket.p_state == 'paid' and\ |
---|
| 237 | ticket.p_category == category and \ |
---|
| 238 | ticket.p_item == p_item and \ |
---|
| 239 | ticket.p_session == p_session: |
---|
| 240 | return _('This type of payment has already been made.'), None |
---|
[8713] | 241 | payment = createObject(u'waeup.StudentOnlinePayment') |
---|
[8953] | 242 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
[8599] | 243 | payment.p_id = "p%s" % timestamp |
---|
| 244 | payment.p_category = category |
---|
| 245 | payment.p_item = p_item |
---|
| 246 | payment.p_session = p_session |
---|
| 247 | payment.p_level = p_level |
---|
[9153] | 248 | payment.p_current = p_current |
---|
[9143] | 249 | payment.amount_auth = float(amount) |
---|
[8599] | 250 | return None, payment |
---|
[7621] | 251 | |
---|
[9207] | 252 | def getAccommodationDetails(self, student): |
---|
| 253 | """Determine the accommodation data of a student. |
---|
| 254 | """ |
---|
| 255 | d = {} |
---|
| 256 | d['error'] = u'' |
---|
| 257 | hostels = grok.getSite()['hostels'] |
---|
| 258 | d['booking_session'] = hostels.accommodation_session |
---|
| 259 | d['allowed_states'] = hostels.accommodation_states |
---|
| 260 | d['startdate'] = hostels.startdate |
---|
| 261 | d['enddate'] = hostels.enddate |
---|
| 262 | d['expired'] = hostels.expired |
---|
| 263 | # Determine bed type |
---|
| 264 | studycourse = student['studycourse'] |
---|
| 265 | certificate = getattr(studycourse,'certificate',None) |
---|
| 266 | current_level = studycourse.current_level |
---|
| 267 | if None in (current_level, certificate): |
---|
| 268 | return d |
---|
| 269 | end_level = certificate.end_level |
---|
| 270 | if current_level == 10: |
---|
| 271 | bt = 'pr' |
---|
| 272 | elif current_level == 100: |
---|
| 273 | bt = 'fr' |
---|
| 274 | elif current_level >= 300: |
---|
| 275 | bt = 'fi' |
---|
| 276 | else: |
---|
| 277 | bt = 're' |
---|
| 278 | if student.sex == 'f': |
---|
| 279 | sex = 'female' |
---|
| 280 | else: |
---|
| 281 | sex = 'male' |
---|
| 282 | special_handling = 'regular' |
---|
| 283 | d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt) |
---|
| 284 | return d |
---|
| 285 | |
---|
[9903] | 286 | def maxCredits(self, studylevel): |
---|
| 287 | """Return maximum credits. |
---|
| 288 | |
---|
| 289 | """ |
---|
| 290 | return 58 |
---|
| 291 | |
---|
[9950] | 292 | def getPDFCreator(self, context): |
---|
| 293 | """Get a pdf creator suitable for `context`. |
---|
| 294 | |
---|
| 295 | The default implementation always returns the default creator. |
---|
| 296 | """ |
---|
| 297 | mode = getattr(context, 'current_mode', None) |
---|
| 298 | if mode and mode.startswith('ug'): |
---|
| 299 | return getUtility(IPDFCreator, name='ibadan_pdfcreator') |
---|
| 300 | return getUtility(IPDFCreator) |
---|
| 301 | |
---|
[9982] | 302 | def _admissionText(self, student, portal_language): |
---|
| 303 | mode = getattr(student, 'current_mode', None) |
---|
| 304 | if mode and mode.startswith('ug'): |
---|
| 305 | text = trans(_( |
---|
| 306 | 'With reference to your application for admission into Bachelor Degree ' |
---|
| 307 | 'Programme of the University of Ibadan, this is to inform you that you have ' |
---|
| 308 | 'been provisionally admitted to pursue a full-time Bachelor of Arts in ' |
---|
| 309 | 'Education Degree Programme as follows:'), |
---|
| 310 | portal_language) |
---|
| 311 | else: |
---|
| 312 | inst_name = grok.getSite()['configuration'].name |
---|
| 313 | text = trans(_( |
---|
| 314 | 'This is to inform you that you have been provisionally' |
---|
| 315 | ' admitted into ${a} as follows:', mapping = {'a': inst_name}), |
---|
| 316 | portal_language) |
---|
| 317 | return text |
---|
| 318 | |
---|
[9989] | 319 | def getBedCoordinates(self, bedticket): |
---|
| 320 | """Return bed coordinates. |
---|
| 321 | |
---|
| 322 | Bed coordinates are invisible in FCEOkene. |
---|
| 323 | """ |
---|
| 324 | return _('(see payment slip)') |
---|
| 325 | |
---|
[8460] | 326 | # FCEOkene prefix |
---|
[8528] | 327 | STUDENT_ID_PREFIX = u'K' |
---|