Changeset 12563


Ignore:
Timestamp:
6 Feb 2015, 14:14:00 (10 years ago)
Author:
Henrik Bettermann
Message:

Beatify table.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/students/reports
Files:
2 edited

Legend:

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

    r12562 r12563  
    5555    site = grok.getSite()
    5656    payment_cats = ('clearance', 'gown', 'hostel_maintenance', 'schoolfee')
    57     payment_cats = payment_cats + (u'Total',)
     57    payment_cats = payment_cats + ('Total',)
    5858    if breakdown == 'faccode':
    5959        codes = tuple(sorted([x for x in site['faculties'].keys()],
     
    6767        codes = tuple(sorted([x for x in depcodes],
    6868                                 key=lambda x: x.lower()))
    69     codes = codes + ('Total',)
     69    codes = codes + (u'Total',)
    7070    # XXX: Here we do _one_ query and then examine the single
    7171    #   students. One could also do multiple queries and just look for
     
    109109    # Build table header
    110110    utils = getUtility(IKofaUtils)
    111     table_header = ['' for x in xrange(2*len(payment_cats))]
     111
     112
     113    table_header = ['' for x in xrange(len(payment_cats))]
    112114    for cat in payment_cats:
    113115        cat_title = utils.PAYMENT_CATEGORIES.get(cat, cat)
    114         table_header[2*payment_cats.index(cat)] = cat_title
    115     # turn lists into tuples
     116        table_header[payment_cats.index(cat)] = cat_title
     117
     118    # Convert float into int
     119    table = [[int(col) for col in row] for row in table]
     120    # Turn lists into tuples
    116121    table = tuple([tuple(row) for row in table])
    117122    return (codes, table_header, table)
     
    124129from waeup.kofa.reports import Report
    125130from waeup.kofa.browser.interfaces import IPDFCreator
     131from waeup.kofa.students.reports.level_report import TTR
    126132
    127133from waeup.kofa.students.reports.student_statistics import (
    128134    tbl_data_to_table, STYLE)
    129135
     136def tbl_data_to_table(row_names, col_names, data):
     137    result = []
     138    new_col_names = []
     139    for name in col_names:
     140        if len(name) > 18:
     141            new_col_names.append(name.replace(' ', '\n', 1))
     142        else:
     143            new_col_names.append(name)
     144    head = [''] + [col_name for col_name in new_col_names]
     145    result = [head]
     146    for idx, row_name in enumerate(row_names):
     147        row = []
     148        i = 0
     149        while i < len(data[idx]):
     150            row.append("%s (%s)" % (data[idx][i+1], data[idx][i]))
     151            i += 2
     152        row = [row_name] + row
     153        result.append(row)
     154    return result
    130155
    131156TABLE_STYLE = [
     
    136161    ('FONT', (-1,0), (-1,-1), 'Helvetica-Bold', 8),
    137162    ('ALIGN', (1,1), (-1,-1), 'RIGHT'),
    138     ('INNERGRID', (0,1), (-1,-1), 0.25, colors.black),
     163    ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black),
    139164    ('LINEBELOW', (0,-1), (-1,-1), 0.25, colors.black),
    140     ('LINEAFTER', (-1,1), (-1,-1), 0.25, colors.black),
    141     ('LINEBEFORE', (-1,1), (-1,-1), 0.25, colors.black),
     165    ('LINEAFTER', (-1,0), (-1,-1), 0.25, colors.black),
     166    ('LINEBEFORE', (-1,0), (-1,-1), 0.25, colors.black),
    142167    #('LINEABOVE', (0,-1), (-1,-1), 1.0, colors.black),
    143168    #('LINEABOVE', (0,0), (-1,0), 0.25, colors.black),
     
    164189        creator = getUtility(IPDFCreator, name='landscape')
    165190        table_data = tbl_data_to_table(*self.data)
    166         col_widths = [None,] + [1.6*cm] * len(self.data[1]) + [None,]
     191        col_widths = [None,] + [3.2*cm] * len(self.data[1]) + [None,]
    167192        pdf_data = [Paragraph('<b>%s</b>' % self.creation_dt_string,
    168193                              STYLE["Normal"]),
  • main/waeup.kofa/trunk/src/waeup/kofa/students/reports/tests/test_student_payment_statistics.py

    r12562 r12563  
    3434            result1,
    3535            ((u'fac1', u'Total'),
    36              ['Acceptance Fee', '', 'Gown Hire Fee', '',
    37               'Hostel Maintenance Fee', '', 'School Fee', '',
    38               'Total', ''],
    39               ((0, 0, 0, 0, 0, 0, 1, 5.678, 1, 5.678),
    40               (0, 0, 0, 0, 0, 0, 1, 5.678, 1, 5.678)))
     36             ['Acceptance Fee', 'Gown Hire Fee',
     37              'Hostel Maintenance Fee', 'School Fee',
     38              'Total'],
     39              ((0, 0, 0, 0, 0, 0, 1, 5, 1, 5),
     40              (0, 0, 0, 0, 0, 0, 1, 5, 1, 5)))
    4141            )
    4242        self.assertEqual(
    4343            result2,
    4444            ((u'fac1', u'Total'),
    45              ['Acceptance Fee', '', 'Gown Hire Fee', '',
    46               'Hostel Maintenance Fee', '', 'School Fee', '',
    47               'Total', ''],
     45             ['Acceptance Fee', 'Gown Hire Fee',
     46              'Hostel Maintenance Fee', 'School Fee',
     47              'Total'],
    4848              ((0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
    4949              (0, 0, 0, 0, 0, 0, 0, 0, 0, 0)))
Note: See TracChangeset for help on using the changeset viewer.