Changeset 10557 for main/waeup.kofa/trunk/src/waeup
- Timestamp:
- 29 Aug 2013, 09:52:11 (11 years ago)
- 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/level_report.py
r10553 r10557 65 65 table.append(line) 66 66 return table 67 68 from reportlab.lib import colors 69 from reportlab.lib.styles import getSampleStyleSheet 70 from reportlab.lib.units import cm 71 from reportlab.platypus import Paragraph, Table, Spacer 72 from reportlab.lib.pagesizes import A4, landscape 73 from waeup.kofa.reports import IReport, IReportGenerator 74 from waeup.kofa.reports import Report 75 from waeup.kofa.browser.interfaces import IPDFCreator 76 from waeup.kofa.university.vocabularies import course_levels 77 78 STYLE = getSampleStyleSheet() 79 80 def tbl_data_to_table(data): 81 result = [] 82 new_col_names = ('Student Id', _('Matric No.'), _('Name') , 83 _('Total Credits'), _('Total Credits Passed'), 84 _('GPA'), _('Courses Failed')) 85 table = [new_col_names] 86 for line in data: 87 table.append(line) 88 return table 89 90 TABLE_STYLE = [ 91 ('FONT', (0,0), (-1,-1), 'Helvetica', 8), 92 ('FONT', (0,0), (0,-1), 'Helvetica-Bold', 8), 93 ('FONT', (0,0), (-1,0), 'Helvetica-Bold', 8), 94 ('FONT', (0,-1), (-1,-1), 'Helvetica-Bold', 8), 95 ('FONT', (-1,0), (-1,-1), 'Helvetica-Bold', 8), 96 ('ALIGN', (1,1), (-1,-1), 'RIGHT'), 97 ('INNERGRID', (0,0), (-1,-1), 0.25, colors.black), 98 ('LINEBELOW', (0,-1), (-1,-1), 0.25, colors.black), 99 ('LINEAFTER', (-1,0), (-1,-1), 0.25, colors.black), 100 ('LINEBEFORE', (-1,0), (-1,-1), 1.0, colors.black), 101 #('LINEABOVE', (0,-1), (-1,-1), 1.0, colors.black), 102 #('LINEABOVE', (0,0), (-1,0), 0.25, colors.black), 103 ('BOX', (0,0), (-1,-1), 1, colors.black), 104 ] 105 106 @implementer(ILevelReport) 107 class LevelReport(Report): 108 data = None 109 session = None 110 level = None 111 faccode = None 112 depcode = None 113 114 def __init__(self, faccode, depcode, session, level, author='System'): 115 super(LevelReport, self).__init__( 116 args=[faccode, depcode, session, level], kwargs={'author':author}) 117 site = grok.getSite() 118 self.session = academic_sessions_vocab.getTerm(session).title 119 self.level = course_levels.getTerm(level).title 120 self.levelcode = level 121 self.sessioncode = session 122 self.faccode = faccode 123 self.depcode = depcode 124 self.factitle = site['faculties'][faccode].longtitle() 125 self.deptitle = site['faculties'][faccode][depcode].longtitle() 126 self.author = author 127 self.creation_dt_string = self.creation_dt.astimezone( 128 getUtility(IKofaUtils).tzinfo).strftime("%Y-%m-%d %H:%M:%S %Z") 129 self.data = get_students_by(faccode, depcode, session, level) 130 131 def create_pdf(self): 132 creator = getUtility(IPDFCreator) 133 table_data = tbl_data_to_table(self.data) 134 #col_widths = [3.5*cm] * len(self.data[0]) 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 pdf_data += [ 143 Table(table_data, style=TABLE_STYLE)] #, colWidths=col_widths)] 144 doc_title = 'Level Report' 145 pdf = creator.create_pdf( 146 pdf_data, None, doc_title, self.author, 147 'Level Report %s/%s/%s/%s' % ( 148 self.faccode, self.depcode, self.levelcode, self.sessioncode), 149 pagesize=landscape(A4)) 150 return pdf -
main/waeup.kofa/trunk/src/waeup/kofa/students/reports/tests/test_level_report.py
r10553 r10557 5 5 from waeup.kofa.interfaces import IJobManager 6 6 from waeup.kofa.students.reports.level_report import ( 7 get_students_by )7 get_students_by, LevelReport) 8 8 from waeup.kofa.students.tests.test_catalog import CatalogTestSetup 9 9 from waeup.kofa.students.tests.test_browser import StudentsFullSetup 10 10 from waeup.kofa.testing import FunctionalLayer 11 11 from waeup.kofa.tests.test_async import FunctionalAsyncTestCase 12 from waeup.kofa.browser.tests.test_pdf import samples_dir 12 13 13 14 class LevelReportTests(CatalogTestSetup): … … 21 22 [(u'K1000000', u'1234', u'Bob Tester', 30, 30, 5.0, [])]) 22 23 return 24 25 def test_create_pdf(self): 26 report = LevelReport('fac1', 'dep1', 2010, 100) 27 result = report.create_pdf() 28 self.assertTrue(result.startswith('%PDF-')) 29 path = os.path.join(samples_dir(), 'level_report.pdf') 30 open(path, 'wb').write(result) 31 print "Sample level_report.pdf written to %s" % path 32 return
Note: See TracChangeset for help on using the changeset viewer.