source: main/waeup.uniben/trunk/src/waeup/uniben/students/utils.py @ 8416

Last change on this file since 8416 was 8413, checked in by Henrik Bettermann, 13 years ago

STUDENT_ID_PREFIX = u'B'

  • Property svn:keywords set to Id
File size: 6.7 KB
Line 
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##
18import grok
19from waeup.kofa.interfaces import CLEARED, RETURNING
20from waeup.kofa.students.utils import StudentsUtils
21from waeup.kofa.students.interfaces import IStudentsUtils
22from waeup.kofa.accesscodes import create_accesscode
23from waeup.uniben.interfaces import MessageFactory as _
24
25def get_school_fee(student):
26    state = student.state
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
35
36def 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
64class CustomStudentsUtils(StudentsUtils):
65    """A collection of customized methods.
66
67    """
68    grok.implements(IStudentsUtils)
69
70    def getReturningData(self, student):
71        """ This method defines what happens after school fee payment
72        of returning students depending on the student's senate verdict.
73        """
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
86        new_session = student['studycourse'].current_session + 1
87        return new_session, new_level
88
89    def getPaymentDetails(self, category, student):
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
97        try:
98            academic_session = grok.getSite()['configuration'][session]
99        except KeyError:
100            details['error'] = _(u'Session configuration object is not available.')
101            return details
102        if category == 'transfer':
103            details['amount'] = academic_session.transfer_fee
104        elif category == 'gown':
105            details['amount'] = academic_session.gown_fee
106        elif category == 'bed_allocation':
107            details['amount'] = academic_session.booking_fee
108        elif category == 'hostel_maintenance':
109            details['amount'] = academic_session.maint_fee
110        elif category == 'clearance':
111            details['p_item'] = student['studycourse'].certificate.code
112            if details['p_item'] in ('BEDCET', 'BIOEDCET', 'CHMEDCET', 'ISEDCET',
113                'MTHEDCET', 'PHYEDCET', 'ITECET', 'AGREDCET', 'HEEDCET'):
114                details['amount'] = 17250.0
115            else:
116                details['amount'] = 34250.0
117        elif category == 'schoolfee':
118            details['amount'] = get_school_fee(student)
119            code = student['studycourse'].certificate.code
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
129
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        }
159
160    SEPARATORS_DICT = {
161        'form.fst_sit_fname': _(u'First Sitting Record'),
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'),
168        'form.uniben_matric': _(u'Former Uniben Student'),
169        }
170
171    STUDENT_ID_PREFIX = u'B'
Note: See TracBrowser for help on using the repository browser.