[7419] | 1 | ## $Id: utils.py 8413 2012-05-10 19:35:55Z 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 |
---|
[8306] | 19 | from waeup.kofa.interfaces import CLEARED, RETURNING |
---|
[7822] | 20 | from waeup.kofa.students.utils import StudentsUtils |
---|
| 21 | from waeup.kofa.students.interfaces import IStudentsUtils |
---|
[8247] | 22 | from waeup.kofa.accesscodes import create_accesscode |
---|
[8020] | 23 | from waeup.uniben.interfaces import MessageFactory as _ |
---|
[6902] | 24 | |
---|
[8263] | 25 | def get_school_fee(student): |
---|
[7152] | 26 | state = student.state |
---|
[8306] | 27 | fee = None |
---|
| 28 | if state == CLEARED: |
---|
| 29 | fee = getattr(student['studycourse'].certificate,'school_fee_1') |
---|
| 30 | elif state == RETURNING: |
---|
| 31 | fee = getattr(student['studycourse'].certificate,'school_fee_2') |
---|
| 32 | if fee is not None: |
---|
| 33 | return fee |
---|
| 34 | return 0.0 |
---|
[7152] | 35 | |
---|
[8247] | 36 | def actions_after_student_payment(student, payment, view): |
---|
| 37 | if payment.p_category == 'clearance': |
---|
| 38 | # Create CLR access code |
---|
| 39 | pin, error = create_accesscode('CLR',0,student.student_id) |
---|
| 40 | if error: |
---|
| 41 | view.flash(_('Valid callback received. ${a}', |
---|
| 42 | mapping = {'a':error})) |
---|
| 43 | return |
---|
| 44 | payment.ac = pin |
---|
| 45 | elif payment.p_category == 'schoolfee': |
---|
| 46 | # Create SFE access code |
---|
| 47 | pin, error = create_accesscode('SFE',0,student.student_id) |
---|
| 48 | if error: |
---|
| 49 | view.flash(_('Valid callback received. ${a}', |
---|
| 50 | mapping = {'a':error})) |
---|
| 51 | return |
---|
| 52 | payment.ac = pin |
---|
| 53 | elif payment.p_category == 'bed_allocation': |
---|
| 54 | # Create HOS access code |
---|
| 55 | pin, error = create_accesscode('HOS',0,student.student_id) |
---|
| 56 | if error: |
---|
| 57 | view.flash(_('Valid callback received. ${a}', |
---|
| 58 | mapping = {'a':error})) |
---|
| 59 | return |
---|
| 60 | payment.ac = pin |
---|
| 61 | view.flash(_('Valid callback received.')) |
---|
| 62 | return |
---|
| 63 | |
---|
[8204] | 64 | class CustomStudentsUtils(StudentsUtils): |
---|
[7151] | 65 | """A collection of customized methods. |
---|
| 66 | |
---|
| 67 | """ |
---|
| 68 | grok.implements(IStudentsUtils) |
---|
| 69 | |
---|
[8270] | 70 | def getReturningData(self, student): |
---|
| 71 | """ This method defines what happens after school fee payment |
---|
[8319] | 72 | of returning students depending on the student's senate verdict. |
---|
[8270] | 73 | """ |
---|
[8319] | 74 | prev_level = student['studycourse'].current_level |
---|
| 75 | cur_verdict = student['studycourse'].current_verdict |
---|
| 76 | if cur_verdict in ('A','B','L','M','N','Z',): |
---|
| 77 | # Successful student |
---|
| 78 | new_level = divmod(int(prev_level),100)[0]*100 + 100 |
---|
| 79 | elif cur_verdict == 'C': |
---|
| 80 | # Student on probation |
---|
| 81 | new_level = int(prev_level) + 10 |
---|
| 82 | else: |
---|
| 83 | # Student is somehow in an undefined state. |
---|
| 84 | # Level has to be set manually. |
---|
| 85 | new_level = prev_level |
---|
[8270] | 86 | new_session = student['studycourse'].current_session + 1 |
---|
| 87 | return new_session, new_level |
---|
| 88 | |
---|
[7419] | 89 | def getPaymentDetails(self, category, student): |
---|
[8306] | 90 | details = {} |
---|
| 91 | details['p_item'] = u'' |
---|
| 92 | details['amount'] = 0.0 |
---|
| 93 | details['error'] = u'' |
---|
| 94 | details['p_session'] = student['studycourse'].current_session |
---|
| 95 | session = str(details['p_session']) |
---|
| 96 | details['p_level'] = student['studycourse'].current_level |
---|
[7151] | 97 | try: |
---|
| 98 | academic_session = grok.getSite()['configuration'][session] |
---|
| 99 | except KeyError: |
---|
[8306] | 100 | details['error'] = _(u'Session configuration object is not available.') |
---|
| 101 | return details |
---|
[7151] | 102 | if category == 'transfer': |
---|
[8306] | 103 | details['amount'] = academic_session.transfer_fee |
---|
[7151] | 104 | elif category == 'gown': |
---|
[8306] | 105 | details['amount'] = academic_session.gown_fee |
---|
[7151] | 106 | elif category == 'bed_allocation': |
---|
[8306] | 107 | details['amount'] = academic_session.booking_fee |
---|
[7151] | 108 | elif category == 'hostel_maintenance': |
---|
[8306] | 109 | details['amount'] = academic_session.maint_fee |
---|
[7151] | 110 | elif category == 'clearance': |
---|
[8306] | 111 | details['p_item'] = student['studycourse'].certificate.code |
---|
| 112 | if details['p_item'] in ('BEDCET', 'BIOEDCET', 'CHMEDCET', 'ISEDCET', |
---|
[8294] | 113 | 'MTHEDCET', 'PHYEDCET', 'ITECET', 'AGREDCET', 'HEEDCET'): |
---|
[8306] | 114 | details['amount'] = 17250.0 |
---|
[8294] | 115 | else: |
---|
[8306] | 116 | details['amount'] = 34250.0 |
---|
[7151] | 117 | elif category == 'schoolfee': |
---|
[8306] | 118 | details['amount'] = get_school_fee(student) |
---|
[7151] | 119 | code = student['studycourse'].certificate.code |
---|
[8306] | 120 | details['p_item'] = code |
---|
| 121 | if student.state == RETURNING: |
---|
| 122 | # In case of returning school fee payment the payment session |
---|
| 123 | # and level contain the values of the session the student |
---|
| 124 | # has paid for. |
---|
| 125 | details['p_session'], details['p_level'] = self.getReturningData(student) |
---|
| 126 | if details['amount'] == 0.0: |
---|
| 127 | details['error'] = _(u'Amount could not be determined.') |
---|
| 128 | return details |
---|
[7621] | 129 | |
---|
[7845] | 130 | VERDICTS_DICT = { |
---|
| 131 | '0': 'not yet', |
---|
| 132 | 'A': 'Successful student', |
---|
| 133 | 'B': 'Student with carryover courses', |
---|
| 134 | 'C': 'Student on probation', |
---|
| 135 | 'D': 'Withdrawn from the faculty', |
---|
| 136 | 'E': 'Student who were previously on probation', |
---|
| 137 | 'F': 'Medical case', |
---|
| 138 | 'G': 'Absent from examination', |
---|
| 139 | 'H': 'Withheld results', |
---|
| 140 | 'I': 'Expelled/rusticated/suspended student', |
---|
| 141 | 'J': 'Temporary withdrawn from the university', |
---|
| 142 | 'K': 'Unregistered student', |
---|
| 143 | 'L': 'Referred student', |
---|
| 144 | 'M': 'Reinstatement', |
---|
| 145 | 'N': 'Student on transfer', |
---|
| 146 | 'O': 'NCE-III repeater', |
---|
| 147 | 'Y': 'No previous verdict', |
---|
| 148 | 'X': 'New 300 level student', |
---|
| 149 | 'Z': 'Successful student (provisional)', |
---|
| 150 | 'A1': 'First Class', |
---|
| 151 | 'A2': 'Second Class Upper', |
---|
| 152 | 'A3': 'Second Class Lower', |
---|
| 153 | 'A4': 'Third Class', |
---|
| 154 | 'A5': 'Pass', |
---|
| 155 | 'A6': 'Distinction', |
---|
| 156 | 'A7': 'Credit', |
---|
| 157 | 'A8': 'Merit', |
---|
| 158 | } |
---|
[8101] | 159 | |
---|
| 160 | SEPARATORS_DICT = { |
---|
[8265] | 161 | 'form.fst_sit_fname': _(u'First Sitting Record'), |
---|
[8101] | 162 | 'form.scd_sit_fname': _(u'Second Sitting Record'), |
---|
| 163 | 'form.alr_fname': _(u'Advanced Level Record'), |
---|
| 164 | 'form.hq_type': _(u'Higher Education Record'), |
---|
| 165 | 'form.hq2_type': _(u'Second Higher Education Record'), |
---|
| 166 | 'form.nysc_year': _(u'NYSC Information'), |
---|
| 167 | 'form.employer': _(u'Employment History'), |
---|
[8136] | 168 | 'form.uniben_matric': _(u'Former Uniben Student'), |
---|
[8413] | 169 | } |
---|
| 170 | |
---|
| 171 | STUDENT_ID_PREFIX = u'B' |
---|