/usr/lib/python2.7/dist-packages/schooltool/lyceum/journal/generations/evolve3.py is in python-schooltool.lyceum.journal 2.6.3-0ubuntu1.
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 | #
# - common information systems platform for school administration
# Copyright (c) 2013 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/>.
#
"""
Move grades from overlapped journal schedules to respective journals.
"""
from zope.app.generations.utility import findObjectsProviding
from zope.app.publication.zopepublication import ZopePublication
from zope.component.hooks import getSite, setSite
from zope.component import getUtility
from zope.intid.interfaces import IIntIds
from schooltool.app.interfaces import ISchoolToolApplication
from schooltool.app.interfaces import ISchoolToolCalendar
from schooltool.course.interfaces import ISection
from schooltool.person.interfaces import IPerson
from schooltool.lyceum.journal.interfaces import ISectionJournalData
from schooltool.term.interfaces import ITerm
def student_sections(students):
sections = set()
for student in students:
for section in student.groups:
if ISection.providedBy(section):
sections.add(section)
return sections
def adjacent_sections(section):
courses = section.courses
instructors = section.instructors
sections = set()
sections.add(section)
members = [member for member in section.members
if IPerson.providedBy(member)]
for section in student_sections(members):
for course in section.courses:
if course in courses:
for instructor in section.instructors:
if instructor in instructors:
sections.add(section)
break
return sections
def collect_meeting_ids(section):
calendar = ISchoolToolCalendar(section)
unique_meeting_ids = set()
for event in sorted(calendar, key=lambda e: e.dtstart):
entry_id = event.meeting_id
if entry_id is None:
entry_id = event.unique_id
if entry_id not in unique_meeting_ids:
unique_meeting_ids.add(entry_id)
return unique_meeting_ids
def collect_student_names(section):
return set([person.__name__ for person in section.members])
def evolveSectionJournal(section, journal):
if not getattr(journal, '__grade_data__', {}):
return
adjacent_journals = sorted([
(ITerm(adj_sec).first,
ISectionJournalData(adj_sec),
collect_meeting_ids(adj_sec),
collect_student_names(adj_sec))
for adj_sec in adjacent_sections(section)
if ITerm(adj_sec).first > ITerm(section).first
])
for key in journal.__grade_data__:
person_name, grade_date = key
for adj_date, adj_journal, adj_eids, adj_students in reversed(adjacent_journals):
if adj_date > grade_date:
continue # journal starts later then grade recorded
if person_name not in adj_students:
continue # person is not attending this section
# process day records
recorded_entries = list(journal.__grade_data__.get(key, ()))
for eid, entries in recorded_entries:
# is the move possible for this grade?
if eid not in adj_eids:
continue
journal.__grade_data__[key] = tuple([
(k, v)
for k, v in journal.__grade_data__[key]
if k != eid])
if not getattr(adj_journal, '__grade_data__', {}):
continue
adj_journal.__grade_data__[key] = tuple(sorted(
[(k, v)
for k, v in adj_journal.__grade_data__.get(key, ())
if k != eid] +
[(eid, entries)]
))
def evolveJournals(app):
container = app['schooltool.lyceum.journal']
int_ids = getUtility(IIntIds)
for section_id, journal in container.items():
section = int_ids.queryObject(int(section_id))
if section:
evolveSectionJournal(section, journal)
else:
# Section was deleted, delete journal data for it
del container[section_id]
def evolve(context):
root = context.connection.root().get(ZopePublication.root_name, None)
old_site = getSite()
apps = findObjectsProviding(root, ISchoolToolApplication)
for app in apps:
setSite(app)
if 'schooltool.lyceum.journal' in app:
evolveJournals(app)
setSite(old_site)
|