Ignore:
Timestamp:
10 Nov 2011, 18:56:18 (13 years ago)
Author:
Henrik Bettermann
Message:

Much more logic for bed allocation, bed release.

Implement student relocation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/hostels/vocabularies.py

    r6973 r7068  
    11"""Vocabularies and sources for the accommodation section.
    22"""
     3from  grok import getSite
     4from zope.component import getUtility
     5from zope.catalog.interfaces import ICatalog
     6from zc.sourcefactory.contextual import BasicContextualSourceFactory
    37from zc.sourcefactory.basic import BasicSourceFactory
    48from waeup.sirp.interfaces import SimpleWAeUPVocabulary
    59
     10NOT_OCCUPIED = u'not occupied'
     11
     12class 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])
    641
    742bed_letters = SimpleWAeUPVocabulary(
Note: See TracChangeset for help on using the changeset viewer.