[10765] | 1 | ## $Id: utils.py 15209 2018-10-30 07:38:19Z 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 | ## |
---|
| 18 | from time import time |
---|
[15176] | 19 | import grok |
---|
[10765] | 20 | from zope.component import createObject, getUtility |
---|
| 21 | from waeup.kofa.interfaces import (IKofaUtils, |
---|
| 22 | CLEARED, RETURNING, PAID, REGISTERED, VALIDATED) |
---|
| 23 | from kofacustom.nigeria.students.utils import NigeriaStudentsUtils |
---|
[15000] | 24 | from kofacustom.edopoly.interfaces import MessageFactory as _ |
---|
[10765] | 25 | |
---|
| 26 | class CustomStudentsUtils(NigeriaStudentsUtils): |
---|
| 27 | """A collection of customized methods. |
---|
| 28 | |
---|
| 29 | """ |
---|
| 30 | |
---|
[15008] | 31 | # prefix |
---|
| 32 | STUDENT_ID_PREFIX = u'U' |
---|
| 33 | |
---|
[15035] | 34 | def warnCreditsOOR(self, studylevel, course=None): |
---|
| 35 | """No maximum credits. |
---|
| 36 | """ |
---|
| 37 | return |
---|
| 38 | |
---|
[15013] | 39 | def GPABoundaries(self, faccode=None, depcode=None, |
---|
| 40 | certcode=None, student=None): |
---|
| 41 | if student and student.current_mode.startswith('dp'): |
---|
| 42 | return ((1, 'IRNS / NER / NYV'), |
---|
| 43 | (2, 'Pass'), |
---|
| 44 | (2.5, 'Lower Credit'), |
---|
| 45 | (3, 'Upper Credit'), |
---|
| 46 | (3.5, 'Distinction')) |
---|
| 47 | elif student: |
---|
| 48 | return ((1, 'FRNS / NER / NYV'), |
---|
| 49 | (1.5, 'Pass'), |
---|
| 50 | (2.4, '3rd Class Honours'), |
---|
| 51 | (3.5, '2nd Class Honours Lower Division'), |
---|
| 52 | (4.5, '2nd Class Honours Upper Division'), |
---|
| 53 | (5, '1st Class Honours')) |
---|
| 54 | # Session Results Presentations depend on certificate |
---|
| 55 | results = None |
---|
| 56 | if certcode: |
---|
| 57 | cat = queryUtility(ICatalog, name='certificates_catalog') |
---|
| 58 | results = list( |
---|
| 59 | cat.searchResults(code=(certcode, certcode))) |
---|
| 60 | if results and results[0].study_mode.startswith('dp'): |
---|
| 61 | return ((1, 'IRNS / NER / NYV'), |
---|
| 62 | (2, 'Pass'), |
---|
| 63 | (2.5, 'Lower Credit'), |
---|
| 64 | (3, 'Upper Credit'), |
---|
| 65 | (3.5, 'Distinction')) |
---|
| 66 | else: |
---|
| 67 | return ((1, 'FRNS / NER / NYV'), |
---|
| 68 | (1.5, 'Pass'), |
---|
| 69 | (2.4, '3rd Class Honours'), |
---|
| 70 | (3.5, '2nd Class Honours Lower Division'), |
---|
| 71 | (4.5, '2nd Class Honours Upper Division'), |
---|
| 72 | (5, '1st Class Honours')) |
---|
[15011] | 73 | |
---|
[15013] | 74 | def getClassFromCGPA(self, gpa, student): |
---|
| 75 | gpa_boundaries = self.GPABoundaries(student=student) |
---|
| 76 | if gpa < gpa_boundaries[0][0]: |
---|
| 77 | return 0, gpa_boundaries[0][1] |
---|
| 78 | if gpa < gpa_boundaries[1][0]: |
---|
| 79 | return 1, gpa_boundaries[1][1] |
---|
| 80 | if gpa < gpa_boundaries[2][0]: |
---|
| 81 | return 2, gpa_boundaries[2][1] |
---|
| 82 | if gpa < gpa_boundaries[3][0]: |
---|
| 83 | return 3, gpa_boundaries[3][1] |
---|
| 84 | if gpa < gpa_boundaries[4][0]: |
---|
| 85 | return 4, gpa_boundaries[4][1] |
---|
| 86 | if gpa <= gpa_boundaries[5][0]: |
---|
| 87 | return 5, gpa_boundaries[5][1] |
---|
| 88 | return 'N/A' |
---|
| 89 | |
---|
[15056] | 90 | def _requiredPaymentsMade(self, student, session): |
---|
[15064] | 91 | req_payments = ('ict_entre', 'logbook_combo', 'siwess_combo') |
---|
| 92 | req_payments_titles = 'ICT, Logbook and SIWESS' |
---|
[15056] | 93 | if len(student['payments']): |
---|
[15072] | 94 | # All ND and HND of part time do not pay LOGBOOK |
---|
[15064] | 95 | if student.current_mode.endswith('_pt'): |
---|
| 96 | req_payments = ('ict_entre', 'siwess_combo') |
---|
| 97 | req_payments_titles = 'ICT and SIWESS' |
---|
[15072] | 98 | # HND2 full time do not pay for SIWES |
---|
| 99 | elif student.current_mode == 'hnd_ft' and student.state == RETURNING: |
---|
| 100 | req_payments = ('ict_entre', 'logbook_combo') |
---|
| 101 | req_payments_titles = 'ICT and Logbook' |
---|
| 102 | # HND1 full time do not pay both SIWES and LOGBOOK |
---|
| 103 | elif student.current_mode == 'hnd_ft' and student.state == CLEARED: |
---|
| 104 | req_payments = ('ict_entre',) |
---|
| 105 | req_payments_titles = 'ICT' |
---|
| 106 | # ND2 FULL TIME Do not pay LOGBOOK |
---|
| 107 | elif student.current_mode == 'nd_ft' and student.state == RETURNING: |
---|
| 108 | req_payments = ('ict_entre', 'siwess_combo') |
---|
| 109 | req_payments_titles = 'ICT and SIWESS' |
---|
| 110 | # ND1 full time do not pay SIWES |
---|
| 111 | elif student.current_mode == 'nd_ft' and student.state == CLEARED: |
---|
| 112 | req_payments = ('ict_entre', 'logbook_combo') |
---|
| 113 | req_payments_titles = 'ICT and Logbook' |
---|
[15056] | 114 | num = 0 |
---|
| 115 | for ticket in student['payments'].values(): |
---|
| 116 | if ticket.p_state == 'paid' and \ |
---|
[15064] | 117 | ticket.p_category in req_payments and \ |
---|
[15056] | 118 | ticket.p_session == session: |
---|
| 119 | num += 1 |
---|
[15064] | 120 | if num == len(req_payments): |
---|
| 121 | return True, None |
---|
| 122 | return False, req_payments_titles |
---|
[15056] | 123 | |
---|
[15011] | 124 | def setPaymentDetails(self, category, student, |
---|
| 125 | previous_session, previous_level): |
---|
| 126 | """Create a payment ticket and set the payment data of a |
---|
| 127 | student for the payment category specified. |
---|
| 128 | """ |
---|
| 129 | p_item = u'' |
---|
| 130 | amount = 0.0 |
---|
| 131 | if previous_session: |
---|
| 132 | if previous_session < student['studycourse'].entry_session: |
---|
| 133 | return _('The previous session must not fall below ' |
---|
| 134 | 'your entry session.'), None |
---|
| 135 | if category == 'schoolfee': |
---|
| 136 | # School fee is always paid for the following session |
---|
| 137 | if previous_session > student['studycourse'].current_session: |
---|
| 138 | return _('This is not a previous session.'), None |
---|
| 139 | else: |
---|
| 140 | if previous_session > student['studycourse'].current_session - 1: |
---|
| 141 | return _('This is not a previous session.'), None |
---|
| 142 | p_session = previous_session |
---|
| 143 | p_level = previous_level |
---|
| 144 | p_current = False |
---|
| 145 | else: |
---|
| 146 | p_session = student['studycourse'].current_session |
---|
| 147 | p_level = student['studycourse'].current_level |
---|
| 148 | p_current = True |
---|
| 149 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 150 | if academic_session == None: |
---|
| 151 | return _(u'Session configuration object is not available.'), None |
---|
| 152 | # Determine fee. |
---|
[15056] | 153 | # The following three fees are part of the school fee which must be |
---|
| 154 | # paid before tuition fee. |
---|
| 155 | if category in ('ict_entre', 'logbook_combo', 'siwess_combo') and \ |
---|
[15209] | 156 | student.state == RETURNING and not previous_session: |
---|
[15056] | 157 | p_session, p_level = self.getReturningData(student) |
---|
[15011] | 158 | if category == 'schoolfee': |
---|
| 159 | try: |
---|
| 160 | certificate = student['studycourse'].certificate |
---|
| 161 | p_item = certificate.code |
---|
| 162 | except (AttributeError, TypeError): |
---|
| 163 | return _('Study course data are incomplete.'), None |
---|
| 164 | if previous_session: |
---|
[15015] | 165 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
[15011] | 166 | else: |
---|
[15015] | 167 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
| 168 | if student.state == RETURNING: |
---|
[15011] | 169 | # In case of returning school fee payment the |
---|
| 170 | # payment session and level contain the values of |
---|
| 171 | # the session the student has paid for. Payment |
---|
| 172 | # session is always next session. |
---|
| 173 | p_session, p_level = self.getReturningData(student) |
---|
| 174 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 175 | if academic_session == None: |
---|
| 176 | return _( |
---|
| 177 | u'Session configuration object is not available.' |
---|
| 178 | ), None |
---|
[15015] | 179 | |
---|
[15011] | 180 | elif student.is_postgrad and student.state == PAID: |
---|
| 181 | # Returning postgraduate students also pay for the |
---|
| 182 | # next session but their level always remains the |
---|
| 183 | # same. |
---|
| 184 | p_session += 1 |
---|
| 185 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 186 | if academic_session == None: |
---|
| 187 | return _( |
---|
| 188 | u'Session configuration object is not available.' |
---|
| 189 | ), None |
---|
[15078] | 190 | rpm, rpt = self._requiredPaymentsMade(student, p_session) |
---|
| 191 | if not rpm: |
---|
| 192 | return 'Pay %s fee(s) first.' % rpt, None |
---|
[15011] | 193 | elif category == 'clearance': |
---|
| 194 | try: |
---|
| 195 | p_item = student['studycourse'].certificate.code |
---|
| 196 | except (AttributeError, TypeError): |
---|
| 197 | return _('Study course data are incomplete.'), None |
---|
| 198 | amount = academic_session.clearance_fee |
---|
| 199 | elif category == 'bed_allocation': |
---|
| 200 | p_item = self.getAccommodationDetails(student)['bt'] |
---|
| 201 | amount = academic_session.booking_fee |
---|
| 202 | elif category == 'hostel_maintenance': |
---|
| 203 | amount = 0.0 |
---|
| 204 | bedticket = student['accommodation'].get( |
---|
| 205 | str(student.current_session), None) |
---|
| 206 | if bedticket is not None and bedticket.bed is not None: |
---|
| 207 | p_item = bedticket.bed_coordinates |
---|
| 208 | if bedticket.bed.__parent__.maint_fee > 0: |
---|
| 209 | amount = bedticket.bed.__parent__.maint_fee |
---|
| 210 | else: |
---|
| 211 | # fallback |
---|
| 212 | amount = academic_session.maint_fee |
---|
| 213 | else: |
---|
| 214 | return _(u'No bed allocated.'), None |
---|
[15183] | 215 | else: |
---|
| 216 | fee_name = category + '_fee' |
---|
| 217 | amount = getattr(academic_session, fee_name, 0.0) |
---|
| 218 | |
---|
| 219 | |
---|
[15011] | 220 | if amount in (0.0, None): |
---|
| 221 | return _('Amount could not be determined.'), None |
---|
| 222 | if self.samePaymentMade(student, category, p_item, p_session): |
---|
| 223 | return _('This type of payment has already been made.'), None |
---|
| 224 | if self._isPaymentDisabled(p_session, category, student): |
---|
| 225 | return _('This category of payments has been disabled.'), None |
---|
| 226 | payment = createObject(u'waeup.StudentOnlinePayment') |
---|
| 227 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
| 228 | payment.p_id = "p%s" % timestamp |
---|
| 229 | payment.p_category = category |
---|
| 230 | payment.p_item = p_item |
---|
| 231 | payment.p_session = p_session |
---|
| 232 | payment.p_level = p_level |
---|
| 233 | payment.p_current = p_current |
---|
| 234 | payment.amount_auth = amount |
---|
[15176] | 235 | return None, payment |
---|
| 236 | |
---|
| 237 | def constructMatricNumber(self, student): |
---|
| 238 | faccode = student.faccode |
---|
| 239 | depcode = student.depcode |
---|
| 240 | certcode = student.certcode |
---|
| 241 | year = unicode(student.entry_session)[2:] |
---|
| 242 | if not student.state in (PAID, ) or not student.is_fresh: |
---|
| 243 | return _('Matriculation number cannot be set.'), None |
---|
| 244 | |
---|
| 245 | # ESITM/ENG/MEC/11/5367 |
---|
| 246 | if student.current_mode == 'nd_ft': |
---|
| 247 | next_integer = grok.getSite()['configuration'].next_matric_integer |
---|
| 248 | if next_integer == 0: |
---|
| 249 | return _('Matriculation number cannot be set.'), None |
---|
| 250 | return None, "ESITM/%s/%s/%s/%05d" % ( |
---|
| 251 | faccode, depcode, year, next_integer) |
---|
| 252 | |
---|
| 253 | # ESITM/ENG/MEC/HND/11/5367 |
---|
| 254 | if student.current_mode == 'hnd_ft': |
---|
| 255 | next_integer = grok.getSite()['configuration'].next_matric_integer_2 |
---|
| 256 | if next_integer == 0: |
---|
| 257 | return _('Matriculation number cannot be set.'), None |
---|
| 258 | return None, "ESITM/%s/%s/HND/%s/%05d" % ( |
---|
| 259 | faccode, depcode, year, next_integer) |
---|
| 260 | |
---|
| 261 | # ESITM/PT-ND/ENG/MEC/11/5367 |
---|
| 262 | if student.current_mode == 'nd_pt': |
---|
| 263 | next_integer = grok.getSite()['configuration'].next_matric_integer_3 |
---|
| 264 | if next_integer == 0: |
---|
| 265 | return _('Matriculation number cannot be set.'), None |
---|
| 266 | return None, "ESITM/PT-ND/%s/%s/%s/%05d" % ( |
---|
| 267 | faccode, depcode, year, next_integer) |
---|
| 268 | |
---|
| 269 | # ??? |
---|
| 270 | if student.current_mode == 'hnd_pt': |
---|
| 271 | pass |
---|
| 272 | |
---|
| 273 | return _('Matriculation number cannot be set.'), None |
---|
[15196] | 274 | |
---|
| 275 | def getAccommodationDetails(self, student): |
---|
| 276 | """Determine the accommodation data of a student. |
---|
| 277 | """ |
---|
| 278 | d = {} |
---|
| 279 | d['error'] = u'' |
---|
| 280 | hostels = grok.getSite()['hostels'] |
---|
| 281 | d['booking_session'] = hostels.accommodation_session |
---|
| 282 | d['allowed_states'] = hostels.accommodation_states |
---|
| 283 | d['startdate'] = hostels.startdate |
---|
| 284 | d['enddate'] = hostels.enddate |
---|
| 285 | d['expired'] = hostels.expired |
---|
| 286 | # Determine bed type |
---|
| 287 | studycourse = student['studycourse'] |
---|
| 288 | certificate = getattr(studycourse,'certificate',None) |
---|
| 289 | entry_session = studycourse.entry_session |
---|
| 290 | current_level = studycourse.current_level |
---|
| 291 | if None in (entry_session, current_level, certificate): |
---|
| 292 | return d |
---|
| 293 | bt = 'all' |
---|
| 294 | if student.sex == 'f': |
---|
| 295 | sex = 'female' |
---|
| 296 | else: |
---|
| 297 | sex = 'male' |
---|
| 298 | special_handling = 'regular' |
---|
| 299 | d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt) |
---|
| 300 | return d |
---|