1 | ## $Id: vocabularies.py 7321 2011-12-10 06:15:17Z 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.sirp.interfaces import SimpleSIRPVocabulary |
---|
25 | |
---|
26 | NOT_OCCUPIED = u'not occupied' |
---|
27 | |
---|
28 | class StudentSource(BasicContextualSourceFactory): |
---|
29 | """A students source delivers all students in accommodation session. |
---|
30 | """ |
---|
31 | |
---|
32 | def acco_students(self, context): |
---|
33 | catalog = getUtility(ICatalog, name='students_catalog') |
---|
34 | accommodation_session = getSite()['configuration'].accommodation_session |
---|
35 | students = catalog.searchResults(current_session=( |
---|
36 | accommodation_session,accommodation_session)) |
---|
37 | existing_students = [ |
---|
38 | context.__parent__[key].owner |
---|
39 | for key in context.__parent__.keys()] |
---|
40 | students = [student for student in students |
---|
41 | if not student.student_id in existing_students] |
---|
42 | students = sorted(list(students), |
---|
43 | key=lambda value: value.student_id) |
---|
44 | return dict([(student.student_id,student.fullname) for student in students]) |
---|
45 | |
---|
46 | def getValues(self, context): |
---|
47 | return self.acco_students(context).keys() |
---|
48 | |
---|
49 | def getToken(self, context, value): |
---|
50 | return value |
---|
51 | |
---|
52 | def getTitle(self, context, value): |
---|
53 | return "%s - %s" % (value, self.acco_students(context)[value]) |
---|
54 | |
---|
55 | bed_letters = SimpleSIRPVocabulary( |
---|
56 | ('Bed A','A'), |
---|
57 | ('Bed B','B'), |
---|
58 | ('Bed C','C'), |
---|
59 | ('Bed D','D'), |
---|
60 | ('Bed E','E'), |
---|
61 | ('Bed F','F'), |
---|
62 | ('Bed G','G'), |
---|
63 | ('Bed H','H'), |
---|
64 | ('Bed I','I'), |
---|
65 | ) |
---|
66 | |
---|
67 | blocks = SimpleSIRPVocabulary( |
---|
68 | ('Block A','A'), |
---|
69 | ('Block B','B'), |
---|
70 | ('Block C','C'), |
---|
71 | ('Block D','D'), |
---|
72 | ('Block E','E'), |
---|
73 | ('Block F','F'), |
---|
74 | ('Block G','G'), |
---|
75 | ('Block H','H'), |
---|
76 | ('Block I','I'), |
---|
77 | ('Block K','K'), |
---|
78 | ('Block L','L'), |
---|
79 | ('Block M','M'), |
---|
80 | ('Block N','N'), |
---|
81 | ('Block O','O'), |
---|
82 | ('Block P','P'), |
---|
83 | ) |
---|
84 | |
---|
85 | special_handling = SimpleSIRPVocabulary( |
---|
86 | ('Regular Hostel','regular'), |
---|
87 | ('Blocked Hostel','blocked'), |
---|
88 | ('Postgraduate Hostel','pg'), |
---|
89 | ) |
---|