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