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

Last change on this file since 17253 was 17236, checked in by Henrik Bettermann, 23 months ago

Adjust to base package.

  • Property svn:keywords set to Id
File size: 31.4 KB
Line 
1## $Id: utils.py 17236 2022-12-22 09:52:30Z 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 time import time
20from reportlab.platypus import Paragraph, Table
21from zope.component import createObject, getUtility
22from reportlab.lib.styles import getSampleStyleSheet
23from waeup.kofa.browser.pdf import ENTRY1_STYLE
24from waeup.kofa.interfaces import (IKofaUtils, ADMITTED, CLEARANCE,
25    CLEARED, REQUESTED, RETURNING, PAID, REGISTERED, VALIDATED, GRADUATED)
26from waeup.kofa.utils.helpers import to_timezone
27from waeup.kofa.students.utils import (
28    trans, render_student_data, formatted_text, render_transcript_data,
29    SLIP_STYLE)
30from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
31from waeup.uniben.interfaces import MessageFactory as _
32
33class CustomStudentsUtils(NigeriaStudentsUtils):
34    """A collection of customized methods.
35
36    """
37
38    SEPARATORS_DICT = {
39        'form.fst_sit_fname': _(u'First Sitting Record'),
40        'form.scd_sit_fname': _(u'Second Sitting Record'),
41        'form.alr_fname': _(u'Advanced Level Record'),
42        'form.hq_type': _(u'Higher Education Record'),
43        'form.hq2_type': _(u'Second Higher Education Record'),
44        'form.nysc_year': _(u'NYSC Information'),
45        'form.employer': _(u'Employment History'),
46        'form.former_matric': _(u'Former Student'),
47        'form.fever': _(u'History of Symptoms'),
48        'form.asthma': _(u'Medical History'),
49        'form.lagos_abuja': _(u'Travel History'),
50        'form.company_suspected': _(u'History of Contact/Infection'),
51        }
52
53    def getReturningData(self, student):
54        """ This method defines what happens after school fee payment
55        of returning students depending on the student's senate verdict.
56        """
57        prev_level = student['studycourse'].current_level
58        cur_verdict = student['studycourse'].current_verdict
59        if cur_verdict == 'N' and prev_level in (100, 200):
60            new_level = prev_level
61        elif cur_verdict in ('A','B','L','M','N','Z',):
62            # Successful student
63            new_level = divmod(int(prev_level),100)[0]*100 + 100
64        elif cur_verdict == 'C':
65            # Student on probation
66            new_level = int(prev_level) + 10
67        else:
68            # Student is somehow in an undefined state.
69            # Level has to be set manually.
70            new_level = prev_level
71        new_session = student['studycourse'].current_session + 1
72        return new_session, new_level
73
74
75    def checkAccommodationRequirements(self, student, acc_details):
76        if acc_details.get('expired', False):
77            startdate = acc_details.get('startdate')
78            enddate = acc_details.get('enddate')
79            if startdate and enddate:
80                tz = getUtility(IKofaUtils).tzinfo
81                startdate = to_timezone(
82                    startdate, tz).strftime("%d/%m/%Y %H:%M:%S")
83                enddate = to_timezone(
84                    enddate, tz).strftime("%d/%m/%Y %H:%M:%S")
85                return _("Outside booking period: ${a} - ${b}",
86                         mapping = {'a': startdate, 'b': enddate})
87            else:
88                return _("Outside booking period.")
89        if not student.is_postgrad and student.current_mode != 'ug_ft':
90            return _("Only undergraduate full-time students are eligible to book accommodation.")
91        bt = acc_details.get('bt')
92        if not bt:
93            return _("Your data are incomplete.")
94        if not student.state in acc_details['allowed_states']:
95            return _("You are in the wrong registration state.")
96        if student['studycourse'].current_session != acc_details[
97            'booking_session']:
98            return _('Your current session does not '
99                     'match accommodation session.')
100        stage = bt.split('_')[2]
101        if not student.is_postgrad and stage != 'fr' and not student[
102            'studycourse'].previous_verdict in (
103                'A', 'B', 'F', 'J', 'L', 'M', 'C', 'Z'):
104            return _("Your are not eligible to book accommodation.")
105        bsession = str(acc_details['booking_session'])
106        if bsession in student['accommodation'].keys() \
107            and not 'booking expired' in \
108            student['accommodation'][bsession].bed_coordinates:
109            return _('You already booked a bed space in '
110                     'current accommodation session.')
111        return
112
113    def getAccommodationDetails(self, student):
114        """Determine the accommodation data of a student.
115        """
116        d = {}
117        d['error'] = u''
118        hostels = grok.getSite()['hostels']
119        d['booking_session'] = hostels.accommodation_session
120        d['allowed_states'] = hostels.accommodation_states
121        d['startdate'] = hostels.startdate
122        d['enddate'] = hostels.enddate
123        d['expired'] = hostels.expired
124        # Determine bed type
125        studycourse = student['studycourse']
126        certificate = getattr(studycourse,'certificate',None)
127        entry_session = studycourse.entry_session
128        current_level = studycourse.current_level
129        if None in (entry_session, current_level, certificate):
130            return d
131        if student.sex == 'f':
132            sex = 'female'
133        else:
134            sex = 'male'
135        if student.is_postgrad:
136            bt = 'all'
137            special_handling = 'pg'
138        else:
139            end_level = certificate.end_level
140            if current_level == 10:
141                bt = 'pr'
142            elif entry_session == grok.getSite()['hostels'].accommodation_session:
143                bt = 'fr'
144            elif current_level >= end_level:
145                bt = 'fi'
146            else:
147                bt = 're'
148            special_handling = 'regular'
149            desired_hostel = student['accommodation'].desired_hostel
150            if student.faccode in ('MED', 'DEN') and (
151                not desired_hostel or desired_hostel.startswith('clinical')):
152                special_handling = 'clinical'
153            elif student.certcode in ('BARTMAS', 'BARTTHR', 'BARTFAA',
154                                      'BAEDFAA', 'BSCEDECHED', 'BAFAA'):
155                special_handling = 'ekenwan'
156        d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt)
157        return d
158
159    def _paymentMade(self, student, session):
160        if len(student['payments']):
161            for ticket in student['payments'].values():
162                if ticket.p_state == 'paid' and \
163                    ticket.p_category == 'schoolfee' and \
164                    ticket.p_session == session:
165                    return True
166        return False
167
168    def _isPaymentDisabled(self, p_session, category, student):
169        academic_session = self._getSessionConfiguration(p_session)
170        if category == 'schoolfee':
171            if 'sf_all' in academic_session.payment_disabled:
172                return True
173            if student.state == RETURNING and \
174                'sf_return' in academic_session.payment_disabled:
175                return True
176            if student.current_mode == 'found' and \
177                'sf_found' in academic_session.payment_disabled:
178                return True
179            if student.is_postgrad:
180                if 'sf_pg' in academic_session.payment_disabled:
181                    return True
182                return False
183            if student.current_mode.endswith('ft') and \
184                'sf_ft' in academic_session.payment_disabled:
185                return True
186            if student.current_mode.endswith('pt') and \
187                'sf_pt' in academic_session.payment_disabled:
188                return True
189            if student.current_mode.startswith('dp') and \
190                'sf_dp' in academic_session.payment_disabled:
191                return True
192            if student.current_mode.endswith('sw') and \
193                'sf_sw' in academic_session.payment_disabled:
194                return True
195        if category == 'hostel_maintenance' and \
196            'maint_all' in academic_session.payment_disabled:
197            return True
198        if category == 'clearance':
199            if 'cl_all' in academic_session.payment_disabled:
200                return True
201            if student.is_jupeb and \
202                'cl_jupeb' in academic_session.payment_disabled:
203                return True
204            if not student.is_jupeb and \
205                'cl_allexj' in academic_session.payment_disabled:
206                return True
207        return False
208
209    #def _hostelApplicationPaymentMade(self, student, session):
210    #    if len(student['payments']):
211    #        for ticket in student['payments'].values():
212    #            if ticket.p_state == 'paid' and \
213    #                ticket.p_category == 'hostel_application' and \
214    #                ticket.p_session == session:
215    #                return True
216    #    return False
217
218    def _pharmdInstallments(self, student):
219        installments = 0.0
220        if len(student['payments']):
221            for ticket in student['payments'].values():
222                if ticket.p_state == 'paid' and \
223                    ticket.p_category.startswith('pharmd') and \
224                    ticket.p_session == student.current_session:
225                    installments += ticket.amount_auth
226        return installments
227
228    def samePaymentMade(self, student, category, p_item, p_session):
229        if category in ('bed_allocation', 'transcript'):
230            return False
231        for key in student['payments'].keys():
232            ticket = student['payments'][key]
233            if ticket.p_state == 'paid' and\
234               ticket.p_category == category and \
235               ticket.p_item == p_item and \
236               ticket.p_session == p_session:
237                  return True
238        return False
239
240    def setPaymentDetails(self, category, student,
241            previous_session, previous_level, combi):
242        """Create Payment object and set the payment data of a student for
243        the payment category specified.
244
245        """
246        p_item = u''
247        amount = 0.0
248        if previous_session:
249            if previous_session < student['studycourse'].entry_session:
250                return _('The previous session must not fall below '
251                         'your entry session.'), None
252            if category == 'schoolfee':
253                # School fee is always paid for the following session
254                if previous_session > student['studycourse'].current_session:
255                    return _('This is not a previous session.'), None
256            else:
257                if previous_session > student['studycourse'].current_session - 1:
258                    return _('This is not a previous session.'), None
259            p_session = previous_session
260            p_level = previous_level
261            p_current = False
262        else:
263            p_session = student['studycourse'].current_session
264            p_level = student['studycourse'].current_level
265            p_current = True
266        academic_session = self._getSessionConfiguration(p_session)
267        if academic_session == None:
268            return _(u'Session configuration object is not available.'), None
269        # Determine fee.
270        if category.startswith('pharmd') \
271            and student.current_mode == 'special_ft':
272            amount = 80000.0
273        elif category == 'plag_test':
274            amount = 2500.0
275            if student.is_postgrad:
276                amount = 5000.0
277        #elif category == 'develop' and student.is_postgrad:
278        #    amount = academic_session.development_fee
279        elif category == 'bed_allocation':
280            acco_details = self.getAccommodationDetails(student)
281            p_session = acco_details['booking_session']
282            p_item = acco_details['bt']
283            desired_hostel = student['accommodation'].desired_hostel
284            if not desired_hostel:
285                return _(u'Select your favoured hostel first.'), None
286            if desired_hostel and desired_hostel != 'no':
287                p_item = u'%s (%s)' % (p_item, desired_hostel)
288            amount = academic_session.booking_fee
289            if student.is_postgrad:
290                amount += 500
291        elif category == 'hostel_maintenance':
292            amount = 0.0
293            booking_session = grok.getSite()['hostels'].accommodation_session
294            bedticket = student['accommodation'].get(str(booking_session), None)
295            if bedticket is not None and bedticket.bed is not None:
296                p_item = bedticket.bed_coordinates
297                p_session = booking_session
298                if bedticket.bed.__parent__.maint_fee > 0:
299                    amount = bedticket.bed.__parent__.maint_fee
300                else:
301                    # fallback
302                    amount = academic_session.maint_fee
303            else:
304                return _(u'No bed allocated.'), None
305        #elif category == 'hostel_application':
306        #    amount = 1000.0
307        #elif category.startswith('tempmaint'):
308        #    if not self._hostelApplicationPaymentMade(
309        #        student, student.current_session):
310        #        return _(
311        #            'You have not yet paid the hostel application fee.'), None
312        #    if category == 'tempmaint_1':
313        #        amount = 8150.0
314        #    elif category == 'tempmaint_2':
315        #        amount = 12650.0
316        #    elif category == 'tempmaint_3':
317        #        amount = 9650.0
318        elif category == 'clearance':
319            p_item = student.certcode
320            if p_item is None:
321                return _('Study course data are incomplete.'), None
322            if student.is_jupeb:
323                amount = 50000.0
324            elif student.faccode.startswith('FCETA'):
325                # ASABA and AKOKA
326                amount = 35000.0
327            elif student.depcode == 'DMIC':
328                amount = 70000.0
329            elif student.faccode in ('BMS', 'MED', 'DEN'):
330            #elif p_item in ('BSCANA', 'BSCMBC', 'BMLS', 'BSCNUR', 'BSCPHS', 'BDS',
331            #    'MBBSMED', 'MBBSNDU', 'BSCPTY', 'BSCPST'):
332                amount = 80000.0
333            elif student.faccode == 'DCOEM':
334                return _('Acceptance fee payment not necessary.'), None
335            else:
336                amount = 60000.0
337        elif category == 'schoolfee':
338            try:
339                certificate = student['studycourse'].certificate
340                p_item = certificate.code
341            except (AttributeError, TypeError):
342                return _('Study course data are incomplete.'), None
343            discount_year = 2017
344            if student.is_postgrad:
345                discount_year = 2020
346            if previous_session:
347                # Students can pay for previous sessions in all workflow states.
348                # Fresh students are excluded by the update method of the
349                # PreviousPaymentAddFormPage.
350                if previous_session == student['studycourse'].entry_session:
351                    if student.is_foreigner:
352                        amount = getattr(certificate, 'school_fee_3', 0.0)
353                    else:
354                        amount = getattr(certificate, 'school_fee_1', 0.0)
355                        # Old new students get a discount.
356                        if student.entry_session < discount_year \
357                            and certificate.custom_float_1:
358                            amount -= certificate.custom_float_1                       
359                else:
360                    if student.is_foreigner:
361                        amount = getattr(certificate, 'school_fee_4', 0.0)
362                    else:
363                        amount = getattr(certificate, 'school_fee_2', 0.0)
364                        # Old returning students get a discount.
365                        if student.entry_session < discount_year \
366                            and certificate.custom_float_2:
367                            amount -= certificate.custom_float_2
368            else:
369                if student.state == CLEARED:
370                    if student.is_foreigner:
371                        amount = getattr(certificate, 'school_fee_3', 0.0)
372                    else:
373                        amount = getattr(certificate, 'school_fee_1', 0.0)
374                        # Old new students get a discount.
375                        if student.entry_session < discount_year \
376                            and certificate.custom_float_1:
377                            amount -= certificate.custom_float_1                             
378                elif student.state == PAID and student.is_postgrad:
379                    p_session += 1
380                    academic_session = self._getSessionConfiguration(p_session)
381                    if academic_session == None:
382                        return _(u'Session configuration object is not available.'), None
383
384                    # Students are only allowed to pay for the next session
385                    # if current session payment
386                    # has really been made, i.e. payment object exists.
387                    #if not self._paymentMade(
388                    #    student, student.current_session):
389                    #    return _('You have not yet paid your current/active' +
390                    #             ' session. Please use the previous session' +
391                    #             ' payment form first.'), None
392
393                    if student.is_foreigner:
394                        amount = getattr(certificate, 'school_fee_4', 0.0)
395                    else:
396                        amount = getattr(certificate, 'school_fee_2', 0.0)
397                        # Old returning students might get a discount.
398                        if student.entry_session < discount_year \
399                            and certificate.custom_float_2:
400                            amount -= certificate.custom_float_2
401                elif student.state == RETURNING:
402                    # In case of returning school fee payment the payment session
403                    # and level contain the values of the session the student
404                    # has paid for.
405                    p_session, p_level = self.getReturningData(student)
406                    academic_session = self._getSessionConfiguration(p_session)
407                    if academic_session == None:
408                        return _(u'Session configuration object is not available.'), None
409
410                    # Students are only allowed to pay for the next session
411                    # if current session payment has really been made,
412                    # i.e. payment object exists and is paid.
413                    #if not self._paymentMade(
414                    #    student, student.current_session):
415                    #    return _('You have not yet paid your current/active' +
416                    #             ' session. Please use the previous session' +
417                    #             ' payment form first.'), None
418
419                    if student.is_foreigner:
420                        amount = getattr(certificate, 'school_fee_4', 0.0)
421                    else:
422                        amount = getattr(certificate, 'school_fee_2', 0.0)
423                        # Old returning students might get a discount.
424                        if student.entry_session < discount_year \
425                            and certificate.custom_float_2:
426                            amount -= certificate.custom_float_2
427                # PHARMD school fee amount is fixed and previously paid
428                # installments in current session are deducted.
429                if student.current_mode == 'special_ft' \
430                    and student.state in (RETURNING, CLEARED):
431                    if student.is_foreigner:
432                        amount = 260000.0 - self._pharmdInstallments(student)
433                    else:
434                        amount = 160000.0 - self._pharmdInstallments(student)
435            # Give 50% school fee discount to staff members.
436            if student.is_staff:
437                amount /= 2
438        else:
439            fee_name = category + '_fee'
440            amount = getattr(academic_session, fee_name, 0.0)
441        if amount in (0.0, None):
442            return _('Amount could not be determined.'), None
443        # Add session specific penalty fee.
444        if category == 'schoolfee' and student.is_postgrad:
445            amount += academic_session.penalty_pg
446            amount += academic_session.development_fee
447        elif category == 'schoolfee' and student.current_mode == ('ug_ft'):
448            amount += academic_session.penalty_ug_ft
449        elif category == 'schoolfee' and student.current_mode == ('ug_pt'):
450            amount += academic_session.penalty_ug_pt
451        elif category == 'schoolfee' and student.current_mode == ('ug_sw'):
452            amount += academic_session.penalty_sw
453        elif category == 'schoolfee' and student.current_mode in (
454            'dp_ft', 'dp_pt'):
455            amount += academic_session.penalty_dp
456        if category.startswith('tempmaint'):
457            p_item = getUtility(IKofaUtils).PAYMENT_CATEGORIES[category]
458            p_item = unicode(p_item)
459            # Now we change the category because tempmaint payments
460            # will be obsolete when Uniben returns to Kofa bed allocation.
461            category = 'hostel_maintenance'
462        # Create ticket.
463        if self.samePaymentMade(student, category, p_item, p_session):
464            return _('This type of payment has already been made.'), None
465        if self._isPaymentDisabled(p_session, category, student):
466            return _('This category of payments has been disabled.'), None
467        payment = createObject(u'waeup.StudentOnlinePayment')
468        timestamp = ("%d" % int(time()*10000))[1:]
469        payment.p_id = "p%s" % timestamp
470        payment.p_category = category
471        payment.p_item = p_item
472        payment.p_session = p_session
473        payment.p_level = p_level
474        payment.p_current = p_current
475        payment.amount_auth = amount
476        return None, payment
477
478    def warnCreditsOOR(self, studylevel, course=None):
479        studycourse = studylevel.__parent__
480        certificate = getattr(studycourse,'certificate', None)
481        current_level = studycourse.current_level
482        if None in (current_level, certificate):
483            return
484        if studylevel.__parent__.previous_verdict == 'R':
485            return
486        end_level = certificate.end_level
487        if studylevel.student.faccode in (
488            'MED', 'DEN', 'BMS') and studylevel.level == 200:
489            limit = 61
490        elif current_level >= end_level:
491            limit = 51
492        else:
493            limit = 50
494        if course and studylevel.total_credits + course.credits > limit:
495            return _('Maximum credits exceeded.')
496        elif studylevel.total_credits > limit:
497            return _('Maximum credits exceeded.')
498        return
499
500    def warnCourseAlreadyPassed(self, studylevel, course):
501        """Return message if course has already been passed at
502        previous levels.
503        """
504
505        # med: we may need to put this matter on hold and allow
506        # all the students to register.
507        return False
508
509        previous_verdict = studylevel.__parent__.previous_verdict
510        if previous_verdict in ('C', 'M'):
511            return False
512        for slevel in studylevel.__parent__.values():
513            for cticket in slevel.values():
514                if cticket.code == course.code \
515                    and cticket.total_score >= cticket.passmark:
516                    return _('Course has already been passed at previous level.')
517        return False
518
519    def clearance_disabled_message(self, student):
520        if student.is_postgrad:
521            return None
522        try:
523            session_config = grok.getSite()[
524                'configuration'][str(student.current_session)]
525        except KeyError:
526            return _('Session configuration object is not available.')
527        if not session_config.clearance_enabled:
528            return _('Clearance is disabled for this session.')
529        return None
530
531    def renderPDFTranscript(self, view, filename='transcript.pdf',
532                  student=None,
533                  studentview=None,
534                  note=None,
535                  signatures=(),
536                  sigs_in_footer=(),
537                  digital_sigs=(),
538                  show_scans=True, topMargin=1.5,
539                  omit_fields=(),
540                  tableheader=None,
541                  no_passport=False,
542                  save_file=False):
543        """Render pdf slip of a transcripts.
544        """
545        portal_language = getUtility(IKofaUtils).PORTAL_LANGUAGE
546        # XXX: tell what the different parameters mean
547        style = getSampleStyleSheet()
548        creator = self.getPDFCreator(student)
549        data = []
550        doc_title = view.label
551        author = '%s (%s)' % (view.request.principal.title,
552                              view.request.principal.id)
553        footer_text = view.label.split('\n')
554        if len(footer_text) > 2:
555            # We can add a department in first line
556            footer_text = footer_text[1]
557        else:
558            # Only the first line is used for the footer
559            footer_text = footer_text[0]
560        if getattr(student, 'student_id', None) is not None:
561            footer_text = "%s - %s - " % (student.student_id, footer_text)
562
563        # Insert student data table
564        if student is not None:
565            #bd_translation = trans(_('Base Data'), portal_language)
566            #data.append(Paragraph(bd_translation, HEADING_STYLE))
567            data.append(render_student_data(
568                studentview, view.context,
569                omit_fields, lang=portal_language,
570                slipname=filename,
571                no_passport=no_passport))
572
573        transcript_data = view.context.getTranscriptData()
574        levels_data = transcript_data[0]
575
576        contextdata = []
577        f_label = trans(_('Course of Study:'), portal_language)
578        f_label = Paragraph(f_label, ENTRY1_STYLE)
579        f_text = formatted_text(view.context.certificate.longtitle)
580        f_text = Paragraph(f_text, ENTRY1_STYLE)
581        contextdata.append([f_label,f_text])
582
583        f_label = trans(_('Faculty:'), portal_language)
584        f_label = Paragraph(f_label, ENTRY1_STYLE)
585        f_text = formatted_text(
586            view.context.certificate.__parent__.__parent__.__parent__.longtitle)
587        f_text = Paragraph(f_text, ENTRY1_STYLE)
588        contextdata.append([f_label,f_text])
589
590        f_label = trans(_('Department:'), portal_language)
591        f_label = Paragraph(f_label, ENTRY1_STYLE)
592        f_text = formatted_text(
593            view.context.certificate.__parent__.__parent__.longtitle)
594        f_text = Paragraph(f_text, ENTRY1_STYLE)
595        contextdata.append([f_label,f_text])
596
597        f_label = trans(_('Entry Session:'), portal_language)
598        f_label = Paragraph(f_label, ENTRY1_STYLE)
599        f_text = formatted_text(
600            view.session_dict.get(view.context.entry_session))
601        f_text = Paragraph(f_text, ENTRY1_STYLE)
602        contextdata.append([f_label,f_text])
603
604        f_label = trans(_('Final Session:'), portal_language)
605        f_label = Paragraph(f_label, ENTRY1_STYLE)
606        f_text = formatted_text(
607            view.session_dict.get(view.context.current_session))
608        f_text = Paragraph(f_text, ENTRY1_STYLE)
609        contextdata.append([f_label,f_text])
610
611        f_label = trans(_('Entry Mode:'), portal_language)
612        f_label = Paragraph(f_label, ENTRY1_STYLE)
613        f_text = formatted_text(view.studymode_dict.get(
614            view.context.entry_mode))
615        f_text = Paragraph(f_text, ENTRY1_STYLE)
616        contextdata.append([f_label,f_text])
617
618        f_label = trans(_('Final Verdict:'), portal_language)
619        f_label = Paragraph(f_label, ENTRY1_STYLE)
620        f_text = formatted_text(view.studymode_dict.get(
621            view.context.current_verdict))
622        f_text = Paragraph(f_text, ENTRY1_STYLE)
623        contextdata.append([f_label,f_text])
624
625        f_label = trans(_('Cumulative GPA:'), portal_language)
626        f_label = Paragraph(f_label, ENTRY1_STYLE)
627        format_float = getUtility(IKofaUtils).format_float
628        cgpa = format_float(transcript_data[1], 3)
629        if student.state == GRADUATED:
630            f_text = formatted_text('%s (%s)' % (
631                cgpa, self.getClassFromCGPA(transcript_data[1], student)[1]))
632        else:
633            f_text = formatted_text('%s' % cgpa)
634        f_text = Paragraph(f_text, ENTRY1_STYLE)
635        contextdata.append([f_label,f_text])
636
637        contexttable = Table(contextdata,style=SLIP_STYLE)
638        data.append(contexttable)
639
640        transcripttables = render_transcript_data(
641            view, tableheader, levels_data, lang=portal_language)
642        data.extend(transcripttables)
643
644        # Insert signatures
645        # XXX: We are using only sigs_in_footer in waeup.kofa, so we
646        # do not have a test for the following lines.
647        if signatures and not sigs_in_footer:
648            data.append(Spacer(1, 20))
649            # Render one signature table per signature to
650            # get date and signature in line.
651            for signature in signatures:
652                signaturetables = get_signature_tables(signature)
653                data.append(signaturetables[0])
654
655        # Insert digital signatures
656        if digital_sigs:
657            data.append(Spacer(1, 20))
658            sigs = digital_sigs.split('\n')
659            for sig in sigs:
660                data.append(Paragraph(sig, NOTE_STYLE))
661
662        view.response.setHeader(
663            'Content-Type', 'application/pdf')
664        try:
665            pdf_stream = creator.create_pdf(
666                data, None, doc_title, author=author, footer=footer_text,
667                note=note, sigs_in_footer=sigs_in_footer, topMargin=topMargin,
668                view=view)
669        except IOError:
670            view.flash(_('Error in image file.'))
671            return view.redirect(view.url(view.context))
672        if save_file:
673            self._saveTranscriptPDF(student, pdf_stream)
674            return
675        return pdf_stream
676
677    #: A tuple containing the names of registration states in which changing of
678    #: passport pictures is allowed.
679    PORTRAIT_CHANGE_STATES = (CLEARANCE, REQUESTED)
680
681    #: A tuple containing the names of registration states in which changing of
682    #: scanned signatures is allowed.
683    SIGNATURE_CHANGE_STATES = (CLEARED, RETURNING, PAID, REGISTERED, VALIDATED, )
684
685    # Uniben prefix
686    @property
687    def STUDENT_ID_PREFIX(self):
688        if grok.getSite().__name__ == 'uniben-cdl':
689            return u'C'
690        return u'B'
691
692    STUDENT_EXPORTER_NAMES = (
693            'students',
694            'studentstudycourses',
695            'studentstudycourses_1',
696            'studentstudylevels',
697            #'studentstudylevels_1',
698            'coursetickets',
699            #'coursetickets_1',
700            'studentpayments',
701            'bedtickets',
702            'trimmed',
703            'outstandingcourses',
704            'unpaidpayments',
705            'sfpaymentsoverview',
706            'sessionpaymentsoverview',
707            'studylevelsoverview',
708            'combocard',
709            'bursary',
710            'accommodationpayments',
711            'transcriptdata',
712            'trimmedpayments',
713            'medicalhistory',
714            )
Note: See TracBrowser for help on using the repository browser.