[7419] | 1 | ## $Id: utils.py 13035 2015-06-05 08:25: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 | ## |
---|
[7151] | 18 | import grok |
---|
[8600] | 19 | from time import time |
---|
| 20 | from zope.component import createObject |
---|
[10922] | 21 | from waeup.kofa.interfaces import ( |
---|
| 22 | 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 | |
---|
[10656] | 33 | VERDICTS_DICT = { |
---|
| 34 | '0': 'not yet', |
---|
| 35 | 'A': 'Successful student', |
---|
| 36 | 'B': 'Student with carryover courses', |
---|
| 37 | 'C': 'Student on probation', |
---|
| 38 | #'D': 'Withdrawn from the faculty', |
---|
| 39 | #'E': 'Student who were previously on probation', |
---|
| 40 | #'F': 'Medical case', |
---|
| 41 | #'G': 'Absent from examination', |
---|
| 42 | #'H': 'Withheld results', |
---|
| 43 | #'I': 'Expelled/rusticated/suspended student', |
---|
| 44 | #'J': 'Temporary withdrawn from the university', |
---|
| 45 | #'K': 'Unregistered student', |
---|
| 46 | #'L': 'Referred student', |
---|
| 47 | #'M': 'Reinstatement', |
---|
| 48 | #'N': 'Student on transfer', |
---|
| 49 | #'O': 'NCE-III repeater', |
---|
| 50 | #'Y': 'No previous verdict', |
---|
| 51 | #'X': 'New 300 level student', |
---|
| 52 | 'Z': 'Successful student (provisional)', |
---|
| 53 | #'A1': 'First Class', |
---|
| 54 | #'A2': 'Second Class Upper', |
---|
| 55 | #'A3': 'Second Class Lower', |
---|
| 56 | #'A4': 'Third Class', |
---|
| 57 | #'A5': 'Pass', |
---|
| 58 | #'A6': 'Distinction', |
---|
| 59 | #'A7': 'Credit', |
---|
| 60 | #'A8': 'Merit', |
---|
| 61 | 'NEOR': 'No evidence of registration', |
---|
| 62 | 'NEOV': 'No evidence of verification', |
---|
| 63 | 'FRNS': 'Faculty requirements not satisfied', |
---|
| 64 | } |
---|
| 65 | |
---|
[10641] | 66 | gpa_boundaries = ((1, 'FRNS'), |
---|
| 67 | (1.5, 'Pass'), |
---|
| 68 | (2.4, '3rd Class Honours'), |
---|
| 69 | (3.5, '2nd Class Honours Lower Division'), |
---|
| 70 | (4.5, '2nd Class Honours Upper Division'), |
---|
| 71 | (5, '1st Class Honours')) |
---|
| 72 | |
---|
[11596] | 73 | def constructMatricNumber(self, student): |
---|
| 74 | next_integer = grok.getSite()['configuration'].next_matric_integer |
---|
| 75 | if next_integer == 0: |
---|
| 76 | return None |
---|
[11593] | 77 | faccode = student.faccode |
---|
| 78 | depcode = student.depcode |
---|
| 79 | year = unicode(student.entry_session)[2:] |
---|
[11605] | 80 | if student.current_mode in ('ug_pt', 'de_pt') \ |
---|
| 81 | and student.state in (PAID, ) \ |
---|
| 82 | and student.is_fresh: |
---|
[12975] | 83 | return None, "PTP/%s/%s/%s/%05d" % ( |
---|
| 84 | faccode, depcode, year, next_integer) |
---|
| 85 | |
---|
[11596] | 86 | #if student.current_mode in ('pg_ft', 'pg_pt'): |
---|
[12975] | 87 | # return None, "SPS/%s/%s/%s/%05d" % ( |
---|
| 88 | # faccode, depcode, year, next_integer) |
---|
[11596] | 89 | #if student.current_mode in ('dp_ft', 'dp_pt'): |
---|
[12975] | 90 | # return None, "DIP/%s/%s/%s/%05d" % ( |
---|
| 91 | # faccode, depcode, year, next_integer) |
---|
[11596] | 92 | #if student.current_mode == 'found': |
---|
[12975] | 93 | # return _( |
---|
| 94 | # 'Foundation programme students don\'t have matric number.'), None |
---|
[11620] | 95 | #return None, "%s/%s/%s/%05d" % (faccode, depcode, year, next_integer) |
---|
[12975] | 96 | |
---|
[11620] | 97 | return _('Matriculation number cannot be set.'), None |
---|
[11593] | 98 | |
---|
[8270] | 99 | def getReturningData(self, student): |
---|
| 100 | """ This method defines what happens after school fee payment |
---|
[8319] | 101 | of returning students depending on the student's senate verdict. |
---|
[8270] | 102 | """ |
---|
[8319] | 103 | prev_level = student['studycourse'].current_level |
---|
| 104 | cur_verdict = student['studycourse'].current_verdict |
---|
| 105 | if cur_verdict in ('A','B','L','M','N','Z',): |
---|
| 106 | # Successful student |
---|
| 107 | new_level = divmod(int(prev_level),100)[0]*100 + 100 |
---|
| 108 | elif cur_verdict == 'C': |
---|
| 109 | # Student on probation |
---|
| 110 | new_level = int(prev_level) + 10 |
---|
| 111 | else: |
---|
| 112 | # Student is somehow in an undefined state. |
---|
| 113 | # Level has to be set manually. |
---|
| 114 | new_level = prev_level |
---|
[8270] | 115 | new_session = student['studycourse'].current_session + 1 |
---|
| 116 | return new_session, new_level |
---|
| 117 | |
---|
[9154] | 118 | def setPaymentDetails(self, category, student, |
---|
| 119 | previous_session=None, previous_level=None): |
---|
[8600] | 120 | """Create Payment object and set the payment data of a student for |
---|
| 121 | the payment category specified. |
---|
| 122 | |
---|
| 123 | """ |
---|
[8306] | 124 | details = {} |
---|
[8600] | 125 | p_item = u'' |
---|
| 126 | amount = 0.0 |
---|
| 127 | error = u'' |
---|
[9154] | 128 | if previous_session: |
---|
| 129 | return _('Previous session payment not yet implemented.'), None |
---|
[8600] | 130 | p_session = student['studycourse'].current_session |
---|
| 131 | p_level = student['studycourse'].current_level |
---|
[9154] | 132 | p_current = True |
---|
[9527] | 133 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 134 | if academic_session == None: |
---|
[8600] | 135 | return _(u'Session configuration object is not available.'), None |
---|
[8677] | 136 | # Determine fee. |
---|
[7151] | 137 | if category == 'transfer': |
---|
[8600] | 138 | amount = academic_session.transfer_fee |
---|
[10467] | 139 | elif category == 'transcript': |
---|
| 140 | amount = academic_session.transcript_fee |
---|
[7151] | 141 | elif category == 'gown': |
---|
[8600] | 142 | amount = academic_session.gown_fee |
---|
[7151] | 143 | elif category == 'bed_allocation': |
---|
[8600] | 144 | amount = academic_session.booking_fee |
---|
[7151] | 145 | elif category == 'hostel_maintenance': |
---|
[8600] | 146 | amount = academic_session.maint_fee |
---|
[7151] | 147 | elif category == 'clearance': |
---|
[11653] | 148 | if student.faccode == 'FP': |
---|
| 149 | amount = academic_session.clearance_fee_fp |
---|
| 150 | else: |
---|
| 151 | amount = academic_session.clearance_fee |
---|
[8753] | 152 | p_item = student['studycourse'].certificate.code |
---|
[11004] | 153 | elif category == 'late_registration': |
---|
[13035] | 154 | amount = academic_session.late_registration_fee |
---|
[9905] | 155 | elif category == 'schoolfee': |
---|
[8600] | 156 | try: |
---|
[8753] | 157 | certificate = student['studycourse'].certificate |
---|
| 158 | p_item = certificate.code |
---|
[8600] | 159 | except (AttributeError, TypeError): |
---|
| 160 | return _('Study course data are incomplete.'), None |
---|
[8753] | 161 | if student.state == CLEARED: |
---|
[10922] | 162 | if student.faccode == 'FP': |
---|
[11653] | 163 | amount = academic_session.school_fee_3 |
---|
[10930] | 164 | else: |
---|
[11624] | 165 | amount = academic_session.school_fee_1 |
---|
[8961] | 166 | elif student.state == RETURNING or\ |
---|
| 167 | (student.is_postgrad and student.state == PAID): |
---|
[9527] | 168 | academic_session = self._getSessionConfiguration(p_session) |
---|
| 169 | if academic_session == None: |
---|
| 170 | return _(u'Session configuration object is not available.'), None |
---|
[8961] | 171 | if student.state == RETURNING: |
---|
| 172 | p_session, p_level = self.getReturningData(student) |
---|
| 173 | else: |
---|
| 174 | # Returning postgraduate students also pay for the |
---|
| 175 | # next session but their level always remains the same. |
---|
| 176 | p_session += 1 |
---|
| 177 | try: |
---|
| 178 | academic_session = grok.getSite()[ |
---|
| 179 | 'configuration'][str(p_session)] |
---|
| 180 | except KeyError: |
---|
| 181 | return _(u'Session configuration object is not available.'), None |
---|
[11624] | 182 | amount = academic_session.school_fee_2 |
---|
[8600] | 183 | else: |
---|
[8753] | 184 | return _('Wrong state.'), None |
---|
[8600] | 185 | if amount in (0.0, None): |
---|
| 186 | return _(u'Amount could not be determined.'), None |
---|
[8677] | 187 | # Add session specific penalty fee. |
---|
[9905] | 188 | if category == 'schoolfee' and student.is_postgrad: |
---|
[8677] | 189 | amount += academic_session.penalty_pg |
---|
[9905] | 190 | elif category == 'schoolfee': |
---|
[8677] | 191 | amount += academic_session.penalty_ug |
---|
| 192 | # Create ticket. |
---|
[8600] | 193 | for key in student['payments'].keys(): |
---|
| 194 | ticket = student['payments'][key] |
---|
| 195 | if ticket.p_state == 'paid' and\ |
---|
| 196 | ticket.p_category == category and \ |
---|
| 197 | ticket.p_item == p_item and \ |
---|
| 198 | ticket.p_session == p_session: |
---|
| 199 | return _('This type of payment has already been made.'), None |
---|
[11455] | 200 | if self._isPaymentDisabled(p_session, category, student): |
---|
| 201 | return _('Payment temporarily disabled.'), None |
---|
[8712] | 202 | payment = createObject(u'waeup.StudentOnlinePayment') |
---|
[8954] | 203 | timestamp = ("%d" % int(time()*10000))[1:] |
---|
[8600] | 204 | payment.p_id = "p%s" % timestamp |
---|
| 205 | payment.p_category = category |
---|
| 206 | payment.p_item = p_item |
---|
| 207 | payment.p_session = p_session |
---|
| 208 | payment.p_level = p_level |
---|
[9154] | 209 | payment.p_current = p_current |
---|
[8600] | 210 | payment.amount_auth = amount |
---|
| 211 | return None, payment |
---|
[7621] | 212 | |
---|
[10922] | 213 | def _admissionText(self, student, portal_language): |
---|
| 214 | inst_name = grok.getSite()['configuration'].name |
---|
| 215 | entry_session = student['studycourse'].entry_session |
---|
| 216 | entry_session = academic_sessions_vocab.getTerm(entry_session).title |
---|
| 217 | text = trans(_( |
---|
[10953] | 218 | 'This is to inform you that you have been offered provisional' |
---|
| 219 | ' admission into ${a} for the ${b} academic session as follows:', |
---|
[10922] | 220 | mapping = {'a': inst_name, 'b': entry_session}), |
---|
| 221 | portal_language) |
---|
| 222 | return text |
---|
| 223 | |
---|
[10051] | 224 | def maxCredits(self, studylevel): |
---|
| 225 | """Return maximum credits. |
---|
| 226 | |
---|
| 227 | """ |
---|
| 228 | return 48 |
---|
| 229 | |
---|
[8444] | 230 | # AAUE prefix |
---|
| 231 | STUDENT_ID_PREFIX = u'E' |
---|