Changeset 10567 for main/waeup.kofa


Ignore:
Timestamp:
30 Aug 2013, 07:39:36 (11 years ago)
Author:
Henrik Bettermann
Message:

Beautify table. Try to rotate text in header. ToDo?: Adjust column width.

File:
1 edited

Legend:

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

    r10565 r10567  
    7070from reportlab.lib.units import cm
    7171from reportlab.platypus import Paragraph, Table, Spacer
     72from reportlab.platypus.flowables import Flowable
    7273from waeup.kofa.reports import IReport, IReportGenerator
    7374from waeup.kofa.reports import Report
     
    7778STYLE = getSampleStyleSheet()
    7879
     80class TTR(Flowable): #TableTextRotate
     81    '''Rotates a text in a table cell.'''
     82
     83    def __init__(self, text):
     84        Flowable.__init__(self)
     85        self.text=text
     86
     87    def draw(self):
     88        canvas = self.canv
     89        canvas.rotate(45)
     90        canvas.drawString( 0, -1, self.text)
     91
     92    #def wrap(self,aW,aH):
     93    #    canv = self.canv
     94    #    return canv._leading, canv.stringWidth(self.text)
     95
    7996def tbl_data_to_table(data):
    8097    result = []
    81     new_col_names = ('Student Id', _('Matric No.'), _('Name') ,
    82                      _('Total Credits'), _('Total Credits Passed'),
    83                      _('GPA'), _('Courses Failed'))
    84     table = [new_col_names]
     98    col_names = ('Student Id', 'Matric No.', 'Name',
     99                     TTR('Total Credits'), TTR('Total Credits Passed'),
     100                     'GPA', 'Courses Failed')
     101    table = [col_names]
    85102    for line in data:
    86103        table.append(line)
     
    89106TABLE_STYLE = [
    90107    ('FONT', (0,0), (-1,-1), 'Helvetica', 8),
    91     ('FONT', (0,0), (0,-1), 'Helvetica-Bold', 8),
    92     ('FONT', (0,0), (-1,0), 'Helvetica-Bold', 8),
    93     ('FONT', (0,-1), (-1,-1), 'Helvetica-Bold', 8),
    94     ('FONT', (-1,0), (-1,-1), 'Helvetica-Bold', 8),
     108    #('FONT', (0,0), (0,-1), 'Helvetica-Bold', 8), # 1st column
     109    ('FONT', (0,0), (-1,0), 'Helvetica-Bold', 8), # 1st row
     110    #('FONT', (0,-1), (-1,-1), 'Helvetica-Bold', 8), # last row
     111    #('FONT', (-1,0), (-1,-1), 'Helvetica-Bold', 8), # last column
    95112    ('ALIGN', (1,1), (-1,-1), 'RIGHT'),
    96     ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
    97     ('LINEBELOW', (0,-1), (-1,-1), 0.25, colors.black),
    98     ('LINEAFTER', (-1,0), (-1,-1), 0.25, colors.black),
    99     ('LINEBEFORE', (-1,0), (-1,-1), 1.0, colors.black),
    100     #('LINEABOVE', (0,-1), (-1,-1), 1.0, colors.black),
    101     #('LINEABOVE', (0,0), (-1,0), 0.25, colors.black),
    102     ('BOX', (0,0), (-1,-1), 1, colors.black),
     113    ('ALIGN', (2,0), (2,-1), 'LEFT'),
     114    ('INNERGRID', (0,1), (-1,-1), 0.25, colors.black),
     115    ('BOX', (0,1), (-1,-1), 1, colors.black),
    103116    ]
    104117
     
    140153                    Spacer(1, 12),]
    141154        pdf_data += [
    142             Table(table_data, style=TABLE_STYLE)]   #, colWidths=col_widths)]
     155            Table(table_data, style=TABLE_STYLE)] #, colWidths=col_widths)]
    143156        doc_title = 'Level Report'
    144157        pdf = creator.create_pdf(
Note: See TracChangeset for help on using the changeset viewer.