~ubuntu-branches/ubuntu/raring/schooltool.intervention/raring

« back to all changes in this revision

Viewing changes to src/schooltool/intervention/vocabularies.py

  • Committer: Gediminas Paulauskas
  • Date: 2011-09-19 16:56:45 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: menesis@pov.lt-20110919165645-718diuud5tc4mjsx
Tags: 0.5.0-0ubuntu1
* New upstream release.
* debian/rules: move gradebook to Suggests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#
2
 
# SchoolTool - common information systems platform for school administration
3
 
# Copyright (c) 2007 Shuttleworth Foundation
4
 
#
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.
9
 
#
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.
14
 
#
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
18
 
#
19
 
"""
20
 
Sources and vocabularies for form fields.
21
 
 
22
 
"""
23
 
from zope.component import queryUtility
24
 
from zope.interface import implements
25
 
from zope.schema.interfaces import ITitledTokenizedTerm
26
 
 
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
32
 
 
33
 
 
34
 
class AdvisorTerm(object):
35
 
    """A term for displaying a person."""
36
 
    implements(ITitledTokenizedTerm)
37
 
 
38
 
    def __init__(self, value):
39
 
        if value:
40
 
            person = ISchoolToolApplication(None)['persons'][value]
41
 
            self.title = '%s %s' % (person.first_name, person.last_name)
42
 
        else:
43
 
            self.title = ''
44
 
        self.token = value
45
 
        self.value = value
46
 
 
47
 
 
48
 
class AdvisorVocabulary(object):
49
 
    implements(IBasicPersonVocabulary)
50
 
 
51
 
    def __init__(self, context):
52
 
        self.context = context
53
 
 
54
 
    def __contains__(self, value):
55
 
        return True
56
 
 
57
 
    def __len__(self):
58
 
        return len(self.context.groups)
59
 
 
60
 
    def __iter__(self):
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)
68
 
 
69
 
    def getTermByToken(self, token):
70
 
        return AdvisorTerm(token)
71
 
 
72
 
    def getTerm(self, value):
73
 
        return AdvisorTerm(value)
74
 
 
75
 
 
76
 
def advisorVocabularyFactory():
77
 
    return AdvisorVocabulary