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