This file is indexed.

/usr/lib/python2.7/dist-packages/schooltool/lyceum/journal/browser/student.py is in python-schooltool.lyceum.journal 2.6.4-0ubuntu2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
#
# SchoolTool - common information systems platform for school administration
# Copyright (c) 2007 Shuttleworth Foundation
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
"""
Lyceum student journal views.
"""
import urllib

from zope.browserpage.viewpagetemplatefile import ViewPageTemplateFile
from zope.component import queryMultiAdapter
from zope.i18n import translate
from zope.interface import implements
from zope.traversing.browser.absoluteurl import absoluteURL

from zc.table.interfaces import IColumn

from schooltool.term.interfaces import ITermContainer
from schooltool.table.interfaces import ITableFormatter
from schooltool.course.interfaces import ICourseContainer
from schooltool.course.interfaces import ILearner
from schooltool.requirement.scoresystem import UNSCORED

from schooltool.lyceum.journal.browser.journal import LyceumSectionJournalView
from schooltool.lyceum.journal.interfaces import ISectionJournalData
from schooltool.lyceum.journal import LyceumMessage as _


class CourseGradesColumn(object):
    implements(IColumn)

    def __init__(self, date, student, courses):
        self.date = date
        self.name = date.strftime("%d")
        self.student = student
        self.courses = courses

    def renderCell(self, course, formatter):
        grades = []
        for section in self.courses[course.__name__]:
            journal = ISectionJournalData(section)
            for meeting, score in journal.gradedMeetings(self.student):
                if meeting.dtstart.date() == self.date:
                    if score:
                        grades.append(unicode(score.value))

        return ", ".join(grades)

    def renderHeader(self, formatter):
        return '<span title="%s">%s</span>' % (
            self.date.strftime("%Y-%m-%d"), self.date.strftime("%d"))


class CourseTermAverageGradesColumn(object):

    def __init__(self, term, student, courses):
        self.term = term
        self.name = term.__name__ + "average"
        self.courses = courses
        self.student = student

    def courseGrades(self, course):
        grades = []
        for section in self.courses[course.__name__]:
            journal = ISectionJournalData(section)
            for meeting, score in journal.gradedMeetings(self.student):
                if meeting.dtstart.date() in self.term:
                    if score:
                        grade = score.value
                        try:
                            grade = score.scoreSystem.getNumericalValue(grade)
                        except ValueError:
                            continue
                        grades.append(grade)
        return grades

    def renderCell(self, course, formatter):
        grades = self.courseGrades(course)
        if grades:
            return "%.3f" % (sum(grades) / len(grades))

        return ""

    def renderHeader(self, formatter):
        return '<span>%s</span>' % translate(_("Average"),
                                             context=formatter.request)


class LyceumStudentJournalView(LyceumSectionJournalView):
    """A view for a student journal."""

    template = ViewPageTemplateFile("templates/student_journal.pt")

    def __init__(self, context, request):
        self.context, self.request = context, request
        self.courses = set()
        learner = ILearner(self.context)
        for section in learner.sections():
            for course in section.courses:
                self.courses.add(course)

    def __call__(self):
        term = self.getSelectedTerm()
        course_container = ICourseContainer(term)
        self.gradebook = queryMultiAdapter((course_container, self.request),
                                           ITableFormatter)
        self.gradebook.setUp(items=self.courses,
                             columns_after=self.gradeColumns(),
                             batch_size=0)
        return self.template()

    def allMeetings(self):
        for date in self.getSelectedTerm():
            yield date

    def meetings(self):
        for meeting in self.allMeetings():
            if meeting.month == self.active_month:
                yield meeting

    def gradeColumns(self):
        columns = []

        learner = ILearner(self.context)
        courses = {}
        for section in learner.sections():
            for course in section.courses:
                courses.setdefault(course.__name__, [])
                courses[course.__name__].append(section)

        for meeting in self.meetings():
            columns.append(CourseGradesColumn(meeting, self.context, courses))
        columns.append(CourseTermAverageGradesColumn(self.getSelectedTerm(),
                                                     self.context, courses))
        return columns

    @property
    def scheduled_terms(self):
        terms = ITermContainer(self.context)
        scheduled_terms = list(terms.values())
        return sorted(scheduled_terms, key=lambda t: t.last)

    def monthsInSelectedTerm(self):
        month = -1
        for meeting in self.allMeetings():
            if meeting.month != month:
                yield meeting.month
                month = meeting.month

    def monthURL(self, month_id):
        url = absoluteURL(self.context, self.request)
        url = "%s/gradebook.html?%s" % (
            url,
            urllib.urlencode([('month', month_id)] +
                             self.extra_parameters(self.request)))
        return url