Ignore:
Timestamp:
2 Sep 2013, 06:42:16 (11 years ago)
Author:
Henrik Bettermann
Message:

Add browser components.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/students/reports/level_results_presentation.py

    r10574 r10576  
    2525from waeup.kofa.students.interfaces import IStudentsUtils
    2626from waeup.kofa.interfaces import MessageFactory as _
     27from waeup.kofa.browser.pdf import get_signature_tables
    2728from waeup.kofa.reports import IReport
    28 from waeup.kofa.browser.pdf import get_signature_tables
     29from waeup.kofa.students.reports.level_report import (
     30    ILevelReport, LevelReportGeneratorPage)
     31from waeup.kofa.students.reports.student_statistics import (
     32    StudentStatisticsReportPDFView)
    2933
     34
     35class ISessionResultsPresentation(ILevelReport):
     36
     37    """ Same interface as for level reports.
     38    """
    3039
    3140def get_students(faccode, depcode, session, level=None):
     
    5867                continue
    5968        else:
     69            # XXX: Not yet supported by by generator page
    6070            itemcount = 0
    6171            for item in stud['studycourse'].values():
     
    7383    return table
    7484
     85from reportlab.lib import colors
     86from reportlab.lib.styles import getSampleStyleSheet
     87from reportlab.lib.units import cm
     88from reportlab.platypus import Paragraph, Table, Spacer
     89from reportlab.platypus.flowables import Flowable
     90from waeup.kofa.reports import IReport, IReportGenerator
     91from waeup.kofa.reports import Report
     92from waeup.kofa.browser.interfaces import IPDFCreator
     93from waeup.kofa.university.vocabularies import course_levels
     94
     95STYLE = getSampleStyleSheet()
     96
     97TABLE_STYLE = [
     98    ('FONT', (0,0), (-1,-1), 'Helvetica', 8),
     99    ('FONT', (0,0), (-1,0), 'Helvetica-Bold', 8), # 1st row
     100    ('ALIGN', (3,1), (-1,-1), 'RIGHT'),
     101    #('ALIGN', (1,0), (1,-1), 'LEFT'),
     102    #('ALIGN', (2,0), (2,-1), 'LEFT'),
     103    #('INNERGRID', (0,1), (-1,-1), 0.25, colors.black),
     104    #('BOX', (0,1), (-1,-1), 1, colors.black),
     105    ]
     106
     107@implementer(ISessionResultsPresentation)
     108class SessionResultsPresentation(Report):
     109    data = None
     110    session = None
     111    level = None
     112    faccode = None
     113    depcode = None
     114
     115    def __init__(self, faccode, depcode, session, level, author='System'):
     116        super(SessionResultsPresentation, self).__init__(
     117            args=[faccode, depcode, session, level], kwargs={'author':author})
     118        site = grok.getSite()
     119        self.session = academic_sessions_vocab.getTerm(session).title
     120        self.level = course_levels.getTerm(level).title
     121        self.levelcode = level
     122        self.sessioncode = session
     123        self.faccode = faccode
     124        self.depcode = depcode
     125        self.factitle = site['faculties'][faccode].longtitle()
     126        self.deptitle = site['faculties'][faccode][depcode].longtitle()
     127        self.author = author
     128        self.creation_dt_string = self.creation_dt.astimezone(
     129            getUtility(IKofaUtils).tzinfo).strftime("%Y-%m-%d %H:%M:%S %Z")
     130        self.data = get_students(faccode, depcode, session, level)
     131
     132    def create_pdf(self):
     133        creator = getUtility(IPDFCreator)
     134        #col_widths = [2*cm, 4*cm, 5*cm, 0.8*cm, 0.8*cm, 0.8*cm, 6*cm, ]
     135        pdf_data = [Paragraph('<b>%s</b>' % self.creation_dt_string,
     136                              STYLE["Normal"]),
     137                    Spacer(1, 12),]
     138        pdf_data += [Paragraph('%s<br />%s<br />Level: %s<br />Session: %s' % (
     139                    self.factitle, self.deptitle, self.level, self.session),
     140                    STYLE["Normal"]),
     141                    Spacer(1, 12),]
     142
     143        for table in self.data:
     144            table_data = [('Student Id', 'Matric No.', 'Name')] + table
     145            pdf_data += [
     146                Table(table_data, style=TABLE_STYLE)]    #, colWidths=col_widths)]
     147        doc_title = 'Presentation of Session Results'
     148
     149        pdf_data.append(Spacer(1, 40))
     150        signatures = ['Ag. Head of Department', 'External Examiner', 'Dean of Faculty']
     151        signaturetables = get_signature_tables(signatures)
     152        pdf_data.append(signaturetables[0])
     153
     154        pdf = creator.create_pdf(
     155            pdf_data, None, doc_title, self.author,
     156            'Session Results Presentation %s/%s/%s/%s' % (
     157            self.faccode, self.depcode, self.levelcode, self.sessioncode)
     158            )
     159        return pdf
     160
     161@implementer(IReportGenerator)
     162class SessionResultsPresentationGenerator(grok.GlobalUtility):
     163
     164    title = _('Session Results Presentation')
     165    grok.name('session_results_presentation')
     166
     167    def generate(self, site, faccode=None, depcode=None,
     168                 session=None, level=None, author=None):
     169        result = SessionResultsPresentation(faccode=faccode, depcode=depcode,
     170                             session=session, level=level, author=author)
     171        return result
     172
     173###############################################################
     174## Browser related stuff
     175##
     176## XXX: move to local browser module
     177###############################################################
     178from waeup.kofa.browser.layout import KofaPage
     179from waeup.kofa.interfaces import academic_sessions_vocab
     180from waeup.kofa.reports import get_generators
     181grok.templatedir('browser_templates')
     182class SessionResultsPresentationGeneratorPage(LevelReportGeneratorPage):
     183
     184    grok.context(SessionResultsPresentationGenerator)
     185    grok.template('levelreportgeneratorpage')
     186    label = _('Create session results presentation')
     187
     188class SessionResultsPresentationPDFView(StudentStatisticsReportPDFView):
     189
     190    grok.context(ISessionResultsPresentation)
     191    grok.name('pdf')
     192    grok.require('waeup.Public')
     193    prefix = 'SessionResultsPresentation'
     194
     195    def _filename(self):
     196        return 'SessionResultsPresentation_%s_%s_%s_%s_%s.pdf' % (
     197            self.context.faccode, self.context.depcode,
     198            self.context.sessioncode, self.context.levelcode,
     199            self.context.creation_dt_string)
Note: See TracChangeset for help on using the changeset viewer.