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