2
# SchoolTool - common information systems platform for school administration
3
# Copyright (c) 2010 Shuttleworth Foundation
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
SchoolTool Niepa report card view.
23
from decimal import Decimal
24
from reportlab.platypus.flowables import Flowable
26
from zope.browserpage.viewpagetemplatefile import ViewPageTemplateFile
27
from zope.publisher.browser import BrowserView
28
from zope.security.proxy import removeSecurityProxy
29
from zope.traversing.browser.absoluteurl import absoluteURL
31
from schooltool.app.browser.report import ReportPDFView
32
from schooltool.app.interfaces import ISchoolToolApplication
33
from schooltool.course.interfaces import IInstructor, ISectionContainer
34
from schooltool.group.interfaces import IGroupContainer
35
from schooltool.schoolyear.interfaces import ISchoolYearContainer
36
from schooltool.schoolyear.interfaces import ISchoolYear
37
from schooltool.term.interfaces import ITerm
39
from schooltool.gradebook.interfaces import IActivities
40
from schooltool.requirement.interfaces import IEvaluations
41
from schooltool.requirement.scoresystem import UNSCORED
43
from schooltool.niepa import NiepaMessage as _
46
class RotatedText(Flowable):
48
def __init__(self, text):
55
canvas.drawString(5, -10, self.text)
56
self.canv.restoreState()
60
return canv._leading, canv.stringWidth(self.text)
63
class ReportCardPDFView(ReportPDFView):
64
"""A view for the term's report card pdf"""
66
template=ViewPageTemplateFile('templates/report_card_pdf.pt')
70
self.term = removeSecurityProxy(self.context)
71
self.year = ISchoolYear(self.term)
72
terms = tuple(self.year.values())
73
this_index = terms.index(self.term)
77
for section in ISectionContainer(term).values():
78
courses.add(tuple(section.courses))
79
courses = list(courses)
82
for course in courses:
83
scores = course_accums[course] = []
84
for index in range(this_index + 1):
86
for section in ISectionContainer(term).values():
87
if tuple(section.courses) == course:
91
scores.append(self.getSectionScores(section, term))
93
self.data = course_accums
94
return super(ReportCardPDFView, self).__call__()
96
def getSectionScores(self, section, term):
98
activities = IActivities(section)
99
key = '%s_%s' % (self.year.__name__, term.__name__)
100
worksheet = activities[key]
101
for student in section.members:
102
scores = results[student] = []
103
evaluations = IEvaluations(student)
104
for activity in worksheet.values():
105
ev = evaluations.get(activity, None)
106
if ev is not None and ev.value is not UNSCORED:
115
courses_tuple = [(', '.join([c.title for c in course]), course)
116
for course in self.data]
118
for title, course in sorted(courses_tuple):
119
scores = self.data[course]
120
students = [(student.title, student, scores[-1][student])
121
for student in scores[-1]]
124
for student_title, student, student_scores in sorted(students):
125
ca1 = student_scores[0]
126
ca2 = student_scores[1]
127
ca3 = student_scores[2]
128
ca_total = ca1 + ca2 + ca3
129
exam = student_scores[3]
130
total = ca_total + exam
136
before = Decimal('0')
137
for prev_index in range(len(scores) - 1):
138
for stu, stu_scores in scores[prev_index].items():
140
before += sum(stu_scores)
142
cumulative = int(round((total + before) / 2))
144
cumulative = int(round((total + before) / 3))
145
before = int(round(before / 2))
148
grade, remarks = '', ''
151
'name': student_title,
155
'ca_total': ca_total,
159
'cumulative': cumulative,
165
class_average = Decimal('0')
167
class_average += Decimal(row['cumulative'])
168
class_average = int(round(class_average / len(rows)))
170
row['class_average'] = class_average
172
row_tuples = [(row['cumulative'], row) for row in rows]
173
row_tuples = reversed(sorted(row_tuples))
174
for index, (cumulative, row) in enumerate(row_tuples):
175
row['position'] = index + 1
178
page_rows = rows[:self.per_page]
181
'term': self.term.title,
183
'heights': '0.9cm,3.5cm' + ',0.7cm' * (len(page_rows)),
185
results.append(result)
186
rows = rows[self.per_page:]
191
return '0.8cm,5cm' + ',0.8cm' * 11 + ',4cm'