source: main/waeup.fceokene/trunk/src/waeup/fceokene/students/utils.py @ 10010

Last change on this file since 10010 was 10010, checked in by Henrik Bettermann, 12 years ago

Show correct warning.

  • Property svn:keywords set to Id
File size: 13.4 KB
Line 
1## $Id: utils.py 10010 2013-03-04 07:11:50Z 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
19import random
20from time import time
21from zope.component import createObject, getUtility
22from waeup.kofa.interfaces import CLEARED, RETURNING, PAID
23from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
24from waeup.kofa.accesscodes import create_accesscode
25from waeup.kofa.interfaces import CLEARED, RETURNING
26from waeup.fceokene.interfaces import MessageFactory as _
27from waeup.kofa.browser.interfaces import IPDFCreator
28from waeup.kofa.students.utils import trans
29
30class CustomStudentsUtils(NigeriaStudentsUtils):
31    """A collection of customized methods.
32
33    """
34
35    def selectBed(self, available_beds):
36        """Randomly select a bed from a list of available beds.
37
38        """
39        return random.choice(available_beds)
40
41    def getReturningData(self, student):
42        """ This method defines what happens after school fee payment
43        of returning students depending on the student's senate verdict.
44        """
45        prev_level = student['studycourse'].current_level
46        cur_verdict = student['studycourse'].current_verdict
47        if cur_verdict in ('A','B','L','M','N','Z',):
48            # Successful student
49            new_level = divmod(int(prev_level),100)[0]*100 + 100
50        elif cur_verdict in ('C','O'):
51            # Student on probation
52            new_level = int(prev_level) + 10
53        else:
54            # Student is somehow in an undefined state.
55            # Level has to be set manually.
56            new_level = prev_level
57        if cur_verdict == 'O':
58            new_session = student['studycourse'].current_session
59        else:
60            new_session = student['studycourse'].current_session + 1
61        return new_session, new_level
62
63    def setPaymentDetails(self, category, student,
64            previous_session=None, previous_level=None):
65        """Create Payment object and set the payment data of a student for
66        the payment category specified.
67
68        """
69        details = {}
70        p_item = u''
71        amount = 0.0
72        error = u''
73        if previous_session:
74            return _('Previous session payment not yet implemented.'), None
75        p_session = student['studycourse'].current_session
76        p_level = student['studycourse'].current_level
77        p_current = True
78        academic_session = self._getSessionConfiguration(p_session)
79        if academic_session == None:
80            return _(u'Session configuration object is not available.'), None
81        # Determine fee.
82        if category == 'transfer':
83            amount = academic_session.transfer_fee
84        elif category == 'gown':
85            amount = academic_session.gown_fee
86        elif category == 'bed_allocation':
87            amount = academic_session.booking_fee
88        elif category == 'hostel_maintenance':
89            current_session = student['studycourse'].current_session
90            bedticket = student['accommodation'].get(str(current_session), None)
91            if bedticket is not None and bedticket.bed is not None:
92                p_item = bedticket.bed_coordinates
93            else:
94                return _(u'You have not yet booked accommodation.'), None
95            acc_details = self.getAccommodationDetails(student)
96            if current_session != acc_details['booking_session']:
97                return _(u'Current session does not match accommodation session.'), None
98            if student.current_mode.endswith('_sw') or student.current_mode == 'pd_ft':
99                amount = 2650.0
100            else:
101                amount = 4150.0
102        elif category == 'clearance':
103            amount = academic_session.clearance_fee
104            try:
105                p_item = student['studycourse'].certificate.code
106            except (AttributeError, TypeError):
107                return _('Study course data are incomplete.'), None
108        elif category == 'schoolfee':
109            try:
110                certificate = student['studycourse'].certificate
111                p_item = certificate.code
112            except (AttributeError, TypeError):
113                return _('Study course data are incomplete.'), None
114
115            # Very special school fee configuration, should be moved to
116            # a seperate file.
117
118            ARTS = ('CRS','ISS','HIS','MUS','ECO','GEO','POL','SOS','CCA','ECU',
119                    'THA','GED','GSE','PES','SPC','ENG','FRE','ARB','HAU','IGB',
120                    'YOR','NCRS','NISS','NHIS','NMUS','NECO','NGEO','NPOL',
121                    'NCCA','NECU','NTHA','NGED','NGSE','NPES','NSPC','NENG',
122                    'NFRE','NARB','NHAU','NIGB','NYOR','NSOS')
123
124            #PDE
125            if student.current_mode == 'pd_ft':
126                amount = 35000
127            # NCE/UG
128            elif not student.current_mode.endswith('_sw'):
129                # PRENCE
130                if student.current_level == 10 and student.state == CLEARED:
131                    if student.depcode in ARTS:
132                        amount = 14900
133                    else:
134                        amount = 15400
135                # NCE/UG I fresh
136                elif student.current_level == 100 and student.state == CLEARED:
137                    if student.depcode in ARTS:
138                        amount = 12020
139                    else:
140                        amount = 12495
141                # NCE/UG II
142                elif student.current_level in (100, 110, 120) and \
143                    student.state == RETURNING:
144                    if student.depcode in ARTS:
145                        amount = 11070
146                    else:
147                        amount = 11545
148                # NCE/UG III
149                elif student.current_level in (200, 210, 220):
150                    if student.depcode in ARTS:
151                        amount = 11070
152                    else:
153                        amount = 11545
154                # NCE/UG III repeater
155                elif student.current_level in (300, 310, 320) and \
156                    student.current_verdict == 'O':
157                    if student.depcode in ARTS:
158                        amount = 6535
159                    else:
160                        amount = 6773
161                # NCE/UG III spillover
162                elif student.current_level in (300, 310, 320) and \
163                    student.current_verdict == 'B':
164                    if student.depcode in ARTS:
165                        amount = 9170
166                    else:
167                        amount = 9645
168                # NCE/UG III second spillover
169                elif student.current_level in (400, 410, 420) and \
170                    student.current_verdict == 'B':
171                    if student.depcode in ARTS:
172                        amount = 9170
173                    else:
174                        amount = 9645
175            else:
176                if student.current_level == 100 and student.state == CLEARED:
177                    if student.depcode in ARTS:
178                        amount = 21900
179                    else:
180                        amount = 22400
181                # NCE/UG II sw
182                elif student.current_level in (100, 110, 120) and \
183                    student.state == RETURNING:
184                    if student.depcode in ARTS:
185                        amount = 18400
186                    else:
187                        amount = 18900
188                # NCE/UG III sw
189                elif student.current_level in (200, 210, 220):
190                    if student.depcode in ARTS:
191                        amount = 20400
192                    else:
193                        amount = 20900
194                # NCE/UG IV sw
195                elif student.current_level in (300, 310, 320):
196                    if student.depcode in ARTS:
197                        amount = 18400
198                    else:
199                        amount = 18900
200                # NCE/UG V sw
201                elif student.current_level in (400, 410, 420):
202                    if student.depcode in ARTS:
203                        amount = 18400
204                    else:
205                        amount = 18900
206                # NCE/UG V spillover sw
207                elif student.current_level in (500, 510, 520) and \
208                    student.current_verdict == 'B':
209                    if student.depcode in ARTS:
210                        amount = 16900
211                    else:
212                        amount = 17400
213                # NCE/UG V second spillover sw
214                elif student.current_level in (600, 610, 620) and \
215                    student.current_verdict == 'B':
216                    if student.depcode in ARTS:
217                        amount = 16900
218                    else:
219                        amount = 17400
220            # NCE student payment can be disabled by
221            # setting the base school fee to -1
222            if academic_session.school_fee_base == -1 and \
223                student.current_mode.startswith('nce'):
224                return _(u'School fee payment is disabled.'), None
225            if student.state == RETURNING:
226                # Override p_session and p_level
227                p_session, p_level = self.getReturningData(student)
228                academic_session = self._getSessionConfiguration(p_session)
229                if academic_session == None:
230                    return _(u'Session configuration object is not available.'), None
231
232        if amount in (0.0, None):
233            return _(u'Amount could not be determined.'), None
234        for key in student['payments'].keys():
235            ticket = student['payments'][key]
236            if ticket.p_state == 'paid' and\
237               ticket.p_category == category and \
238               ticket.p_item == p_item and \
239               ticket.p_session == p_session:
240                  return _('This type of payment has already been made.'), None
241        payment = createObject(u'waeup.StudentOnlinePayment')
242        timestamp = ("%d" % int(time()*10000))[1:]
243        payment.p_id = "p%s" % timestamp
244        payment.p_category = category
245        payment.p_item = p_item
246        payment.p_session = p_session
247        payment.p_level = p_level
248        payment.p_current = p_current
249        payment.amount_auth = float(amount)
250        return None, payment
251
252    def getAccommodationDetails(self, student):
253        """Determine the accommodation data of a student.
254        """
255        d = {}
256        d['error'] = u''
257        hostels = grok.getSite()['hostels']
258        d['booking_session'] = hostels.accommodation_session
259        d['allowed_states'] = hostels.accommodation_states
260        d['startdate'] = hostels.startdate
261        d['enddate'] = hostels.enddate
262        d['expired'] = hostels.expired
263        # Determine bed type
264        studycourse = student['studycourse']
265        certificate = getattr(studycourse,'certificate',None)
266        current_level = studycourse.current_level
267        if None in (current_level, certificate):
268            return d
269        end_level = certificate.end_level
270        if current_level == 10:
271            bt = 'pr'
272        elif current_level == 100:
273            bt = 'fr'
274        elif current_level >= 300:
275            bt = 'fi'
276        else:
277            bt = 're'
278        if student.sex == 'f':
279            sex = 'female'
280        else:
281            sex = 'male'
282        special_handling = 'regular'
283        d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt)
284        return d
285
286    def maxCredits(self, studylevel):
287        """Return maximum credits.
288
289        """
290        return 58
291
292    def getPDFCreator(self, context):
293        """Get a pdf creator suitable for `context`.
294
295        The default implementation always returns the default creator.
296        """
297        mode = getattr(context, 'current_mode', None)
298        if mode and mode.startswith('ug'):
299            return getUtility(IPDFCreator, name='ibadan_pdfcreator')
300        return getUtility(IPDFCreator)
301
302    def _admissionText(self, student, portal_language):
303        mode = getattr(student, 'current_mode', None)
304        if mode and mode.startswith('ug'):
305            text = trans(_(
306                'With reference to your application for admission into Bachelor Degree '
307                'Programme of the University of Ibadan, this is to inform you that you have '
308                'been provisionally admitted to pursue a full-time Bachelor of Arts in '
309                'Education Degree Programme as follows:'),
310                portal_language)
311        else:
312            inst_name = grok.getSite()['configuration'].name
313            text = trans(_(
314                'This is to inform you that you have been provisionally'
315                ' admitted into ${a} as follows:', mapping = {'a': inst_name}),
316                portal_language)
317        return text
318
319    def getBedCoordinates(self, bedticket):
320        """Return bed coordinates.
321
322        Bed coordinates are invisible in FCEOkene.
323        """
324        return _('(see payment slip)')
325
326    # FCEOkene prefix
327    STUDENT_ID_PREFIX = u'K'
Note: See TracBrowser for help on using the repository browser.