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

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Gediminas Paulauskas
  • Date: 2011-02-24 17:10:33 UTC
  • Revision ID: james.westby@ubuntu.com-20110224171033-8wflfqxxe3zld6bf
Tags: upstream-0.4.2
ImportĀ upstreamĀ versionĀ 0.4.2

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) 2005 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
from zope.catalog.interfaces import ICatalog
 
21
from zope.component import getUtility
 
22
from zope.security.proxy import removeSecurityProxy
 
23
 
 
24
from zc.catalog.catalogindex import ValueIndex
 
25
from zc.catalog.extentcatalog import Catalog
 
26
from zc.catalog.extentcatalog import FilterExtent
 
27
 
 
28
from schooltool.table.catalog import ConvertingIndex
 
29
from schooltool.table.catalog import FilterImplementing
 
30
from schooltool.utility.utility import UtilitySetUp
 
31
 
 
32
import interfaces
 
33
 
 
34
 
 
35
INTERVENTION_CATALOG_KEY = 'schooltool.intervention'
 
36
 
 
37
 
 
38
def catalogFactory():
 
39
    return Catalog(FilterExtent(FilterImplementing(
 
40
        interfaces.IInterventionMarker)))
 
41
 
 
42
 
 
43
def catalogSetUp(catalog):
 
44
    catalog['first_name'] = ConvertingIndex(converter=getStudentFirstName)
 
45
    catalog['last_name'] = ConvertingIndex(converter=getStudentLastName)
 
46
    catalog['persons_responsible'] = ConvertingIndex(
 
47
        converter=interfaces.IInterventionPersonsResponsible)
 
48
    catalog['created'] = ValueIndex('created')
 
49
    catalog['schoolYearId'] = ConvertingIndex(converter=getSchoolYearId)
 
50
    catalog['intervention_type'] = ConvertingIndex(
 
51
        converter=interfaces.IInterventionType)
 
52
 
 
53
 
 
54
catalogSetUpSubscriber = UtilitySetUp(
 
55
    catalogFactory, ICatalog, INTERVENTION_CATALOG_KEY, setUp=catalogSetUp)
 
56
 
 
57
 
 
58
def getInterventionCatalog(container):
 
59
    return getUtility(ICatalog, INTERVENTION_CATALOG_KEY)
 
60
 
 
61
 
 
62
def getStudentFirstName(obj):
 
63
    return obj.student.first_name
 
64
 
 
65
 
 
66
def getStudentLastName(obj):
 
67
    return obj.student.last_name
 
68
 
 
69
 
 
70
def getMessagePersonsResponsible(obj):
 
71
    return obj.recipients
 
72
 
 
73
 
 
74
def getGoalPersonsResponsible(obj):
 
75
    # XXX not using removeSecurityProxy caused ZODB to crash
 
76
    # Cannot pickle <type 'zope.security._proxy._Proxy'> objects
 
77
    return removeSecurityProxy(obj.persons_responsible)
 
78
 
 
79
 
 
80
def getMessageType(obj):
 
81
    return 'message'
 
82
 
 
83
 
 
84
def getGoalType(obj):
 
85
    return 'goal'
 
86
 
 
87
 
 
88
def getSchoolYearId(obj):
 
89
    sy = interfaces.IInterventionSchoolYear(obj)
 
90
    return sy.__name__
 
91
 
 
92
 
 
93
def messageGetter(obj):
 
94
    value = obj.body
 
95
    if len(value) > 50:
 
96
        value = value[:47] + '...'
 
97
    return value
 
98
 
 
99
 
 
100
def goalGetter(obj):
 
101
    value = obj.presenting_concerns
 
102
    if len(value) > 50:
 
103
        value = value[:47] + '...'
 
104
    return value
 
105