/usr/lib/python2.7/dist-packages/schooltool/gradebook/generations/evolve1.py is in python-schooltool.gradebook 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 | #
# SchoolTool - common information systems platform for school administration
# Copyright (c) 2008 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/>.
#
"""
Evolve database to generation 1.
Moves hard-coded score system utilities to the app site manager.
"""
from zope.app.generations.utility import getRootFolder
from schooltool.gradebook.interfaces import IActivities, IGradebookRoot
from schooltool.gradebook.gradebook_init import setUpGradebookRoot
from schooltool.requirement.interfaces import ICustomScoreSystem
from schooltool.requirement.interfaces import IEvaluations
from schooltool.requirement.scoresystem import CustomScoreSystem, PassFail
from schooltool.requirement.scoresystem import AmericanLetterScoreSystem
from schooltool.requirement.scoresystem import ExtendedAmericanLetterScoreSystem
def updateEvaluations(app, ss, custom_ss):
"""Update all evaluations using the hard-coded score system to use the
newly created custom score system"""
for person in app['persons'].values():
evaluations = IEvaluations(person)
for evaluation in evaluations.values():
if evaluation.scoreSystem == ss:
evaluation.scoreSystem = custom_ss
person._p_changed = True
def updateObjActivities(obj, activities, ss, custom_ss):
"""Update the obj activities using the hard-coded score system to use the
newly created custom score system"""
for worksheet in activities.values():
for activity in worksheet.values():
if activity.scoresystem == ss:
activity.scoresystem = custom_ss
obj._p_changed = True
def updateAllActivities(app, ss, custom_ss):
"""Update all activities using the hard-coded score system to use the
newly created custom score system"""
for sections in app['schooltool.course.section'].values():
for section in sections.values():
updateObjActivities(section, IActivities(section), ss, custom_ss)
root = IGradebookRoot(app)
if root is None:
return
updateObjActivities(root, root.templates, ss, custom_ss)
updateObjActivities(root, root.deployed, ss, custom_ss)
def evolve(context):
"""Migrates hard-coded discrete values score systems found in
schooltool.requirement.scoresystem to the app site manager"""
app = getRootFolder(context)
setUpGradebookRoot(app)
for ss in [PassFail, AmericanLetterScoreSystem,
ExtendedAmericanLetterScoreSystem]:
custom_ss = CustomScoreSystem(ss.title, ss.description, ss.scores,
ss._bestScore, ss._minPassingScore)
app.getSiteManager().registerUtility(custom_ss, ICustomScoreSystem,
name=custom_ss.title)
updateEvaluations(app, ss, custom_ss)
updateAllActivities(app, ss, custom_ss)
|