source: main/waeup.kofa/trunk/src/waeup/kofa/hostels/vocabularies.py @ 9400

Last change on this file since 9400 was 9400, checked in by Henrik Bettermann, 12 years ago

Make special handling of beds more easily customizable.

  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
1## $Id: vocabularies.py 9400 2012-10-24 05:16:32Z 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"""
20from  grok import getSite
21from zope.component import getUtility
22from zope.catalog.interfaces import ICatalog
23from zc.sourcefactory.contextual import BasicContextualSourceFactory
24from waeup.kofa.interfaces import SimpleKofaVocabulary
25from waeup.kofa.interfaces import MessageFactory as _
26from waeup.kofa.university.vocabularies import ContextualDictSourceFactoryBase
27
28NOT_OCCUPIED = u'not occupied'
29
30class StudentSource(BasicContextualSourceFactory):
31    """A students source delivers all students in accommodation session.
32    """
33
34    def acco_students(self, context):
35        catalog = getUtility(ICatalog, name='students_catalog')
36        accommodation_session = getSite()['hostels'].accommodation_session
37        students = catalog.searchResults(current_session=(
38            accommodation_session,accommodation_session))
39        existing_students = [
40            context.__parent__[key].owner
41            for key in context.__parent__.keys()]
42        students = [student for student in students
43                      if not student.student_id in existing_students]
44        students = sorted(list(students),
45                          key=lambda value: value.student_id)
46        return dict([(student.student_id,student.fullname) for student in students])
47
48    def getValues(self, context):
49        return self.acco_students(context).keys()
50
51    def getToken(self, context, value):
52        return value
53
54    def getTitle(self, context, value):
55        return "%s - %s" % (value, self.acco_students(context)[value])
56
57class SpecialHandlingSource(ContextualDictSourceFactoryBase):
58    """A application category source delivers all special handling categories
59    provided for accommodation booking.
60    """
61    #: name of dict to deliver from kofa utils.
62    DICT_NAME = 'SPECIAL_HANDLING_DICT'
63
64bed_letters = SimpleKofaVocabulary(
65    (_('Bed A'),'A'),
66    (_('Bed B'),'B'),
67    (_('Bed C'),'C'),
68    (_('Bed D'),'D'),
69    (_('Bed E'),'E'),
70    (_('Bed F'),'F'),
71    (_('Bed G'),'G'),
72    (_('Bed H'),'H'),
73    (_('Bed I'),'I'),
74    (_('Bed J'),'J'),
75    (_('Bed K'),'K'),
76    (_('Bed L'),'L'),
77    )
78
79blocks = SimpleKofaVocabulary(
80    (_('Block A'),'A'),
81    (_('Block B'),'B'),
82    (_('Block C'),'C'),
83    (_('Block D'),'D'),
84    (_('Block E'),'E'),
85    (_('Block F'),'F'),
86    (_('Block G'),'G'),
87    (_('Block H'),'H'),
88    (_('Block I'),'I'),
89    (_('Block K'),'K'),
90    (_('Block L'),'L'),
91    (_('Block M'),'M'),
92    (_('Block N'),'N'),
93    (_('Block O'),'O'),
94    (_('Block P'),'P'),
95    (_('Block Q'),'Q'),
96    )
Note: See TracBrowser for help on using the repository browser.