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

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

Increase number of block letters.

  • Property svn:keywords set to Id
File size: 3.1 KB
RevLine 
[7195]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##
[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')
[8685]35        accommodation_session = getSite()['hostels'].accommodation_session
[7068]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'),
[9371]66    (_('Bed J'),'J'),
67    (_('Bed K'),'K'),
68    (_('Bed L'),'L'),
[6958]69    )
70
[7819]71blocks = SimpleKofaVocabulary(
[7718]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'),
[9373]87    (_('Block Q'),'Q'),
[6958]88    )
[6970]89
[7819]90special_handling = SimpleKofaVocabulary(
[7718]91    (_('Regular Hostel'),'regular'),
92    (_('Blocked Hostel'),'blocked'),
93    (_('Postgraduate Hostel'),'pg'),
[6970]94    )
Note: See TracBrowser for help on using the repository browser.