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