[7419] | 1 | ## $Id: utils.py 17498 2023-07-20 13:39:23Z 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 | ## |
---|
[11773] | 18 | import grok |
---|
[17457] | 19 | import os |
---|
| 20 | import csv |
---|
[8598] | 21 | from time import time |
---|
[16108] | 22 | from reportlab.platypus import Paragraph, Table |
---|
[9459] | 23 | from zope.component import createObject, getUtility |
---|
[16106] | 24 | from reportlab.lib.styles import getSampleStyleSheet |
---|
[16108] | 25 | from waeup.kofa.browser.pdf import ENTRY1_STYLE |
---|
[16359] | 26 | from waeup.kofa.interfaces import (IKofaUtils, ADMITTED, CLEARANCE, |
---|
[16445] | 27 | CLEARED, REQUESTED, RETURNING, PAID, REGISTERED, VALIDATED, GRADUATED) |
---|
[13251] | 28 | from waeup.kofa.utils.helpers import to_timezone |
---|
[16108] | 29 | from waeup.kofa.students.utils import ( |
---|
| 30 | trans, render_student_data, formatted_text, render_transcript_data, |
---|
| 31 | SLIP_STYLE) |
---|
[8821] | 32 | from kofacustom.nigeria.students.utils import NigeriaStudentsUtils |
---|
[8020] | 33 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
[6902] | 34 | |
---|
[17457] | 35 | SCHOOLFEES = dict() |
---|
| 36 | |
---|
| 37 | schoolfees_path = os.path.join( |
---|
| 38 | os.path.dirname(__file__), 'schoolfees_22.csv') |
---|
| 39 | reader = csv.DictReader(open(schoolfees_path, 'rb')) |
---|
| 40 | SCHOOLFEES[22] = {line['code']: {item[0]:item[1] for item in line.items()} |
---|
| 41 | for line in reader} |
---|
| 42 | |
---|
| 43 | |
---|
| 44 | schoolfees_path = os.path.join( |
---|
| 45 | os.path.dirname(__file__), 'schoolfees_20.csv') |
---|
| 46 | reader = csv.DictReader(open(schoolfees_path, 'rb')) |
---|
| 47 | SCHOOLFEES[20] = {line['code']: {item[0]:item[1] for item in line.items()} |
---|
| 48 | for line in reader} |
---|
| 49 | |
---|
| 50 | |
---|
| 51 | schoolfees_path = os.path.join( |
---|
| 52 | os.path.dirname(__file__), 'schoolfees_17.csv') |
---|
| 53 | reader = csv.DictReader(open(schoolfees_path, 'rb')) |
---|
| 54 | SCHOOLFEES[17] = {line['code']: {item[0]:item[1] for item in line.items()} |
---|
| 55 | for line in reader} |
---|
| 56 | |
---|
| 57 | schoolfees_path = os.path.join( |
---|
| 58 | os.path.dirname(__file__), 'schoolfees_12.csv') |
---|
| 59 | reader = csv.DictReader(open(schoolfees_path, 'rb')) |
---|
| 60 | SCHOOLFEES[12] = {line['code']: {item[0]:item[1] for item in line.items()} |
---|
| 61 | for line in reader} |
---|
| 62 | |
---|
[8821] | 63 | class CustomStudentsUtils(NigeriaStudentsUtils): |
---|
[7151] | 64 | """A collection of customized methods. |
---|
| 65 | |
---|
| 66 | """ |
---|
| 67 | |
---|
[16382] | 68 | SEPARATORS_DICT = { |
---|
| 69 | 'form.fst_sit_fname': _(u'First Sitting Record'), |
---|
| 70 | 'form.scd_sit_fname': _(u'Second Sitting Record'), |
---|
| 71 | 'form.alr_fname': _(u'Advanced Level Record'), |
---|
| 72 | 'form.hq_type': _(u'Higher Education Record'), |
---|
| 73 | 'form.hq2_type': _(u'Second Higher Education Record'), |
---|
| 74 | 'form.nysc_year': _(u'NYSC Information'), |
---|
| 75 | 'form.employer': _(u'Employment History'), |
---|
| 76 | 'form.former_matric': _(u'Former Student'), |
---|
| 77 | 'form.fever': _(u'History of Symptoms'), |
---|
| 78 | 'form.asthma': _(u'Medical History'), |
---|
| 79 | 'form.lagos_abuja': _(u'Travel History'), |
---|
| 80 | 'form.company_suspected': _(u'History of Contact/Infection'), |
---|
[17255] | 81 | 'form.genotype': _(u'TISHIP Registration Form Data'), |
---|
[16382] | 82 | } |
---|
| 83 | |
---|
[8270] | 84 | def getReturningData(self, student): |
---|
| 85 | """ This method defines what happens after school fee payment |
---|
[8319] | 86 | of returning students depending on the student's senate verdict. |
---|
[8270] | 87 | """ |
---|
[8319] | 88 | prev_level = student['studycourse'].current_level |
---|
| 89 | cur_verdict = student['studycourse'].current_verdict |
---|
[16714] | 90 | if cur_verdict == 'N' and prev_level in (100, 200): |
---|
[15482] | 91 | new_level = prev_level |
---|
| 92 | elif cur_verdict in ('A','B','L','M','N','Z',): |
---|
[8319] | 93 | # Successful student |
---|
| 94 | new_level = divmod(int(prev_level),100)[0]*100 + 100 |
---|
| 95 | elif cur_verdict == 'C': |
---|
| 96 | # Student on probation |
---|
| 97 | new_level = int(prev_level) + 10 |
---|
| 98 | else: |
---|
| 99 | # Student is somehow in an undefined state. |
---|
| 100 | # Level has to be set manually. |
---|
| 101 | new_level = prev_level |
---|
[8270] | 102 | new_session = student['studycourse'].current_session + 1 |
---|
| 103 | return new_session, new_level |
---|
| 104 | |
---|
[13251] | 105 | |
---|
[13248] | 106 | def checkAccommodationRequirements(self, student, acc_details): |
---|
| 107 | if acc_details.get('expired', False): |
---|
| 108 | startdate = acc_details.get('startdate') |
---|
| 109 | enddate = acc_details.get('enddate') |
---|
| 110 | if startdate and enddate: |
---|
| 111 | tz = getUtility(IKofaUtils).tzinfo |
---|
| 112 | startdate = to_timezone( |
---|
| 113 | startdate, tz).strftime("%d/%m/%Y %H:%M:%S") |
---|
| 114 | enddate = to_timezone( |
---|
| 115 | enddate, tz).strftime("%d/%m/%Y %H:%M:%S") |
---|
| 116 | return _("Outside booking period: ${a} - ${b}", |
---|
| 117 | mapping = {'a': startdate, 'b': enddate}) |
---|
| 118 | else: |
---|
| 119 | return _("Outside booking period.") |
---|
[13777] | 120 | if not student.is_postgrad and student.current_mode != 'ug_ft': |
---|
[13446] | 121 | return _("Only undergraduate full-time students are eligible to book accommodation.") |
---|
[13283] | 122 | bt = acc_details.get('bt') |
---|
| 123 | if not bt: |
---|
[13248] | 124 | return _("Your data are incomplete.") |
---|
| 125 | if not student.state in acc_details['allowed_states']: |
---|
| 126 | return _("You are in the wrong registration state.") |
---|
[17255] | 127 | #if student['studycourse'].current_session != acc_details[ |
---|
| 128 | # 'booking_session']: |
---|
| 129 | # return _('Your current session does not ' |
---|
| 130 | # 'match accommodation session.') |
---|
| 131 | if acc_details['booking_session'] - student[ |
---|
| 132 | 'studycourse'].current_session > self.ACCOMMODATION_SPAN: |
---|
| 133 | return _('Your current session does not allow ' + \ |
---|
| 134 | 'to book accommodation.') |
---|
[13283] | 135 | stage = bt.split('_')[2] |
---|
[13777] | 136 | if not student.is_postgrad and stage != 'fr' and not student[ |
---|
[14328] | 137 | 'studycourse'].previous_verdict in ( |
---|
[15392] | 138 | 'A', 'B', 'F', 'J', 'L', 'M', 'C', 'Z'): |
---|
[13283] | 139 | return _("Your are not eligible to book accommodation.") |
---|
[15307] | 140 | bsession = str(acc_details['booking_session']) |
---|
| 141 | if bsession in student['accommodation'].keys() \ |
---|
| 142 | and not 'booking expired' in \ |
---|
| 143 | student['accommodation'][bsession].bed_coordinates: |
---|
[13248] | 144 | return _('You already booked a bed space in ' |
---|
| 145 | 'current accommodation session.') |
---|
| 146 | return |
---|
[13244] | 147 | |
---|
[13295] | 148 | def getAccommodationDetails(self, student): |
---|
| 149 | """Determine the accommodation data of a student. |
---|
| 150 | """ |
---|
| 151 | d = {} |
---|
| 152 | d['error'] = u'' |
---|
| 153 | hostels = grok.getSite()['hostels'] |
---|
| 154 | d['booking_session'] = hostels.accommodation_session |
---|
| 155 | d['allowed_states'] = hostels.accommodation_states |
---|
| 156 | d['startdate'] = hostels.startdate |
---|
| 157 | d['enddate'] = hostels.enddate |
---|
| 158 | d['expired'] = hostels.expired |
---|
| 159 | # Determine bed type |
---|
| 160 | studycourse = student['studycourse'] |
---|
| 161 | certificate = getattr(studycourse,'certificate',None) |
---|
| 162 | entry_session = studycourse.entry_session |
---|
| 163 | current_level = studycourse.current_level |
---|
| 164 | if None in (entry_session, current_level, certificate): |
---|
| 165 | return d |
---|
| 166 | if student.sex == 'f': |
---|
| 167 | sex = 'female' |
---|
| 168 | else: |
---|
| 169 | sex = 'male' |
---|
[13777] | 170 | if student.is_postgrad: |
---|
| 171 | bt = 'all' |
---|
| 172 | special_handling = 'pg' |
---|
| 173 | else: |
---|
| 174 | end_level = certificate.end_level |
---|
| 175 | if current_level == 10: |
---|
| 176 | bt = 'pr' |
---|
| 177 | elif entry_session == grok.getSite()['hostels'].accommodation_session: |
---|
| 178 | bt = 'fr' |
---|
| 179 | elif current_level >= end_level: |
---|
| 180 | bt = 'fi' |
---|
| 181 | else: |
---|
| 182 | bt = 're' |
---|
| 183 | special_handling = 'regular' |
---|
[15354] | 184 | desired_hostel = student['accommodation'].desired_hostel |
---|
| 185 | if student.faccode in ('MED', 'DEN') and ( |
---|
| 186 | not desired_hostel or desired_hostel.startswith('clinical')): |
---|
[13777] | 187 | special_handling = 'clinical' |
---|
| 188 | elif student.certcode in ('BARTMAS', 'BARTTHR', 'BARTFAA', |
---|
[17324] | 189 | 'BAEDFAA', 'BSCEDECHED', 'BAFAA', |
---|
| 190 | 'BARTMUS', 'BSCEDECHED'): |
---|
[13777] | 191 | special_handling = 'ekenwan' |
---|
[13295] | 192 | d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt) |
---|
| 193 | return d |
---|
| 194 | |
---|
[9520] | 195 | def _paymentMade(self, student, session): |
---|
| 196 | if len(student['payments']): |
---|
| 197 | for ticket in student['payments'].values(): |
---|
| 198 | if ticket.p_state == 'paid' and \ |
---|
| 199 | ticket.p_category == 'schoolfee' and \ |
---|
| 200 | ticket.p_session == session: |
---|
| 201 | return True |
---|
| 202 | return False |
---|
| 203 | |
---|
[13566] | 204 | def _isPaymentDisabled(self, p_session, category, student): |
---|
| 205 | academic_session = self._getSessionConfiguration(p_session) |
---|
[14688] | 206 | if category == 'schoolfee': |
---|
| 207 | if 'sf_all' in academic_session.payment_disabled: |
---|
| 208 | return True |
---|
[16516] | 209 | if student.state == RETURNING and \ |
---|
| 210 | 'sf_return' in academic_session.payment_disabled: |
---|
| 211 | return True |
---|
[14688] | 212 | if student.current_mode == 'found' and \ |
---|
| 213 | 'sf_found' in academic_session.payment_disabled: |
---|
| 214 | return True |
---|
| 215 | if student.is_postgrad: |
---|
| 216 | if 'sf_pg' in academic_session.payment_disabled: |
---|
| 217 | return True |
---|
| 218 | return False |
---|
| 219 | if student.current_mode.endswith('ft') and \ |
---|
| 220 | 'sf_ft' in academic_session.payment_disabled: |
---|
| 221 | return True |
---|
| 222 | if student.current_mode.endswith('pt') and \ |
---|
| 223 | 'sf_pt' in academic_session.payment_disabled: |
---|
| 224 | return True |
---|
| 225 | if student.current_mode.startswith('dp') and \ |
---|
| 226 | 'sf_dp' in academic_session.payment_disabled: |
---|
| 227 | return True |
---|
| 228 | if student.current_mode.endswith('sw') and \ |
---|
| 229 | 'sf_sw' in academic_session.payment_disabled: |
---|
| 230 | return True |
---|
[13566] | 231 | if category == 'hostel_maintenance' and \ |
---|
| 232 | 'maint_all' in academic_session.payment_disabled: |
---|
| 233 | return True |
---|
[16025] | 234 | if category == 'clearance': |
---|
| 235 | if 'cl_all' in academic_session.payment_disabled: |
---|
| 236 | return True |
---|
| 237 | if student.is_jupeb and \ |
---|
| 238 | 'cl_jupeb' in academic_session.payment_disabled: |
---|
| 239 | return True |
---|
[16374] | 240 | if not student.is_jupeb and \ |
---|
| 241 | 'cl_allexj' in academic_session.payment_disabled: |
---|
| 242 | return True |
---|
[13566] | 243 | return False |
---|
| 244 | |
---|
[13251] | 245 | #def _hostelApplicationPaymentMade(self, student, session): |
---|
| 246 | # if len(student['payments']): |
---|
| 247 | # for ticket in student['payments'].values(): |
---|
| 248 | # if ticket.p_state == 'paid' and \ |
---|
| 249 | # ticket.p_category == 'hostel_application' and \ |
---|
| 250 | # ticket.p_session == session: |
---|
| 251 | # return True |
---|
| 252 | # return False |
---|
[12566] | 253 | |
---|
[14960] | 254 | def _pharmdInstallments(self, student): |
---|
| 255 | installments = 0.0 |
---|
| 256 | if len(student['payments']): |
---|
| 257 | for ticket in student['payments'].values(): |
---|
| 258 | if ticket.p_state == 'paid' and \ |
---|
| 259 | ticket.p_category.startswith('pharmd') and \ |
---|
| 260 | ticket.p_session == student.current_session: |
---|
| 261 | installments += ticket.amount_auth |
---|
| 262 | return installments |
---|
| 263 | |
---|
[15320] | 264 | def samePaymentMade(self, student, category, p_item, p_session): |
---|
[15447] | 265 | if category in ('bed_allocation', 'transcript'): |
---|
[15320] | 266 | return False |
---|
| 267 | for key in student['payments'].keys(): |
---|
| 268 | ticket = student['payments'][key] |
---|
| 269 | if ticket.p_state == 'paid' and\ |
---|
| 270 | ticket.p_category == category and \ |
---|
| 271 | ticket.p_item == p_item and \ |
---|
| 272 | ticket.p_session == p_session: |
---|
| 273 | return True |
---|
| 274 | return False |
---|
| 275 | |
---|
[9152] | 276 | def setPaymentDetails(self, category, student, |
---|
[15666] | 277 | previous_session, previous_level, combi): |
---|
[8598] | 278 | """Create Payment object and set the payment data of a student for |
---|
| 279 | the payment category specified. |
---|
| 280 | |
---|
| 281 | """ |
---|
| 282 | p_item = u'' |
---|
| 283 | amount = 0.0 |
---|
[9152] | 284 | if previous_session: |
---|
[9520] | 285 | if previous_session < student['studycourse'].entry_session: |
---|
| 286 | return _('The previous session must not fall below ' |
---|
| 287 | 'your entry session.'), None |
---|
| 288 | if category == 'schoolfee': |
---|
| 289 | # School fee is always paid for the following session |
---|
| 290 | if previous_session > student['studycourse'].current_session: |
---|
| 291 | return _('This is not a previous session.'), None |
---|
| 292 | else: |
---|
| 293 | if previous_session > student['studycourse'].current_session - 1: |
---|
| 294 | return _('This is not a previous session.'), None |
---|
[9152] | 295 | p_session = previous_session |
---|
| 296 | p_level = previous_level |
---|
| 297 | p_current = False |
---|
| 298 | else: |
---|
| 299 | p_session = student['studycourse'].current_session |
---|
| 300 | p_level = student['studycourse'].current_level |
---|
| 301 | p_current = True |
---|
[9520] | 302 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 303 | if academic_session == None: |
---|
[8598] | 304 | return _(u'Session configuration object is not available.'), None |
---|
[8676] | 305 | # Determine fee. |
---|
[16873] | 306 | if category.startswith('pharmd') \ |
---|
[14960] | 307 | and student.current_mode == 'special_ft': |
---|
| 308 | amount = 80000.0 |
---|
[16780] | 309 | elif category == 'plag_test': |
---|
| 310 | amount = 2500.0 |
---|
| 311 | if student.is_postgrad: |
---|
| 312 | amount = 5000.0 |
---|
[15108] | 313 | #elif category == 'develop' and student.is_postgrad: |
---|
| 314 | # amount = academic_session.development_fee |
---|
[13251] | 315 | elif category == 'bed_allocation': |
---|
[17236] | 316 | acco_details = self.getAccommodationDetails(student) |
---|
| 317 | p_session = acco_details['booking_session'] |
---|
| 318 | p_item = acco_details['bt'] |
---|
[15268] | 319 | desired_hostel = student['accommodation'].desired_hostel |
---|
[15314] | 320 | if not desired_hostel: |
---|
| 321 | return _(u'Select your favoured hostel first.'), None |
---|
| 322 | if desired_hostel and desired_hostel != 'no': |
---|
[15268] | 323 | p_item = u'%s (%s)' % (p_item, desired_hostel) |
---|
[13251] | 324 | amount = academic_session.booking_fee |
---|
[15002] | 325 | if student.is_postgrad: |
---|
| 326 | amount += 500 |
---|
[13251] | 327 | elif category == 'hostel_maintenance': |
---|
| 328 | amount = 0.0 |
---|
[17236] | 329 | booking_session = grok.getSite()['hostels'].accommodation_session |
---|
| 330 | bedticket = student['accommodation'].get(str(booking_session), None) |
---|
[13500] | 331 | if bedticket is not None and bedticket.bed is not None: |
---|
[13251] | 332 | p_item = bedticket.bed_coordinates |
---|
[17236] | 333 | p_session = booking_session |
---|
[13251] | 334 | if bedticket.bed.__parent__.maint_fee > 0: |
---|
| 335 | amount = bedticket.bed.__parent__.maint_fee |
---|
| 336 | else: |
---|
| 337 | # fallback |
---|
| 338 | amount = academic_session.maint_fee |
---|
| 339 | else: |
---|
[13508] | 340 | return _(u'No bed allocated.'), None |
---|
[13251] | 341 | #elif category == 'hostel_application': |
---|
| 342 | # amount = 1000.0 |
---|
| 343 | #elif category.startswith('tempmaint'): |
---|
| 344 | # if not self._hostelApplicationPaymentMade( |
---|
| 345 | # student, student.current_session): |
---|
| 346 | # return _( |
---|
| 347 | # 'You have not yet paid the hostel application fee.'), None |
---|
| 348 | # if category == 'tempmaint_1': |
---|
| 349 | # amount = 8150.0 |
---|
| 350 | # elif category == 'tempmaint_2': |
---|
| 351 | # amount = 12650.0 |
---|
| 352 | # elif category == 'tempmaint_3': |
---|
| 353 | # amount = 9650.0 |
---|
[7151] | 354 | elif category == 'clearance': |
---|
[9796] | 355 | p_item = student.certcode |
---|
| 356 | if p_item is None: |
---|
[8598] | 357 | return _('Study course data are incomplete.'), None |
---|
[14902] | 358 | if student.is_jupeb: |
---|
[14897] | 359 | amount = 50000.0 |
---|
| 360 | elif student.faccode.startswith('FCETA'): |
---|
[13869] | 361 | # ASABA and AKOKA |
---|
[14932] | 362 | amount = 35000.0 |
---|
[17112] | 363 | elif student.depcode == 'DMIC': |
---|
| 364 | amount = 70000.0 |
---|
[17361] | 365 | elif student.faccode in ('BMS', 'MED', 'DEN') \ |
---|
| 366 | and not student.is_postgrad: |
---|
[14897] | 367 | amount = 80000.0 |
---|
[15574] | 368 | elif student.faccode == 'DCOEM': |
---|
| 369 | return _('Acceptance fee payment not necessary.'), None |
---|
[11479] | 370 | else: |
---|
[14897] | 371 | amount = 60000.0 |
---|
[7151] | 372 | elif category == 'schoolfee': |
---|
[8598] | 373 | try: |
---|
| 374 | certificate = student['studycourse'].certificate |
---|
| 375 | p_item = certificate.code |
---|
| 376 | except (AttributeError, TypeError): |
---|
| 377 | return _('Study course data are incomplete.'), None |
---|
[17457] | 378 | try: |
---|
| 379 | if student.entry_session < 2017: |
---|
| 380 | schoolfees_dict = SCHOOLFEES[12][p_item] |
---|
| 381 | elif student.entry_session < 2020: |
---|
| 382 | schoolfees_dict = SCHOOLFEES[17][p_item] |
---|
| 383 | elif student.entry_session < 2022: |
---|
| 384 | schoolfees_dict = SCHOOLFEES[20][p_item] |
---|
| 385 | else: |
---|
| 386 | schoolfees_dict = SCHOOLFEES[22][p_item] |
---|
| 387 | except KeyError: |
---|
| 388 | return _('School fee not yet fixed: p_item = %s' % p_item), None |
---|
[9152] | 389 | if previous_session: |
---|
[9520] | 390 | # Students can pay for previous sessions in all workflow states. |
---|
| 391 | # Fresh students are excluded by the update method of the |
---|
| 392 | # PreviousPaymentAddFormPage. |
---|
[9157] | 393 | if previous_session == student['studycourse'].entry_session: |
---|
[9152] | 394 | if student.is_foreigner: |
---|
[17457] | 395 | amount = schoolfees_dict['initial_foreigner'] |
---|
[9152] | 396 | else: |
---|
[17457] | 397 | amount = schoolfees_dict['initial'] |
---|
[9006] | 398 | else: |
---|
[9152] | 399 | if student.is_foreigner: |
---|
[17457] | 400 | amount = schoolfees_dict['returning_foreigner'] |
---|
[9152] | 401 | else: |
---|
[17457] | 402 | amount = schoolfees_dict['returning'] |
---|
[9152] | 403 | else: |
---|
| 404 | if student.state == CLEARED: |
---|
| 405 | if student.is_foreigner: |
---|
[17457] | 406 | amount = schoolfees_dict['initial_foreigner'] |
---|
[9152] | 407 | else: |
---|
[17457] | 408 | amount = schoolfees_dict['initial'] |
---|
[14858] | 409 | elif student.state == PAID and student.is_postgrad: |
---|
[9513] | 410 | p_session += 1 |
---|
[9520] | 411 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 412 | if academic_session == None: |
---|
[9513] | 413 | return _(u'Session configuration object is not available.'), None |
---|
| 414 | if student.is_foreigner: |
---|
[17457] | 415 | amount = schoolfees_dict['returning_foreigner'] |
---|
[9513] | 416 | else: |
---|
[17457] | 417 | amount = schoolfees_dict['returning'] |
---|
[9152] | 418 | elif student.state == RETURNING: |
---|
| 419 | # In case of returning school fee payment the payment session |
---|
| 420 | # and level contain the values of the session the student |
---|
| 421 | # has paid for. |
---|
| 422 | p_session, p_level = self.getReturningData(student) |
---|
[9520] | 423 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 424 | if academic_session == None: |
---|
[9152] | 425 | return _(u'Session configuration object is not available.'), None |
---|
[9570] | 426 | |
---|
[9520] | 427 | # Students are only allowed to pay for the next session |
---|
| 428 | # if current session payment has really been made, |
---|
| 429 | # i.e. payment object exists and is paid. |
---|
[9570] | 430 | #if not self._paymentMade( |
---|
| 431 | # student, student.current_session): |
---|
| 432 | # return _('You have not yet paid your current/active' + |
---|
| 433 | # ' session. Please use the previous session' + |
---|
| 434 | # ' payment form first.'), None |
---|
| 435 | |
---|
[9152] | 436 | if student.is_foreigner: |
---|
[17457] | 437 | amount = schoolfees_dict['returning_foreigner'] |
---|
[9152] | 438 | else: |
---|
[17457] | 439 | amount = schoolfees_dict['returning'] |
---|
[14960] | 440 | # PHARMD school fee amount is fixed and previously paid |
---|
| 441 | # installments in current session are deducted. |
---|
[15363] | 442 | if student.current_mode == 'special_ft' \ |
---|
| 443 | and student.state in (RETURNING, CLEARED): |
---|
| 444 | if student.is_foreigner: |
---|
| 445 | amount = 260000.0 - self._pharmdInstallments(student) |
---|
| 446 | else: |
---|
| 447 | amount = 160000.0 - self._pharmdInstallments(student) |
---|
[17457] | 448 | try: |
---|
| 449 | amount = float(amount) |
---|
| 450 | except ValueError: |
---|
| 451 | return _(u'School fee not yet fixed: p_item = %s' % p_item), None |
---|
[9006] | 452 | # Give 50% school fee discount to staff members. |
---|
| 453 | if student.is_staff: |
---|
| 454 | amount /= 2 |
---|
[17457] | 455 | |
---|
[16873] | 456 | else: |
---|
| 457 | fee_name = category + '_fee' |
---|
| 458 | amount = getattr(academic_session, fee_name, 0.0) |
---|
[8598] | 459 | if amount in (0.0, None): |
---|
[9520] | 460 | return _('Amount could not be determined.'), None |
---|
[8676] | 461 | # Add session specific penalty fee. |
---|
| 462 | if category == 'schoolfee' and student.is_postgrad: |
---|
| 463 | amount += academic_session.penalty_pg |
---|
[15108] | 464 | amount += academic_session.development_fee |
---|
[13757] | 465 | elif category == 'schoolfee' and student.current_mode == ('ug_ft'): |
---|
[13756] | 466 | amount += academic_session.penalty_ug_ft |
---|
[13757] | 467 | elif category == 'schoolfee' and student.current_mode == ('ug_pt'): |
---|
[13756] | 468 | amount += academic_session.penalty_ug_pt |
---|
[13998] | 469 | elif category == 'schoolfee' and student.current_mode == ('ug_sw'): |
---|
| 470 | amount += academic_session.penalty_sw |
---|
[14717] | 471 | elif category == 'schoolfee' and student.current_mode in ( |
---|
| 472 | 'dp_ft', 'dp_pt'): |
---|
| 473 | amount += academic_session.penalty_dp |
---|
[9727] | 474 | if category.startswith('tempmaint'): |
---|
| 475 | p_item = getUtility(IKofaUtils).PAYMENT_CATEGORIES[category] |
---|
| 476 | p_item = unicode(p_item) |
---|
| 477 | # Now we change the category because tempmaint payments |
---|
[12566] | 478 | # will be obsolete when Uniben returns to Kofa bed allocation. |
---|
[9727] | 479 | category = 'hostel_maintenance' |
---|
[8676] | 480 | # Create ticket. |
---|
[15320] | 481 | if self.samePaymentMade(student, category, p_item, p_session): |
---|
[11644] | 482 | return _('This type of payment has already been made.'), None |
---|
[11459] | 483 | if self._isPaymentDisabled(p_session, category, student): |
---|
[13814] | 484 | return _('This category of payments has been disabled.'), None |
---|
[8715] | 485 | payment = createObject(u'waeup.StudentOnlinePayment') |
---|
[8950] | 486 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
[8598] | 487 | payment.p_id = "p%s" % timestamp |
---|
| 488 | payment.p_category = category |
---|
| 489 | payment.p_item = p_item |
---|
| 490 | payment.p_session = p_session |
---|
| 491 | payment.p_level = p_level |
---|
[9152] | 492 | payment.p_current = p_current |
---|
[8598] | 493 | payment.amount_auth = amount |
---|
| 494 | return None, payment |
---|
[7621] | 495 | |
---|
[14588] | 496 | def warnCreditsOOR(self, studylevel, course=None): |
---|
[9831] | 497 | studycourse = studylevel.__parent__ |
---|
| 498 | certificate = getattr(studycourse,'certificate', None) |
---|
| 499 | current_level = studycourse.current_level |
---|
| 500 | if None in (current_level, certificate): |
---|
[14588] | 501 | return |
---|
[16438] | 502 | if studylevel.__parent__.previous_verdict == 'R': |
---|
| 503 | return |
---|
[9831] | 504 | end_level = certificate.end_level |
---|
[15840] | 505 | if studylevel.student.faccode in ( |
---|
| 506 | 'MED', 'DEN', 'BMS') and studylevel.level == 200: |
---|
| 507 | limit = 61 |
---|
| 508 | elif current_level >= end_level: |
---|
[14588] | 509 | limit = 51 |
---|
| 510 | else: |
---|
| 511 | limit = 50 |
---|
| 512 | if course and studylevel.total_credits + course.credits > limit: |
---|
| 513 | return _('Maximum credits exceeded.') |
---|
| 514 | elif studylevel.total_credits > limit: |
---|
| 515 | return _('Maximum credits exceeded.') |
---|
| 516 | return |
---|
[9831] | 517 | |
---|
[16406] | 518 | def warnCourseAlreadyPassed(self, studylevel, course): |
---|
| 519 | """Return message if course has already been passed at |
---|
| 520 | previous levels. |
---|
| 521 | """ |
---|
[16413] | 522 | |
---|
| 523 | # med: we may need to put this matter on hold and allow |
---|
| 524 | # all the students to register. |
---|
| 525 | return False |
---|
| 526 | |
---|
[16406] | 527 | previous_verdict = studylevel.__parent__.previous_verdict |
---|
| 528 | if previous_verdict in ('C', 'M'): |
---|
| 529 | return False |
---|
| 530 | for slevel in studylevel.__parent__.values(): |
---|
| 531 | for cticket in slevel.values(): |
---|
| 532 | if cticket.code == course.code \ |
---|
| 533 | and cticket.total_score >= cticket.passmark: |
---|
| 534 | return _('Course has already been passed at previous level.') |
---|
| 535 | return False |
---|
| 536 | |
---|
[11773] | 537 | def clearance_disabled_message(self, student): |
---|
| 538 | if student.is_postgrad: |
---|
| 539 | return None |
---|
| 540 | try: |
---|
| 541 | session_config = grok.getSite()[ |
---|
| 542 | 'configuration'][str(student.current_session)] |
---|
| 543 | except KeyError: |
---|
| 544 | return _('Session configuration object is not available.') |
---|
| 545 | if not session_config.clearance_enabled: |
---|
| 546 | return _('Clearance is disabled for this session.') |
---|
| 547 | return None |
---|
| 548 | |
---|
[16100] | 549 | def renderPDFTranscript(self, view, filename='transcript.pdf', |
---|
| 550 | student=None, |
---|
| 551 | studentview=None, |
---|
| 552 | note=None, |
---|
| 553 | signatures=(), |
---|
| 554 | sigs_in_footer=(), |
---|
| 555 | digital_sigs=(), |
---|
| 556 | show_scans=True, topMargin=1.5, |
---|
| 557 | omit_fields=(), |
---|
| 558 | tableheader=None, |
---|
| 559 | no_passport=False, |
---|
| 560 | save_file=False): |
---|
| 561 | """Render pdf slip of a transcripts. |
---|
| 562 | """ |
---|
| 563 | portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE |
---|
| 564 | # XXX: tell what the different parameters mean |
---|
| 565 | style = getSampleStyleSheet() |
---|
| 566 | creator = self.getPDFCreator(student) |
---|
| 567 | data = [] |
---|
| 568 | doc_title = view.label |
---|
| 569 | author = '%s (%s)' % (view.request.principal.title, |
---|
| 570 | view.request.principal.id) |
---|
| 571 | footer_text = view.label.split('\n') |
---|
| 572 | if len(footer_text) > 2: |
---|
| 573 | # We can add a department in first line |
---|
| 574 | footer_text = footer_text[1] |
---|
| 575 | else: |
---|
| 576 | # Only the first line is used for the footer |
---|
| 577 | footer_text = footer_text[0] |
---|
| 578 | if getattr(student, 'student_id', None) is not None: |
---|
| 579 | footer_text = "%s - %s - " % (student.student_id, footer_text) |
---|
| 580 | |
---|
| 581 | # Insert student data table |
---|
| 582 | if student is not None: |
---|
| 583 | #bd_translation = trans(_('Base Data'), portal_language) |
---|
| 584 | #data.append(Paragraph(bd_translation, HEADING_STYLE)) |
---|
| 585 | data.append(render_student_data( |
---|
| 586 | studentview, view.context, |
---|
| 587 | omit_fields, lang=portal_language, |
---|
| 588 | slipname=filename, |
---|
| 589 | no_passport=no_passport)) |
---|
| 590 | |
---|
| 591 | transcript_data = view.context.getTranscriptData() |
---|
| 592 | levels_data = transcript_data[0] |
---|
| 593 | |
---|
| 594 | contextdata = [] |
---|
| 595 | f_label = trans(_('Course of Study:'), portal_language) |
---|
| 596 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
| 597 | f_text = formatted_text(view.context.certificate.longtitle) |
---|
| 598 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
| 599 | contextdata.append([f_label,f_text]) |
---|
| 600 | |
---|
| 601 | f_label = trans(_('Faculty:'), portal_language) |
---|
| 602 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
| 603 | f_text = formatted_text( |
---|
| 604 | view.context.certificate.__parent__.__parent__.__parent__.longtitle) |
---|
| 605 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
| 606 | contextdata.append([f_label,f_text]) |
---|
| 607 | |
---|
| 608 | f_label = trans(_('Department:'), portal_language) |
---|
| 609 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
| 610 | f_text = formatted_text( |
---|
| 611 | view.context.certificate.__parent__.__parent__.longtitle) |
---|
| 612 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
| 613 | contextdata.append([f_label,f_text]) |
---|
| 614 | |
---|
| 615 | f_label = trans(_('Entry Session:'), portal_language) |
---|
| 616 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
| 617 | f_text = formatted_text( |
---|
| 618 | view.session_dict.get(view.context.entry_session)) |
---|
| 619 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
| 620 | contextdata.append([f_label,f_text]) |
---|
| 621 | |
---|
| 622 | f_label = trans(_('Final Session:'), portal_language) |
---|
| 623 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
| 624 | f_text = formatted_text( |
---|
| 625 | view.session_dict.get(view.context.current_session)) |
---|
| 626 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
| 627 | contextdata.append([f_label,f_text]) |
---|
| 628 | |
---|
| 629 | f_label = trans(_('Entry Mode:'), portal_language) |
---|
| 630 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
| 631 | f_text = formatted_text(view.studymode_dict.get( |
---|
| 632 | view.context.entry_mode)) |
---|
| 633 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
| 634 | contextdata.append([f_label,f_text]) |
---|
| 635 | |
---|
| 636 | f_label = trans(_('Final Verdict:'), portal_language) |
---|
| 637 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
| 638 | f_text = formatted_text(view.studymode_dict.get( |
---|
| 639 | view.context.current_verdict)) |
---|
| 640 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
| 641 | contextdata.append([f_label,f_text]) |
---|
| 642 | |
---|
| 643 | f_label = trans(_('Cumulative GPA:'), portal_language) |
---|
| 644 | f_label = Paragraph(f_label, ENTRY1_STYLE) |
---|
| 645 | format_float = getUtility(IKofaUtils).format_float |
---|
| 646 | cgpa = format_float(transcript_data[1], 3) |
---|
| 647 | if student.state == GRADUATED: |
---|
| 648 | f_text = formatted_text('%s (%s)' % ( |
---|
| 649 | cgpa, self.getClassFromCGPA(transcript_data[1], student)[1])) |
---|
| 650 | else: |
---|
| 651 | f_text = formatted_text('%s' % cgpa) |
---|
[17498] | 652 | if not transcript_data[1]: |
---|
| 653 | f_text = formatted_text('No results yet!') |
---|
[16100] | 654 | f_text = Paragraph(f_text, ENTRY1_STYLE) |
---|
| 655 | contextdata.append([f_label,f_text]) |
---|
| 656 | |
---|
| 657 | contexttable = Table(contextdata,style=SLIP_STYLE) |
---|
| 658 | data.append(contexttable) |
---|
| 659 | |
---|
[17498] | 660 | if transcript_data[1]: |
---|
| 661 | transcripttables = render_transcript_data( |
---|
| 662 | view, tableheader, levels_data, lang=portal_language) |
---|
| 663 | data.extend(transcripttables) |
---|
[16100] | 664 | |
---|
| 665 | # Insert signatures |
---|
| 666 | # XXX: We are using only sigs_in_footer in waeup.kofa, so we |
---|
| 667 | # do not have a test for the following lines. |
---|
| 668 | if signatures and not sigs_in_footer: |
---|
| 669 | data.append(Spacer(1, 20)) |
---|
| 670 | # Render one signature table per signature to |
---|
| 671 | # get date and signature in line. |
---|
| 672 | for signature in signatures: |
---|
| 673 | signaturetables = get_signature_tables(signature) |
---|
| 674 | data.append(signaturetables[0]) |
---|
| 675 | |
---|
| 676 | # Insert digital signatures |
---|
| 677 | if digital_sigs: |
---|
| 678 | data.append(Spacer(1, 20)) |
---|
| 679 | sigs = digital_sigs.split('\n') |
---|
| 680 | for sig in sigs: |
---|
| 681 | data.append(Paragraph(sig, NOTE_STYLE)) |
---|
| 682 | |
---|
| 683 | view.response.setHeader( |
---|
| 684 | 'Content-Type', 'application/pdf') |
---|
| 685 | try: |
---|
| 686 | pdf_stream = creator.create_pdf( |
---|
| 687 | data, None, doc_title, author=author, footer=footer_text, |
---|
[16906] | 688 | note=note, sigs_in_footer=sigs_in_footer, topMargin=topMargin, |
---|
| 689 | view=view) |
---|
[16100] | 690 | except IOError: |
---|
| 691 | view.flash(_('Error in image file.')) |
---|
| 692 | return view.redirect(view.url(view.context)) |
---|
| 693 | if save_file: |
---|
| 694 | self._saveTranscriptPDF(student, pdf_stream) |
---|
| 695 | return |
---|
| 696 | return pdf_stream |
---|
| 697 | |
---|
[14038] | 698 | #: A tuple containing the names of registration states in which changing of |
---|
| 699 | #: passport pictures is allowed. |
---|
[16445] | 700 | PORTRAIT_CHANGE_STATES = (CLEARANCE, REQUESTED) |
---|
[14038] | 701 | |
---|
[16611] | 702 | #: A tuple containing the names of registration states in which changing of |
---|
| 703 | #: scanned signatures is allowed. |
---|
[16620] | 704 | SIGNATURE_CHANGE_STATES = (CLEARED, RETURNING, PAID, REGISTERED, VALIDATED, ) |
---|
[16611] | 705 | |
---|
[8441] | 706 | # Uniben prefix |
---|
[17145] | 707 | @property |
---|
| 708 | def STUDENT_ID_PREFIX(self): |
---|
| 709 | if grok.getSite().__name__ == 'uniben-cdl': |
---|
| 710 | return u'C' |
---|
| 711 | return u'B' |
---|
[15980] | 712 | |
---|
| 713 | STUDENT_EXPORTER_NAMES = ( |
---|
| 714 | 'students', |
---|
| 715 | 'studentstudycourses', |
---|
[16840] | 716 | 'studentstudycourses_1', |
---|
[15980] | 717 | 'studentstudylevels', |
---|
[16840] | 718 | #'studentstudylevels_1', |
---|
[15980] | 719 | 'coursetickets', |
---|
[16840] | 720 | #'coursetickets_1', |
---|
[15980] | 721 | 'studentpayments', |
---|
| 722 | 'bedtickets', |
---|
| 723 | 'trimmed', |
---|
| 724 | 'outstandingcourses', |
---|
| 725 | 'unpaidpayments', |
---|
| 726 | 'sfpaymentsoverview', |
---|
| 727 | 'sessionpaymentsoverview', |
---|
| 728 | 'studylevelsoverview', |
---|
| 729 | 'combocard', |
---|
| 730 | 'bursary', |
---|
| 731 | 'accommodationpayments', |
---|
| 732 | 'transcriptdata', |
---|
| 733 | 'trimmedpayments', |
---|
[16390] | 734 | 'medicalhistory', |
---|
[17396] | 735 | 'nysc', |
---|
[15980] | 736 | ) |
---|