2
# SchoolTool - common information systems platform for school administration
3
# Copyright (c) 2007 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
Sources and vocabularies for form fields.
23
from zope.component import queryUtility
24
from zope.interface import implements
25
from zope.schema.interfaces import ITitledTokenizedTerm
27
from schooltool.app.interfaces import ISchoolToolApplication
28
from schooltool.basicperson.interfaces import IBasicPersonVocabulary
29
from schooltool.group.interfaces import IGroupContainer
30
from schooltool.schoolyear.interfaces import ISchoolYear
31
from schooltool.term.interfaces import IDateManager
34
class AdvisorTerm(object):
35
"""A term for displaying a person."""
36
implements(ITitledTokenizedTerm)
38
def __init__(self, value):
40
person = ISchoolToolApplication(None)['persons'][value]
41
self.title = '%s %s' % (person.first_name, person.last_name)
48
class AdvisorVocabulary(object):
49
implements(IBasicPersonVocabulary)
51
def __init__(self, context):
52
self.context = context
54
def __contains__(self, value):
58
return len(self.context.groups)
61
term = queryUtility(IDateManager).current_term
62
groups = IGroupContainer(ISchoolYear(term))
63
persons = set(groups['teachers'].members).union(
64
set(groups['administrators'].members))
65
persons = sorted(persons, key=lambda p: (p.last_name, p.first_name))
66
for person in persons:
67
yield AdvisorTerm(person.username)
69
def getTermByToken(self, token):
70
return AdvisorTerm(token)
72
def getTerm(self, value):
73
return AdvisorTerm(value)
76
def advisorVocabularyFactory():
77
return AdvisorVocabulary