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

Last change on this file since 7878 was 7819, checked in by Henrik Bettermann, 13 years ago

KOFA -> Kofa

  • Property svn:keywords set to Id
File size: 3.0 KB
RevLine 
[7195]1## $Id: vocabularies.py 7819 2012-03-08 22:28:46Z 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 _
[6958]26
[7068]27NOT_OCCUPIED = u'not occupied'
[6958]28
[7068]29class 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))
[7070]38        existing_students = [
39            context.__parent__[key].owner
40            for key in context.__parent__.keys()]
[7068]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
[7819]56bed_letters = SimpleKofaVocabulary(
[7718]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'),
[6958]66    )
67
[7819]68blocks = SimpleKofaVocabulary(
[7718]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'),
[6958]84    )
[6970]85
[7819]86special_handling = SimpleKofaVocabulary(
[7718]87    (_('Regular Hostel'),'regular'),
88    (_('Blocked Hostel'),'blocked'),
89    (_('Postgraduate Hostel'),'pg'),
[6970]90    )
Note: See TracBrowser for help on using the repository browser.