2
# SchoolTool - common information systems platform for school administration
3
# Copyright (c) 2005 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
21
from persistent import Persistent
22
from datetime import datetime
25
from zope.container.contained import NameChooser
26
from zope.container.interfaces import INameChooser
27
from zope.component import queryUtility, getMultiAdapter
28
from zope.component import adapter, adapts
29
from zope.interface import implementer, implements
30
from zope.lifecycleevent.interfaces import IObjectRemovedEvent
31
from zope.security.proxy import removeSecurityProxy
32
from zope.traversing.api import getParent
34
from schooltool.app.app import InitBase, StartUpBase
35
from schooltool.app.interfaces import ISchoolToolApplication
36
from schooltool.contact.interfaces import IContactable, IContact
37
from schooltool.person.interfaces import IPerson
38
from schooltool.schoolyear.interfaces import ISchoolYear, ISchoolYearContainer
39
from schooltool.schoolyear.subscriber import ObjectEventAdapterSubscriber
40
from schooltool.term.interfaces import IDateManager
42
import interfaces, intervention
45
def setUpInterventions(app):
46
app[u'schooltool.interventions'] = intervention.InterventionRoot()
49
class InterventionStartup(StartUpBase):
51
if u'schooltool.interventions' not in self.app:
52
setUpInterventions(self.app)
55
class InterventionInit(InitBase):
56
"""Create the InterventionRoot object."""
59
setUpInterventions(self.app)
62
@adapter(ISchoolToolApplication)
63
@implementer(interfaces.IInterventionRoot)
64
def getInterventionRoot(app):
65
return app[u'schooltool.interventions']
69
@implementer(interfaces.IInterventionSchoolYear)
70
def getSchoolYearInterventionSchoolYear(schoolyear):
71
app = ISchoolToolApplication(None)
72
interventionRoot = interfaces.IInterventionRoot(app)
74
interventionSchoolYear = interventionRoot[schoolyear.__name__]
76
interventionSchoolYear = intervention.InterventionSchoolYear()
77
interventionRoot[schoolyear.__name__] = interventionSchoolYear
78
return interventionSchoolYear
81
@adapter(ISchoolToolApplication)
82
@implementer(interfaces.IInterventionSchoolYear)
83
def getSchoolToolApplicationInterventionSchoolYear(app):
84
term = queryUtility(IDateManager).current_term
85
schoolyear = ISchoolYear(term)
86
return interfaces.IInterventionSchoolYear(schoolyear)
89
@adapter(interfaces.IInterventionSchoolYear)
90
@implementer(ISchoolYear)
91
def getInterventionSchoolYearSchoolYear(schoolyear):
92
app = ISchoolToolApplication(None)
93
return ISchoolYearContainer(app)[schoolyear.__name__]
96
@adapter(interfaces.IInterventionMarker)
97
@implementer(interfaces.IInterventionStudent)
98
def getMarkerInterventionStudent(marker):
99
return interfaces.IInterventionStudent(marker.__parent__.__parent__)
102
@adapter(IPerson, ISchoolYear)
103
@implementer(interfaces.IInterventionStudent)
104
def getStudentYearInterventionStudent(student, schoolyear):
105
interventionSchoolYear = interfaces.IInterventionSchoolYear(schoolyear)
107
interventionStudent = interventionSchoolYear[student.__name__]
109
interventionStudent = intervention.InterventionStudent()
110
interventionSchoolYear[student.__name__] = interventionStudent
111
interventionStudent[u'messages'] = intervention.InterventionMessages()
112
interventionStudent[u'goals'] = intervention.InterventionGoals()
113
return interventionStudent
117
@implementer(interfaces.IInterventionStudent)
118
def getStudentInterventionStudent(student):
119
app = ISchoolToolApplication(None)
120
interventionSchoolYear = interfaces.IInterventionSchoolYear(app)
121
schoolyear = ISchoolYear(interventionSchoolYear)
122
interventionStudent = getMultiAdapter((student, schoolyear),
123
interfaces.IInterventionStudent)
124
return interventionStudent
127
@adapter(interfaces.IStudentSchoolYearProxy)
128
@implementer(interfaces.IInterventionStudent)
129
def getSchoolYearProxyInterventionStudent(proxy):
130
student = proxy.__parent__.__parent__
131
app = ISchoolToolApplication(None)
132
schoolyear = ISchoolYearContainer(app)[proxy.__name__]
133
interventionStudent = getMultiAdapter((student, schoolyear),
134
interfaces.IInterventionStudent)
135
return interventionStudent
138
@adapter(interfaces.IInterventionStudent)
139
@implementer(IPerson)
140
def getInterventionStudentStudent(interventionStudent):
141
persons = ISchoolToolApplication(None)['persons']
142
return persons[interventionStudent.__name__]
145
@adapter(interfaces.IInterventionMessages)
146
@implementer(IPerson)
147
def getInterventionMessagesStudent(interventionMessages):
148
return IPerson(interventionMessages.__parent__)
151
@adapter(interfaces.IInterventionMessage)
152
@implementer(IPerson)
153
def getInterventionMessageStudent(interventionMessage):
154
return IPerson(interventionMessage.__parent__)
157
@adapter(interfaces.IInterventionGoals)
158
@implementer(IPerson)
159
def getInterventionGoalsStudent(interventionGoals):
160
return IPerson(interventionGoals.__parent__)
163
@adapter(interfaces.IInterventionGoal)
164
@implementer(IPerson)
165
def getInterventionGoalStudent(interventionGoal):
166
return IPerson(interventionGoal.__parent__)
169
@adapter(interfaces.ISectionMessagesProxy)
170
@implementer(IPerson)
171
def getSectionMessagesProxyStudent(proxy):
172
return removeSecurityProxy(proxy).student
175
@adapter(interfaces.IStudentMessagesGoalsProxy)
176
@implementer(IPerson)
177
def getSectionMessagesGoalsProxyStudent(proxy):
178
return removeSecurityProxy(proxy.__parent__.__parent__).student
181
def getInterventionSchoolYearFromObj(obj):
182
while not interfaces.IInterventionSchoolYear.providedBy(obj):
183
if interfaces.IStudentSchoolYearProxy.providedBy(obj):
189
class SequenceNumberNameChooser(NameChooser):
190
"""A name chooser that returns a sequence number."""
192
implements(INameChooser)
194
def chooseName(self, name, obj):
195
"""See INameChooser."""
196
numbers = [int(v.__name__) for v in self.context.values()
197
if v.__name__.isdigit()]
199
n = str(max(numbers) + 1)
202
self.checkName(n, obj)
206
class PersonRemovedSubsciber(ObjectEventAdapterSubscriber):
207
adapts(IObjectRemovedEvent, IPerson)
210
app = ISchoolToolApplication(None)
211
interventionRoot = app[u'schooltool.interventions']
212
for schoolYear in interventionRoot.values():
213
if self.object.username in schoolYear:
214
del schoolYear[self.object.username]
217
class SchoolYearRemovedSubsciber(ObjectEventAdapterSubscriber):
218
adapts(IObjectRemovedEvent, ISchoolYear)
221
app = ISchoolToolApplication(None)
222
interventionRoot = app[u'schooltool.interventions']
223
if self.object.__name__ in interventionRoot:
224
del interventionRoot[self.object.__name__]