"""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'), )