[7419] | 1 | ## $Id: utils.py 13400 2015-11-06 18:29:20Z 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 |
---|
[8600] | 19 | from time import time |
---|
| 20 | from zope.component import createObject |
---|
[10922] | 21 | from waeup.kofa.interfaces import ( |
---|
[13348] | 22 | ADMITTED, CLEARED, RETURNING, PAID, academic_sessions_vocab) |
---|
[8823] | 23 | from kofacustom.nigeria.students.utils import NigeriaStudentsUtils |
---|
[8247] | 24 | from waeup.kofa.accesscodes import create_accesscode |
---|
[10922] | 25 | from waeup.kofa.students.utils import trans |
---|
[8444] | 26 | from waeup.aaue.interfaces import MessageFactory as _ |
---|
[6902] | 27 | |
---|
[8823] | 28 | class CustomStudentsUtils(NigeriaStudentsUtils): |
---|
[7151] | 29 | """A collection of customized methods. |
---|
| 30 | |
---|
| 31 | """ |
---|
| 32 | |
---|
[13348] | 33 | PORTRAIT_CHANGE_STATES = (ADMITTED, RETURNING) |
---|
| 34 | |
---|
[10641] | 35 | gpa_boundaries = ((1, 'FRNS'), |
---|
| 36 | (1.5, 'Pass'), |
---|
| 37 | (2.4, '3rd Class Honours'), |
---|
| 38 | (3.5, '2nd Class Honours Lower Division'), |
---|
| 39 | (4.5, '2nd Class Honours Upper Division'), |
---|
| 40 | (5, '1st Class Honours')) |
---|
| 41 | |
---|
[13359] | 42 | def increaseMatricInteger(self, student): |
---|
| 43 | """Increase counter for matric numbers. |
---|
| 44 | This counter can be a centrally stored attribute or an attribute of |
---|
| 45 | faculties, departments or certificates. In the base package the counter |
---|
| 46 | is as an attribute of the site configuration container. |
---|
| 47 | """ |
---|
| 48 | if student.current_mode in ('ug_pt', 'de_pt'): |
---|
| 49 | grok.getSite()['configuration'].next_matric_integer += 1 |
---|
| 50 | return |
---|
| 51 | grok.getSite()['configuration'].next_matric_integer_2 += 1 |
---|
| 52 | return |
---|
| 53 | |
---|
[11596] | 54 | def constructMatricNumber(self, student): |
---|
[11593] | 55 | faccode = student.faccode |
---|
| 56 | depcode = student.depcode |
---|
| 57 | year = unicode(student.entry_session)[2:] |
---|
[13359] | 58 | if not student.state in (PAID, ) or not student.is_fresh or \ |
---|
| 59 | student.current_mode == 'found': |
---|
| 60 | return _('Matriculation number cannot be set.'), None |
---|
| 61 | if student.current_mode in ('ug_pt', 'de_pt'): |
---|
| 62 | next_integer = grok.getSite()['configuration'].next_matric_integer |
---|
| 63 | if next_integer == 0: |
---|
| 64 | return _('Matriculation number cannot be set.'), None |
---|
[12975] | 65 | return None, "PTP/%s/%s/%s/%05d" % ( |
---|
| 66 | faccode, depcode, year, next_integer) |
---|
[13359] | 67 | next_integer = grok.getSite()['configuration'].next_matric_integer_2 |
---|
| 68 | if next_integer == 0: |
---|
| 69 | return _('Matriculation number cannot be set.'), None |
---|
| 70 | if student.faccode in ('FBM', 'FCS'): |
---|
| 71 | return None, "CMS/%s/%s/%s/%05d" % ( |
---|
| 72 | faccode, depcode, year, next_integer) |
---|
| 73 | return None, "%s/%s/%s/%05d" % (faccode, depcode, year, next_integer) |
---|
[12975] | 74 | |
---|
[8270] | 75 | def getReturningData(self, student): |
---|
| 76 | """ This method defines what happens after school fee payment |
---|
[8319] | 77 | of returning students depending on the student's senate verdict. |
---|
[8270] | 78 | """ |
---|
[8319] | 79 | prev_level = student['studycourse'].current_level |
---|
| 80 | cur_verdict = student['studycourse'].current_verdict |
---|
| 81 | if cur_verdict in ('A','B','L','M','N','Z',): |
---|
| 82 | # Successful student |
---|
| 83 | new_level = divmod(int(prev_level),100)[0]*100 + 100 |
---|
| 84 | elif cur_verdict == 'C': |
---|
| 85 | # Student on probation |
---|
| 86 | new_level = int(prev_level) + 10 |
---|
| 87 | else: |
---|
| 88 | # Student is somehow in an undefined state. |
---|
| 89 | # Level has to be set manually. |
---|
| 90 | new_level = prev_level |
---|
[8270] | 91 | new_session = student['studycourse'].current_session + 1 |
---|
| 92 | return new_session, new_level |
---|
| 93 | |
---|
[9154] | 94 | def setPaymentDetails(self, category, student, |
---|
| 95 | previous_session=None, previous_level=None): |
---|
[8600] | 96 | """Create Payment object and set the payment data of a student for |
---|
| 97 | the payment category specified. |
---|
| 98 | |
---|
| 99 | """ |
---|
[8306] | 100 | details = {} |
---|
[8600] | 101 | p_item = u'' |
---|
| 102 | amount = 0.0 |
---|
| 103 | error = u'' |
---|
[9154] | 104 | if previous_session: |
---|
| 105 | return _('Previous session payment not yet implemented.'), None |
---|
[8600] | 106 | p_session = student['studycourse'].current_session |
---|
| 107 | p_level = student['studycourse'].current_level |
---|
[9154] | 108 | p_current = True |
---|
[9527] | 109 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 110 | if academic_session == None: |
---|
[8600] | 111 | return _(u'Session configuration object is not available.'), None |
---|
[8677] | 112 | # Determine fee. |
---|
[7151] | 113 | if category == 'transfer': |
---|
[8600] | 114 | amount = academic_session.transfer_fee |
---|
[10467] | 115 | elif category == 'transcript': |
---|
| 116 | amount = academic_session.transcript_fee |
---|
[7151] | 117 | elif category == 'gown': |
---|
[8600] | 118 | amount = academic_session.gown_fee |
---|
[7151] | 119 | elif category == 'bed_allocation': |
---|
[8600] | 120 | amount = academic_session.booking_fee |
---|
[7151] | 121 | elif category == 'hostel_maintenance': |
---|
[8600] | 122 | amount = academic_session.maint_fee |
---|
[13374] | 123 | elif category == 'welfare': |
---|
| 124 | amount = academic_session.welfare_fee |
---|
| 125 | elif category == 'union': |
---|
| 126 | amount = academic_session.union_fee |
---|
| 127 | elif category == 'lapel': |
---|
| 128 | amount = academic_session.lapel_fee |
---|
| 129 | elif category == 'matric_gown': |
---|
| 130 | amount = academic_session.matric_gown_fee |
---|
| 131 | elif category == 'concessional': |
---|
| 132 | amount = academic_session.concession_fee |
---|
| 133 | elif category == 'medical': |
---|
| 134 | amount = academic_session.medical_fee |
---|
[13400] | 135 | elif category.startswith('clearance'): |
---|
[11653] | 136 | if student.faccode == 'FP': |
---|
| 137 | amount = academic_session.clearance_fee_fp |
---|
[13377] | 138 | elif student.current_mode.endswith('_pt'): |
---|
| 139 | amount = academic_session.clearance_fee_pt |
---|
| 140 | elif student.faccode in ('FBM', 'FCS'): |
---|
| 141 | amount = academic_session.clearance_fee_med |
---|
[11653] | 142 | else: |
---|
| 143 | amount = academic_session.clearance_fee |
---|
[8753] | 144 | p_item = student['studycourse'].certificate.code |
---|
[13400] | 145 | # Add Matric Gown Fee and Lapel Fee |
---|
| 146 | if category == 'clearance_incl': |
---|
| 147 | if amount is None: |
---|
| 148 | # Otherwise we can't add somtehing |
---|
| 149 | amount = 0.0 |
---|
| 150 | amount += academic_session.matric_gown_fee + academic_session.lapel_fee |
---|
[11004] | 151 | elif category == 'late_registration': |
---|
[13035] | 152 | amount = academic_session.late_registration_fee |
---|
[13400] | 153 | elif category.startswith('schoolfee'): |
---|
[8600] | 154 | try: |
---|
[8753] | 155 | certificate = student['studycourse'].certificate |
---|
| 156 | p_item = certificate.code |
---|
[8600] | 157 | except (AttributeError, TypeError): |
---|
| 158 | return _('Study course data are incomplete.'), None |
---|
[8753] | 159 | if student.state == CLEARED: |
---|
[13374] | 160 | if student.is_foreigner: |
---|
| 161 | amount = getattr(certificate, 'school_fee_3', 0.0) |
---|
[10930] | 162 | else: |
---|
[13374] | 163 | amount = getattr(certificate, 'school_fee_1', 0.0) |
---|
| 164 | elif student.state == RETURNING: |
---|
| 165 | # In case of returning school fee payment the payment session |
---|
| 166 | # and level contain the values of the session the student |
---|
| 167 | # has paid for. |
---|
| 168 | p_session, p_level = self.getReturningData(student) |
---|
[8961] | 169 | try: |
---|
| 170 | academic_session = grok.getSite()[ |
---|
| 171 | 'configuration'][str(p_session)] |
---|
| 172 | except KeyError: |
---|
| 173 | return _(u'Session configuration object is not available.'), None |
---|
[13374] | 174 | if student.is_foreigner: |
---|
| 175 | amount = getattr(certificate, 'school_fee_4', 0.0) |
---|
| 176 | else: |
---|
| 177 | amount = getattr(certificate, 'school_fee_2', 0.0) |
---|
[8600] | 178 | else: |
---|
[8753] | 179 | return _('Wrong state.'), None |
---|
[13400] | 180 | # Add Student Union Fee and Welfare Assurance |
---|
| 181 | if category == 'schoolfee_incl': |
---|
| 182 | if amount is None: |
---|
| 183 | # Otherwise we can't add somtehing |
---|
| 184 | amount = 0.0 |
---|
| 185 | amount += academic_session.welfare_fee + academic_session.union_fee |
---|
[8600] | 186 | if amount in (0.0, None): |
---|
| 187 | return _(u'Amount could not be determined.'), None |
---|
[8677] | 188 | # Add session specific penalty fee. |
---|
[9905] | 189 | if category == 'schoolfee' and student.is_postgrad: |
---|
[8677] | 190 | amount += academic_session.penalty_pg |
---|
[9905] | 191 | elif category == 'schoolfee': |
---|
[8677] | 192 | amount += academic_session.penalty_ug |
---|
| 193 | # Create ticket. |
---|
[8600] | 194 | for key in student['payments'].keys(): |
---|
| 195 | ticket = student['payments'][key] |
---|
| 196 | if ticket.p_state == 'paid' and\ |
---|
| 197 | ticket.p_category == category and \ |
---|
| 198 | ticket.p_item == p_item and \ |
---|
| 199 | ticket.p_session == p_session: |
---|
| 200 | return _('This type of payment has already been made.'), None |
---|
[11455] | 201 | if self._isPaymentDisabled(p_session, category, student): |
---|
| 202 | return _('Payment temporarily disabled.'), None |
---|
[8712] | 203 | payment = createObject(u'waeup.StudentOnlinePayment') |
---|
[8954] | 204 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
[8600] | 205 | payment.p_id = "p%s" % timestamp |
---|
| 206 | payment.p_category = category |
---|
| 207 | payment.p_item = p_item |
---|
| 208 | payment.p_session = p_session |
---|
| 209 | payment.p_level = p_level |
---|
[9154] | 210 | payment.p_current = p_current |
---|
[8600] | 211 | payment.amount_auth = amount |
---|
| 212 | return None, payment |
---|
[7621] | 213 | |
---|
[10922] | 214 | def _admissionText(self, student, portal_language): |
---|
| 215 | inst_name = grok.getSite()['configuration'].name |
---|
| 216 | entry_session = student['studycourse'].entry_session |
---|
| 217 | entry_session = academic_sessions_vocab.getTerm(entry_session).title |
---|
| 218 | text = trans(_( |
---|
[10953] | 219 | 'This is to inform you that you have been offered provisional' |
---|
| 220 | ' admission into ${a} for the ${b} academic session as follows:', |
---|
[10922] | 221 | mapping = {'a': inst_name, 'b': entry_session}), |
---|
| 222 | portal_language) |
---|
| 223 | return text |
---|
| 224 | |
---|
[10051] | 225 | def maxCredits(self, studylevel): |
---|
| 226 | """Return maximum credits. |
---|
| 227 | |
---|
| 228 | """ |
---|
| 229 | return 48 |
---|
| 230 | |
---|
[13353] | 231 | def getBedCoordinates(self, bedticket): |
---|
| 232 | """Return descriptive bed coordinates. |
---|
| 233 | This method can be used to customize the `display_coordinates` |
---|
| 234 | property method in order to display a |
---|
| 235 | customary description of the bed space. |
---|
| 236 | """ |
---|
| 237 | bc = bedticket.bed_coordinates.split(',') |
---|
| 238 | if len(bc) == 4: |
---|
| 239 | return bc[0] |
---|
| 240 | return bedticket.bed_coordinates |
---|
| 241 | |
---|
[8444] | 242 | # AAUE prefix |
---|
| 243 | STUDENT_ID_PREFIX = u'E' |
---|