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

Last change on this file since 18364 was 18364, checked in by Henrik Bettermann, 9 days ago

New NCE school fees.

  • Property svn:keywords set to Id
File size: 28.6 KB
RevLine 
[7419]1## $Id: utils.py 18364 2026-11-18 15:10:11Z 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]18import grok
[9190]19import random
[18262]20import textwrap
[8599]21from time import time
[18262]22from zope.i18n import translate
[9950]23from zope.component import createObject, getUtility
[18262]24from reportlab.lib.styles import getSampleStyleSheet
25from reportlab.platypus import Paragraph, Image, Table, Spacer
[13800]26from waeup.kofa.interfaces import (
27    CLEARED, RETURNING, PAID, ADMITTED, CLEARANCE, REQUESTED)
[8834]28from kofacustom.nigeria.students.utils import NigeriaStudentsUtils
[8247]29from waeup.kofa.accesscodes import create_accesscode
[18262]30from waeup.kofa.interfaces import CLEARED, RETURNING, academic_sessions_vocab
[8460]31from waeup.fceokene.interfaces import MessageFactory as _
[9950]32from waeup.kofa.browser.interfaces import IPDFCreator
[18262]33from waeup.kofa.students.utils import trans, CONTENT_STYLE
34from waeup.kofa.browser.pdf import (
35    ENTRY1_STYLE, format_html, NOTE_STYLE, HEADING_STYLE,
36    get_signature_tables, get_qrcode)
[6902]37
[11919]38# Very special school fee configuration, should be moved to
39# a seperate file.
40
41ARTS = ('CRS','ISS','HIS','MUS','ECO','GEO','POL','SOS','CCA','ECU',
42        'THA','GED','GSE','PES','SPC','ENG','FRE','ARB','HAU','IGB',
43        'YOR','NCRS','NISS','NHIS','NMUS','NECO','NGEO','NPOL',
44        'NCCA','NECU','NTHA','NGED','NGSE','NPES','NSPC','NENG',
45        'NFRE','NARB','NHAU','NIGB','NYOR','NSOS')
46
[15594]47GATEWAY_AMT = 0.0
[15283]48
[8834]49class CustomStudentsUtils(NigeriaStudentsUtils):
[7151]50    """A collection of customized methods.
51
52    """
53
[15706]54    def selectBed(self, available_beds):
[13459]55        """Randomly select a bed from the list of available beds.
[9190]56        """
57        return random.choice(available_beds)
58
[8270]59    def getReturningData(self, student):
60        """ This method defines what happens after school fee payment
[8319]61        of returning students depending on the student's senate verdict.
[8270]62        """
[8319]63        prev_level = student['studycourse'].current_level
64        cur_verdict = student['studycourse'].current_verdict
65        if cur_verdict in ('A','B','L','M','N','Z',):
66            # Successful student
67            new_level = divmod(int(prev_level),100)[0]*100 + 100
[9923]68        elif cur_verdict in ('C','O'):
[8319]69            # Student on probation
70            new_level = int(prev_level) + 10
71        else:
72            # Student is somehow in an undefined state.
73            # Level has to be set manually.
74            new_level = prev_level
[9923]75        if cur_verdict == 'O':
76            new_session = student['studycourse'].current_session
77        else:
78            new_session = student['studycourse'].current_session + 1
[8270]79        return new_session, new_level
80
[16899]81    #def _nce3PaymentMade(self, student, p_level):
82    #    if len(student['payments']):
83    #        for ticket in student['payments'].values():
84    #            if ticket.p_state in ('paid', 'scholarship', 'waived') and \
85    #                ticket.p_level == p_level and \
86    #                ticket.p_category == 'schoolfee':
87    #                return True
88    #    return False
[16008]89
[9153]90    def setPaymentDetails(self, category, student,
[15678]91            previous_session=None, previous_level=None, combi=[]):
[8599]92        """Create Payment object and set the payment data of a student for
93        the payment category specified.
94
95        """
[8306]96        details = {}
[8599]97        p_item = u''
98        amount = 0.0
99        error = u''
[9153]100        if previous_session:
101            return _('Previous session payment not yet implemented.'), None
[8599]102        p_session = student['studycourse'].current_session
103        p_level = student['studycourse'].current_level
[9153]104        p_current = True
[9525]105        academic_session = self._getSessionConfiguration(p_session)
106        if academic_session == None:
[8599]107            return _(u'Session configuration object is not available.'), None
[9525]108        # Determine fee.
[7151]109        if category == 'transfer':
[8599]110            amount = academic_session.transfer_fee
[7151]111        elif category == 'gown':
[8599]112            amount = academic_session.gown_fee
[7151]113        elif category == 'bed_allocation':
[17183]114            acco_details = self.getAccommodationDetails(student)
115            p_session = acco_details['booking_session']
116            p_item = acco_details['bt']
[8599]117            amount = academic_session.booking_fee
[7151]118        elif category == 'hostel_maintenance':
[17183]119            amount = 0.0
120            booking_session = grok.getSite()['hostels'].accommodation_session
121            bedticket = student['accommodation'].get(str(booking_session), None)
[9611]122            if bedticket is not None and bedticket.bed is not None:
[17183]123                p_session = booking_session
[9611]124                p_item = bedticket.bed_coordinates
[17629]125                if bedticket.bed.__parent__.maint_fee > 0:
126                    amount = bedticket.bed.__parent__.maint_fee
127                #if student['studycourse'].current_session < 2022:
128                #    amount = 6100.0
129                #else:
130                #    amount = 10090.0
[9611]131            else:
[13616]132                return _(u'No bed space allocated.'), None
133            if student.current_mode.endswith('_sw') \
134                or student.current_mode == 'pd_ft':
135                amount *= 0.625
[7151]136        elif category == 'clearance':
[9143]137            amount = academic_session.clearance_fee
[8599]138            try:
139                p_item = student['studycourse'].certificate.code
140            except (AttributeError, TypeError):
141                return _('Study course data are incomplete.'), None
[13800]142            if student.state not in (ADMITTED, CLEARANCE, REQUESTED, CLEARED):
143                return _(u'Acceptance Fee payments not allowed.'), None
[16899]144        #elif category == 'third_semester' and student.current_mode == 'nce_ft' \
145        #    and p_level in (300, 310, 320, 400, 410, 420):
146        #    #if not self._nce3PaymentMade(student, p_level):
147        #    #    return _(u'Make NCE 3 school fee payment first.'), None
148        #    no_additional_courses = 0
149        #    courses_level = student['studycourse'].get(str(p_level))
150        #    if courses_level and len(courses_level)> 6:
151        #        no_additional_courses = len(courses_level)-6
152        #        amount = 2000.0 * no_additional_courses
[18057]153        elif category == 'reg2sandwich':
154            amount = 40000.0
[16461]155        elif category.startswith('schoolfee'):
156            if category == 'schoolfee_pde1':
[16462]157                if not student.current_mode.startswith('pd'):
158                    return _('You are not a PDE student.'), None
[16461]159                if student.state != CLEARED:
160                        return _('You are not a fresh student.'), None
[17734]161            if category == 'schoolfee_ug_new':
162                if not student.current_mode.startswith('ug'):
163                    return _('You are not a UG student.'), None
164                if student.state != CLEARED:
165                        return _('You are not a fresh student.'), None
166            if category == 'schoolfee_ug_ret':
167                if not student.current_mode.startswith('ug'):
168                    return _('You are not a UG student.'), None
169                if student.state != RETURNING:
170                        return _('You are not a returning student.'), None
[16899]171            if category == 'schoolfee_third':
172                if not student.current_mode == 'nce_ft' \
173                    or not p_level in (300, 310, 320, 400, 410, 420):
174                    return _('You are not an NCE 3 student.'), None
[12602]175            p_item =  student.certcode
176            if not p_item:
[8599]177                return _('Study course data are incomplete.'), None
[10012]178            if student.state not in (CLEARED, RETURNING):
179                return _('Wrong state.'), None
[10661]180            # PDE repeater
181            if student.current_verdict == 'OPDE':
[18052]182                amount = 30000
[13274]183            # PDE new
184            elif student.current_mode == 'pd_ft' and student.state == CLEARED:
[18052]185                amount = 90000
[16461]186                if category == 'schoolfee_pde1':
187                    amount = 40000
[10660]188            # PDE
189            elif student.current_mode == 'pd_ft':
[13275]190                amount = 35300
[12602]191
192            #Short Duration ICT Programs
193            elif p_item in ('CCO','DPMTS','DTPGD') and \
194                 student.state == CLEARED:
195                amount = 15000
196            elif p_item in ('ADTPGD','ADPMTS') and \
197                 student.state == CLEARED:
198                amount = 16000
199            elif p_item in ('ADPMTSI','ADTPGDI','DPMTSI','DTPGDI') and \
200                 student.state == CLEARED:
201                amount = 25000
202            elif p_item in ('ADPMTSA','ADTPGDA') and \
203               student.state == CLEARED:
204                amount = 35000
205
[18233]206            # new degree programme
207            elif student.faccode == 'SUP':
208                amount = 85500
209
[10012]210            # UG
211            elif student.current_mode == 'ug_ft':
[17734]212                if category == 'schoolfee_ug_new':
213                    # conditions checked above
[17983]214                    amount = 80000
[17734]215                elif category == 'schoolfee_ug_ret':
216                    # conditions checked above
[17983]217                    amount = 60000
[17734]218                elif student.state == CLEARED:
[17983]219                    amount = 140000
[13779]220                # Introducing repeater fee for 'ug_ft' for 1st time
221                # on 15/03/2016
[17734]222                #elif student.current_verdict == 'O':
223                #    amount = 96700
[10876]224                else:
[17983]225                    amount = 110000
226
[10012]227            # NCE
[9143]228            elif not student.current_mode.endswith('_sw'):
229                # PRENCE
230                if student.current_level == 10 and student.state == CLEARED:
[18364]231                    amount = 25000
[10012]232                # NCE I fresh
[9143]233                elif student.current_level == 100 and student.state == CLEARED:
[18364]234                    amount = 42000
[14931]235                    # SIWES Fee
[16542]236                    if student.depcode in ('AGE', 'BED', 'FAA', 'HEC', 'CSC', 'MUS') \
[17087]237                       or student.certcode in ('NCECHECSC',
238                                               'NCEBIOCSC',
239                                               'NCEPHYCSC',
240                                               'NCEPHECSC',
241                                               'NCETHAMUS',
242                                               'NCEANFMUS',
243                                               'NCEHISMUS',
244                                               'NCEIGBMUS',
245                                               'NCESPCCSC',
246                                               ):
[14931]247                        amount += 3000
[10012]248                # NCE II
[9143]249                elif student.current_level in (100, 110, 120) and \
250                    student.state == RETURNING:
[18364]251                    amount = 31500
[16899]252                # NCE III third semester
253                elif category == 'schoolfee_third':
[18052]254                    amount = 18000
[10012]255                # NCE III
[9143]256                elif student.current_level in (200, 210, 220):
[18364]257                    amount = 29000
[10012]258                # NCE III repeater
[9143]259                elif student.current_level in (300, 310, 320) and \
260                    student.current_verdict == 'O':
[18364]261                    amount = 45000
[10012]262                # NCE III spillover
[9143]263                elif student.current_level in (300, 310, 320) and \
264                    student.current_verdict == 'B':
[18364]265                    amount = 45000
[10012]266                # NCE III second spillover
[9143]267                elif student.current_level in (400, 410, 420) and \
268                    student.current_verdict == 'B':
[18364]269                    amount = 45000
[9143]270            else:
[14265]271                # NCE I fresh sw
[9143]272                if student.current_level == 100 and student.state == CLEARED:
273                    if student.depcode in ARTS:
[14193]274                        amount = 23100
[9143]275                    else:
[14193]276                        amount = 23600
[14265]277                # NCE II fresh sw
278                elif student.current_level == 200 and student.state == CLEARED:
279                    if student.depcode in ARTS:
280                        amount = 19000
281                    else:
282                        amount = 19500
[10012]283                # NCE II sw
[9143]284                elif student.current_level in (100, 110, 120) and \
285                    student.state == RETURNING:
286                    if student.depcode in ARTS:
[11850]287                        amount = 19000
[9143]288                    else:
[11882]289                        amount = 19500
[10012]290                # NCE III sw
[9143]291                elif student.current_level in (200, 210, 220):
292                    if student.depcode in ARTS:
[11850]293                        amount = 21000
[9143]294                    else:
[14193]295                        amount = 21500
[10012]296                # NCE IV sw
[9143]297                elif student.current_level in (300, 310, 320):
298                    if student.depcode in ARTS:
[11850]299                        amount = 19000
[9143]300                    else:
[11850]301                        amount = 19500
[10012]302                # NCE V sw
[9143]303                elif student.current_level in (400, 410, 420):
304                    if student.depcode in ARTS:
[11850]305                        amount = 19000
[9143]306                    else:
[11850]307                        amount = 19500
[10012]308                # NCE V spillover sw
[9143]309                elif student.current_level in (500, 510, 520) and \
310                    student.current_verdict == 'B':
311                    if student.depcode in ARTS:
[11850]312                        amount = 17500
[9143]313                    else:
[11850]314                        amount = 18000
[10012]315                # NCE V second spillover sw
[9143]316                elif student.current_level in (600, 610, 620) and \
317                    student.current_verdict == 'B':
318                    if student.depcode in ARTS:
[16921]319                        amount = 17500
[9143]320                    else:
[16921]321                        amount = 18000
[10009]322            # NCE student payment can be disabled by
323            # setting the base school fee to -1
324            if academic_session.school_fee_base == -1 and \
325                student.current_mode.startswith('nce'):
[10010]326                return _(u'School fee payment is disabled.'), None
[9297]327            if student.state == RETURNING:
[9525]328                # Override p_session and p_level
[9297]329                p_session, p_level = self.getReturningData(student)
[9525]330                academic_session = self._getSessionConfiguration(p_session)
331                if academic_session == None:
332                    return _(u'Session configuration object is not available.'), None
[17087]333        else:
334            fee_name = category + '_fee'
335            amount = getattr(academic_session, fee_name, 0.0)
336           
[8599]337        if amount in (0.0, None):
338            return _(u'Amount could not be determined.'), None
[14566]339
340        # Add session and level specific penalty fee.
[13881]341        if category == 'schoolfee' and student.current_mode in (
[14617]342            'ug_ft', 'de_ft') and student.state != CLEARED:
[13881]343            amount += academic_session.penalty_ug_ft
344        elif category == 'schoolfee' and student.current_mode in (
[14556]345            'nce_ft',) and student['studycourse'].previous_verdict != 'O':
[14566]346            # NCE I fresh
347            if student.current_level == 100 and student.state == CLEARED:
348                amount += academic_session.penalty_nce1_ft
349            # NCE II
350            elif student.current_level in (100, 110, 120) and \
351                student.state == RETURNING:
352                amount += academic_session.penalty_nce2_ft
353            # NCE III (except repeaters and spillovers)
354            elif student.current_level in (200, 210, 220):
355                amount += academic_session.penalty_nce3_ft
[14618]356        elif category == 'schoolfee' and student.current_mode in ('nce_sw',
357            'nce_pt') and student['studycourse'].previous_verdict != 'O':
[14566]358            # NCE I fresh
359            if student.current_level == 100 and student.state == CLEARED:
360                amount += academic_session.penalty_nce1_pt
361            # NCE II
362            elif student.current_level in (100, 110, 120) and \
363                student.state == RETURNING:
364                amount += academic_session.penalty_nce2_pt
365            # NCE III (except repeaters and spillovers)
366            elif student.current_level in (200, 210, 220):
367                amount += academic_session.penalty_nce3_pt
[13881]368        elif category == 'schoolfee' and student.current_mode in ('prence',):
369            amount += academic_session.penalty_prence
[11649]370        if self.samePaymentMade(student, category, p_item, p_session):
371            return _('This type of payment has already been made.'), None
[11457]372        if self._isPaymentDisabled(p_session, category, student):
[13800]373            return _('This category of payments has been disabled.'), None
[8713]374        payment = createObject(u'waeup.StudentOnlinePayment')
[8953]375        timestamp = ("%d" % int(time()*10000))[1:]
[8599]376        payment.p_id = "p%s" % timestamp
377        payment.p_category = category
378        payment.p_item = p_item
379        payment.p_session = p_session
380        payment.p_level = p_level
[9153]381        payment.p_current = p_current
[10388]382        payment.amount_auth = float(amount) + GATEWAY_AMT
[8599]383        return None, payment
[7621]384
[9207]385    def getAccommodationDetails(self, student):
386        """Determine the accommodation data of a student.
387        """
388        d = {}
389        d['error'] = u''
390        hostels = grok.getSite()['hostels']
391        d['booking_session'] = hostels.accommodation_session
392        d['allowed_states'] = hostels.accommodation_states
393        d['startdate'] = hostels.startdate
394        d['enddate'] = hostels.enddate
395        d['expired'] = hostels.expired
396        # Determine bed type
397        studycourse = student['studycourse']
398        certificate = getattr(studycourse,'certificate',None)
399        current_level = studycourse.current_level
400        if None in (current_level, certificate):
401            return d
402        end_level = certificate.end_level
403        if current_level == 10:
404            bt = 'pr'
405        elif current_level == 100:
406            bt = 'fr'
407        elif current_level >= 300:
408            bt = 'fi'
409        else:
410            bt = 're'
411        if student.sex == 'f':
412            sex = 'female'
413        else:
414            sex = 'male'
415        special_handling = 'regular'
[13614]416        if certificate.study_mode == 'ug_ft':
417            special_handling = 'ugft'
[9207]418        d['bt'] = u'%s_%s_%s' % (special_handling,sex,bt)
419        return d
420
[14617]421    #def warnCreditsOOR(self, studylevel, course=None):
422    #    """Return message if credits are out of range.
423    #    """
424    #    # adding a course ticket
425    #    if course:
426    #        if course.semester == 1:
427    #            if studylevel.total_credits_s1 + course.credits > 24:
428    #                return _('Maximum credits in 1st semester exceeded.')
429    #        if course.semester == 2:
430    #            if studylevel.total_credits_s2 + course.credits > 24:
431    #                return _('Maximum credits in 2nd semester exceeded.')
432    #    # registering course list
433    #    else:
434    #        if studylevel.total_credits_s1 > 24:
435    #            return _('Maximum credits in 1st semester exceeded.')
436    #        if studylevel.total_credits_s1 < 18:
437    #            return _('Minimum credits in 1st semester not reached.')
438    #        if studylevel.total_credits_s2 > 24:
439    #            return _('Maximum credits in 2nd semester exceeded.')
440    #        if studylevel.total_credits_s2 < 18:
441    #            return _('Minimum credits in 2nd semester not reached.')
442    #    return
443
[14586]444    def warnCreditsOOR(self, studylevel, course=None):
[14591]445        """Return message if credits are out of range.
[9903]446        """
[14591]447        # adding a course ticket
448        if course:
[14617]449            if studylevel.total_credits + course.credits > 52:
450                return _('Maximum credits exceeded.')
[14591]451        # registering course list
452        else:
[14617]453            if studylevel.total_credits > 52:
454                return _('Maximum credits exceeded.')
[14618]455            if studylevel.__parent__.previous_verdict == 'O':
456                return
[14591]457            if studylevel.total_credits_s1 < 18:
458                return _('Minimum credits in 1st semester not reached.')
459            if studylevel.total_credits_s2 < 18:
460                return _('Minimum credits in 2nd semester not reached.')
[14586]461        return
[9903]462
[9950]463    def getPDFCreator(self, context):
464        """Get a pdf creator suitable for `context`.
465
466        The default implementation always returns the default creator.
467        """
468        mode = getattr(context, 'current_mode', None)
[18234]469        faccode = getattr(context, 'faccode', None)
470        if (mode and faccode) and mode.startswith('ug') and faccode != 'SUP':
[9950]471            return getUtility(IPDFCreator, name='ibadan_pdfcreator')
472        return getUtility(IPDFCreator)
473
[9982]474    def _admissionText(self, student, portal_language):
[18227]475        if student.current_mode.startswith('ug') and student.faccode != 'SUP':
[9982]476            text = trans(_(
[17576]477                'With reference to your application for admission into '
478                'Bachelor Degree Programme of the University of Ibadan, '
[18228]479                'you have been provisionally admitted into Federal College '
480                'of Education Okene as follows: '),
[9982]481                portal_language)
[18227]482        #elif student.current_mode.startswith('ug'):
483        #    text = trans(_(
484        #        'With reference to your application for admission into '
485        #        'Bachelor Degree Programme, '
486        #        'you have been provisionally admitted to a full-time '
487        #        'Bachelor of Arts in Education Degree Programme as follows: '),
488        #        portal_language)
[9982]489        else:
490            inst_name = grok.getSite()['configuration'].name
491            text = trans(_(
[17576]492                'You have been provisionally admitted into Federal College '
493                'of Education Okene as follows: '
[17577]494                ),
[9982]495                portal_language)
496        return text
497
[9989]498    def getBedCoordinates(self, bedticket):
499        """Return bed coordinates.
500
501        Bed coordinates are invisible in FCEOkene.
502        """
503        return _('(see payment slip)')
504
[13030]505    def _isPaymentDisabled(self, p_session, category, student):
506        academic_session = self._getSessionConfiguration(p_session)
507        if category == 'schoolfee':
508            if 'sf_all' in academic_session.payment_disabled:
509                return True
510            if 'sf_nce1' in academic_session.payment_disabled and \
511                student.current_level == 100 and student.state == CLEARED and \
512                student.current_mode == 'nce_ft':
513                return True
[16554]514        if category == 'clearance':
515            if 'cl_except_ug' in academic_session.payment_disabled and \
516                student.current_mode != 'ug_ft':
517                return True
[13030]518        return False
519
[10019]520    SEPARATORS_DICT = {
521        'form.fst_sit_fname': _(u'First Sitting Record'),
522        'form.scd_sit_fname': _(u'Second Sitting Record'),
523        #'form.alr_fname': _(u'Advanced Level Record'),
524        'form.hq_type': _(u'Advanced Level Record'),
525        'form.hq2_type': _(u'Second Higher Education Record'),
526        'form.nysc_year': _(u'NYSC Information'),
527        'form.employer': _(u'Employment History'),
528        'form.former_matric': _(u'Former Student'),
529        }
530
[10023]531    SKIP_UPLOAD_VIEWLETS = (
532        'higherqualificationresultupload',
533        'secondHigherqualificationresultupload',
534        'certificateupload',
535        'secondcertificateupload',
536        'thirdcertificateupload',
537        'resultstatementupload',
538        'secondrefereeletterupload',
539        'thirdrefereeletterupload',)
540
[17178]541    ACCOMMODATION_SPAN = 1
542
[8460]543    # FCEOkene prefix
[10520]544    STUDENT_ID_PREFIX = u'K'
[18262]545
546    def renderPDFCourseticketsOverview(
547            self, view, name, session, data, lecturers, orientation,
548            title_length, note,
549            signatures=(),
550            sigs_in_footer=(),):
551        """Render pdf slip of course tickets for a lecturer.
552        """
553        filename = '%s_%s_%s_%s.pdf' % (
554            name, view.context.code, session, view.request.principal.id)
555        try:
556            session = academic_sessions_vocab.getTerm(session).title
557        except LookupError:
558            session = _('void')
559        creator = getUtility(IPDFCreator, name=orientation)
560        style = getSampleStyleSheet()
561        pdf_data = []
562        pdf_data += [Paragraph(
563            translate(_('<b>Lecturer(s): ${a}</b>',
564                      mapping = {'a':lecturers})), style["Normal"]),]
565        pdf_data += [Paragraph(
566            translate(_('<br /><b>Department: ${a}</b>',
567                      mapping = {'a':view.context.__parent__.__parent__.longtitle})), style["Normal"]),]
568        pdf_data += [Paragraph(
569            translate(_('<br /><b>Credits: ${a}</b>',
570                      mapping = {'a':view.context.credits})), style["Normal"]),]
571        pdf_data += [Paragraph(
572            translate(_('<br /><b>Venue:</b>')), style["Normal"]),]
573        pdf_data += [Paragraph(
574            translate(_('<br /><b>Time:</b>')), style["Normal"]),]
575        # Not used in base package. Requested by AAUE.
576        if data[1]:
577            pdf_data += [Paragraph(
578                translate(_('<b>${a}</b>',
579                    mapping = {'a':data[1][0]})), style["Normal"]),]
580            pdf_data += [Paragraph(
581                translate(_('<b>${a}</b>',
582                    mapping = {'a':data[1][1]})), style["Normal"]),]
583            pdf_data += [Paragraph(
584                translate(_('<b>Total Students: ${a}</b>',
585                    mapping = {'a':data[1][2]})), style["Normal"]),]
586            pdf_data += [Paragraph(
587                translate(_('<b>Total Pass: ${a} (${b}%)</b>',
588                mapping = {'a':data[1][3],'b':data[1][4]})), style["Normal"]),]
589            pdf_data += [Paragraph(
590                translate(_('<b>Total Fail: ${a} (${b}%)</b>',
591                mapping = {'a':data[1][5],'b':data[1][6]})), style["Normal"]),]
592            grade_stats = []
593            for item in sorted(data[1][7].items()):
594                grade_stats.append(('%s=%s' % (item[0], item[1])))
595            grade_stats_string = ', '.join(grade_stats)
596            pdf_data += [Paragraph(
597                translate(_('<b>${a}</b>',
598                mapping = {'a':grade_stats_string})), style["Normal"]),]
599        pdf_data.append(Spacer(1, 20))
600        colWidths = [None] * len(data[0][0])
601        pdf_data += [Table(data[0], colWidths=colWidths, style=CONTENT_STYLE,
602                           repeatRows=1)]
603        # Process title if too long
604        title = " ".join(view.context.title.split())
605        ct = textwrap.fill(title, title_length)
606        ft = "" # title
607        #if len(textwrap.wrap(title, title_length)) > 1:
608        #    ft = textwrap.wrap(title, title_length)[0] + ' ...'
609        doc_title = translate(_('${a} (${b})\nAcademic Session ${d}',
610            mapping = {'a':ct,
611                       'b':view.context.code,
612                       'd':session}))
613        if name == 'attendance':
614            doc_title += '\n' + translate(_('Attendance Sheet'))
615        if name == 'coursetickets':
616            doc_title += '\n' + translate(_('Course Tickets Overview'))
617        if name == 'marksheet':
618            # requested by Uniben
619            dt = view.context.__parent__.__parent__.longtitle
620            #doc_title = '%s\n%s (%s)\nMid-Semester Continuous Assessment\nAcademic Session %s' % (dt, ct, view.context.code, session)
621            doc_title = '%s\n%s (%s)\nAcademic Session %s' % (dt, ct, view.context.code, session)
622        #footer_title = translate(_('${a} (${b}) - ${d}',
623        #    mapping = {'a':ft,
624        #               'b':view.context.code,
625        #               'd':session}))
626        footer_title = translate(_('${b} - ${d}',
627            mapping = {'b':view.context.code,
628                       'd':session}))
629        author = '%s (%s)' % (view.request.principal.title,
630                              view.request.principal.id)
631
632        # Insert signatures
633        # XXX: Not used in waeup.kofa, so we
634        # do not have a test for the following lines.
635        if signatures and not sigs_in_footer:
636            pdf_data.append(Spacer(1, 20))
637            # Render one signature table per signature to
638            # get date and signature in line.
639            for signature in signatures:
640                signaturetables = get_signature_tables(signature)
641                pdf_data.append(signaturetables[0])
642
643        view.response.setHeader(
644            'Content-Type', 'application/pdf')
645        view.response.setHeader(
646            'Content-Disposition:', 'attachment; filename="%s' % filename)
647        pdf_stream = creator.create_pdf(
648            pdf_data, None, doc_title, author, footer_title + ' -', note,
649            sigs_in_footer=sigs_in_footer,
650            )
651        return pdf_stream
Note: See TracBrowser for help on using the repository browser.