## $Id: vocabularies.py 7195 2011-11-25 07:34:07Z 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 zc.sourcefactory.basic import BasicSourceFactory from waeup.sirp.interfaces import SimpleWAeUPVocabulary 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 = SimpleWAeUPVocabulary( ('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 = SimpleWAeUPVocabulary( ('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 = SimpleWAeUPVocabulary( ('Regular Hostel','regular'), ('Blocked Hostel','blocked'), ('Postgraduate Hostel','pg'), )