- Timestamp:
- 10 Nov 2011, 18:56:18 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/hostels/vocabularies.py
r6973 r7068 1 1 """Vocabularies and sources for the accommodation section. 2 2 """ 3 from grok import getSite 4 from zope.component import getUtility 5 from zope.catalog.interfaces import ICatalog 6 from zc.sourcefactory.contextual import BasicContextualSourceFactory 3 7 from zc.sourcefactory.basic import BasicSourceFactory 4 8 from waeup.sirp.interfaces import SimpleWAeUPVocabulary 5 9 10 NOT_OCCUPIED = u'not occupied' 11 12 class StudentSource(BasicContextualSourceFactory): 13 """A students source delivers all students in accommodation session. 14 """ 15 16 def acco_students(self, context): 17 catalog = getUtility(ICatalog, name='students_catalog') 18 accommodation_session = getSite()['configuration'].accommodation_session 19 students = catalog.searchResults(current_session=( 20 accommodation_session,accommodation_session)) 21 try: 22 existing_students = [ 23 context.__parent__[key].owner 24 for key in context.__parent__.keys()] 25 except AttributeError: 26 return {NOT_OCCUPIED:NOT_OCCUPIED} 27 students = [student for student in students 28 if not student.student_id in existing_students] 29 students = sorted(list(students), 30 key=lambda value: value.student_id) 31 return dict([(student.student_id,student.fullname) for student in students]) 32 33 def getValues(self, context): 34 return self.acco_students(context).keys() 35 36 def getToken(self, context, value): 37 return value 38 39 def getTitle(self, context, value): 40 return "%s - %s" % (value, self.acco_students(context)[value]) 6 41 7 42 bed_letters = SimpleWAeUPVocabulary(
Note: See TracChangeset for help on using the changeset viewer.