1 | ## $Id: vocabularies.py 9373 2012-10-21 15:49:12Z henrik $ |
---|
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()['hostels'].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 | (_('Bed J'),'J'), |
---|
67 | (_('Bed K'),'K'), |
---|
68 | (_('Bed L'),'L'), |
---|
69 | ) |
---|
70 | |
---|
71 | blocks = SimpleKofaVocabulary( |
---|
72 | (_('Block A'),'A'), |
---|
73 | (_('Block B'),'B'), |
---|
74 | (_('Block C'),'C'), |
---|
75 | (_('Block D'),'D'), |
---|
76 | (_('Block E'),'E'), |
---|
77 | (_('Block F'),'F'), |
---|
78 | (_('Block G'),'G'), |
---|
79 | (_('Block H'),'H'), |
---|
80 | (_('Block I'),'I'), |
---|
81 | (_('Block K'),'K'), |
---|
82 | (_('Block L'),'L'), |
---|
83 | (_('Block M'),'M'), |
---|
84 | (_('Block N'),'N'), |
---|
85 | (_('Block O'),'O'), |
---|
86 | (_('Block P'),'P'), |
---|
87 | (_('Block Q'),'Q'), |
---|
88 | ) |
---|
89 | |
---|
90 | special_handling = SimpleKofaVocabulary( |
---|
91 | (_('Regular Hostel'),'regular'), |
---|
92 | (_('Blocked Hostel'),'blocked'), |
---|
93 | (_('Postgraduate Hostel'),'pg'), |
---|
94 | ) |
---|