1 | ## $Id: vocabularies.py 7811 2012-03-08 19:00:51Z uli $ |
---|
2 | ## |
---|
3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
4 | ## This program is free software; you can redistribute it and/or modify |
---|
5 | ## it under the terms of the GNU General Public License as published by |
---|
6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
7 | ## (at your option) any later version. |
---|
8 | ## |
---|
9 | ## This program is distributed in the hope that it will be useful, |
---|
10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
12 | ## GNU General Public License for more details. |
---|
13 | ## |
---|
14 | ## You should have received a copy of the GNU General Public License |
---|
15 | ## along with this program; if not, write to the Free Software |
---|
16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
17 | ## |
---|
18 | """Vocabularies and sources for the accommodation section. |
---|
19 | """ |
---|
20 | from grok import getSite |
---|
21 | from zope.component import getUtility |
---|
22 | from zope.catalog.interfaces import ICatalog |
---|
23 | from zc.sourcefactory.contextual import BasicContextualSourceFactory |
---|
24 | from waeup.kofa.interfaces import SimpleKOFAVocabulary |
---|
25 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
26 | |
---|
27 | NOT_OCCUPIED = u'not occupied' |
---|
28 | |
---|
29 | class StudentSource(BasicContextualSourceFactory): |
---|
30 | """A students source delivers all students in accommodation session. |
---|
31 | """ |
---|
32 | |
---|
33 | def acco_students(self, context): |
---|
34 | catalog = getUtility(ICatalog, name='students_catalog') |
---|
35 | accommodation_session = getSite()['configuration'].accommodation_session |
---|
36 | students = catalog.searchResults(current_session=( |
---|
37 | accommodation_session,accommodation_session)) |
---|
38 | existing_students = [ |
---|
39 | context.__parent__[key].owner |
---|
40 | for key in context.__parent__.keys()] |
---|
41 | students = [student for student in students |
---|
42 | if not student.student_id in existing_students] |
---|
43 | students = sorted(list(students), |
---|
44 | key=lambda value: value.student_id) |
---|
45 | return dict([(student.student_id,student.fullname) for student in students]) |
---|
46 | |
---|
47 | def getValues(self, context): |
---|
48 | return self.acco_students(context).keys() |
---|
49 | |
---|
50 | def getToken(self, context, value): |
---|
51 | return value |
---|
52 | |
---|
53 | def getTitle(self, context, value): |
---|
54 | return "%s - %s" % (value, self.acco_students(context)[value]) |
---|
55 | |
---|
56 | bed_letters = SimpleKOFAVocabulary( |
---|
57 | (_('Bed A'),'A'), |
---|
58 | (_('Bed B'),'B'), |
---|
59 | (_('Bed C'),'C'), |
---|
60 | (_('Bed D'),'D'), |
---|
61 | (_('Bed E'),'E'), |
---|
62 | (_('Bed F'),'F'), |
---|
63 | (_('Bed G'),'G'), |
---|
64 | (_('Bed H'),'H'), |
---|
65 | (_('Bed I'),'I'), |
---|
66 | ) |
---|
67 | |
---|
68 | blocks = SimpleKOFAVocabulary( |
---|
69 | (_('Block A'),'A'), |
---|
70 | (_('Block B'),'B'), |
---|
71 | (_('Block C'),'C'), |
---|
72 | (_('Block D'),'D'), |
---|
73 | (_('Block E'),'E'), |
---|
74 | (_('Block F'),'F'), |
---|
75 | (_('Block G'),'G'), |
---|
76 | (_('Block H'),'H'), |
---|
77 | (_('Block I'),'I'), |
---|
78 | (_('Block K'),'K'), |
---|
79 | (_('Block L'),'L'), |
---|
80 | (_('Block M'),'M'), |
---|
81 | (_('Block N'),'N'), |
---|
82 | (_('Block O'),'O'), |
---|
83 | (_('Block P'),'P'), |
---|
84 | ) |
---|
85 | |
---|
86 | special_handling = SimpleKOFAVocabulary( |
---|
87 | (_('Regular Hostel'),'regular'), |
---|
88 | (_('Blocked Hostel'),'blocked'), |
---|
89 | (_('Postgraduate Hostel'),'pg'), |
---|
90 | ) |
---|