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

Last change on this file since 9401 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
RevLine 
[7195]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##
[6958]18"""Vocabularies and sources for the accommodation section.
19"""
[7068]20from  grok import getSite
21from zope.component import getUtility
22from zope.catalog.interfaces import ICatalog
23from zc.sourcefactory.contextual import BasicContextualSourceFactory
[7819]24from waeup.kofa.interfaces import SimpleKofaVocabulary
[7811]25from waeup.kofa.interfaces import MessageFactory as _
[9400]26from waeup.kofa.university.vocabularies import ContextualDictSourceFactoryBase
[6958]27
[7068]28NOT_OCCUPIED = u'not occupied'
[6958]29
[7068]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')
[8685]36        accommodation_session = getSite()['hostels'].accommodation_session
[7068]37        students = catalog.searchResults(current_session=(
38            accommodation_session,accommodation_session))
[7070]39        existing_students = [
40            context.__parent__[key].owner
41            for key in context.__parent__.keys()]
[7068]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
[9400]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
[7819]64bed_letters = SimpleKofaVocabulary(
[7718]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'),
[9371]74    (_('Bed J'),'J'),
75    (_('Bed K'),'K'),
76    (_('Bed L'),'L'),
[6958]77    )
78
[7819]79blocks = SimpleKofaVocabulary(
[7718]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'),
[9373]95    (_('Block Q'),'Q'),
[6958]96    )
Note: See TracBrowser for help on using the repository browser.