2
# SchoolTool - common information systems platform for school administration
3
# Copyright (c) 2008 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
Evolve database to generation 7.
22
Move message and goal id lists to new contact relationsship properties.
27
from zope.app.generations.utility import findObjectsProviding
28
from zope.app.generations.utility import getRootFolder
29
from zope.component.hooks import getSite, setSite
31
from schooltool.app.interfaces import ISchoolToolApplication
32
from schooltool.contact.interfaces import IContact, IContactable
35
def getContacts(ids, persons):
37
if len(id) > 2 and id[-2] == ':':
46
contacts = [contact for contact in IContactable(person).contacts]
47
if index <= len(contacts):
48
yield contacts[index - 1]
50
yield IContact(person)
53
def fixMessage(message, persons):
54
created = message.created # activate __dict__
55
if 'sender' in message.__dict__:
56
message.created = created # activate persistence
57
sender_id = message.__dict__['sender']
58
del message.__dict__['sender']
59
for contact in getContacts([sender_id], persons):
60
if contact not in message.sender:
61
message.sender.add(contact)
63
if 'recipients' in message.__dict__:
64
message.created = created # activate persistence
65
recipient_ids = message.__dict__['recipients']
66
del message.__dict__['recipients']
67
for contact in getContacts(recipient_ids, persons):
68
if contact not in message.recipients:
69
message.recipients.add(contact)
72
def fixGoal(goal, persons):
73
created = goal.created # activate __dict__
74
if 'creator' in goal.__dict__:
75
goal.created = created # activate persistence
76
creator_id = goal.__dict__['creator']
77
del goal.__dict__['creator']
78
for contact in getContacts([creator_id], persons):
79
if contact not in goal.creator:
80
goal.creator.add(contact)
82
if '_persons_responsible' in goal.__dict__:
83
goal.created = created # activate persistence
84
responsible_ids = goal.__dict__['_persons_responsible']
85
del goal.__dict__['_persons_responsible']
86
for contact in getContacts(responsible_ids, persons):
87
if contact not in goal._persons_responsible:
88
goal._persons_responsible.add(contact)
90
if 'at_one_time_responsible' in goal.__dict__:
91
at_one_time_ids = goal.__dict__['at_one_time_responsible']
92
del goal.__dict__['at_one_time_responsible']
93
for contact in getContacts(at_one_time_ids, persons):
94
goal.at_one_time_responsible.add(contact)
98
root = getRootFolder(context)
100
apps = findObjectsProviding(root, ISchoolToolApplication)
104
interventionRoot = app.get(u'schooltool.interventions', {})
105
persons = app.get('persons', {})
106
for schoolYear in interventionRoot.values():
107
for student in schoolYear.values():
108
for message in student['messages'].values():
109
fixMessage(message, persons)
110
for goal in student['goals'].values():
111
fixGoal(goal, persons)