## $Id: vocabularies.py 7819 2012-03-08 22:28:46Z henrik $ ## ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## """Vocabularies and sources for the accommodation section. """ from grok import getSite from zope.component import getUtility from zope.catalog.interfaces import ICatalog from zc.sourcefactory.contextual import BasicContextualSourceFactory from waeup.kofa.interfaces import SimpleKofaVocabulary from waeup.kofa.interfaces import MessageFactory as _ NOT_OCCUPIED = u'not occupied' class StudentSource(BasicContextualSourceFactory): """A students source delivers all students in accommodation session. """ def acco_students(self, context): catalog = getUtility(ICatalog, name='students_catalog') accommodation_session = getSite()['configuration'].accommodation_session students = catalog.searchResults(current_session=( accommodation_session,accommodation_session)) existing_students = [ context.__parent__[key].owner for key in context.__parent__.keys()] students = [student for student in students if not student.student_id in existing_students] students = sorted(list(students), key=lambda value: value.student_id) return dict([(student.student_id,student.fullname) for student in students]) def getValues(self, context): return self.acco_students(context).keys() def getToken(self, context, value): return value def getTitle(self, context, value): return "%s - %s" % (value, self.acco_students(context)[value]) bed_letters = SimpleKofaVocabulary( (_('Bed A'),'A'), (_('Bed B'),'B'), (_('Bed C'),'C'), (_('Bed D'),'D'), (_('Bed E'),'E'), (_('Bed F'),'F'), (_('Bed G'),'G'), (_('Bed H'),'H'), (_('Bed I'),'I'), ) blocks = SimpleKofaVocabulary( (_('Block A'),'A'), (_('Block B'),'B'), (_('Block C'),'C'), (_('Block D'),'D'), (_('Block E'),'E'), (_('Block F'),'F'), (_('Block G'),'G'), (_('Block H'),'H'), (_('Block I'),'I'), (_('Block K'),'K'), (_('Block L'),'L'), (_('Block M'),'M'), (_('Block N'),'N'), (_('Block O'),'O'), (_('Block P'),'P'), ) special_handling = SimpleKofaVocabulary( (_('Regular Hostel'),'regular'), (_('Blocked Hostel'),'blocked'), (_('Postgraduate Hostel'),'pg'), )