source: main/waeup.sirp/trunk/src/waeup/sirp/hostels/vocabularies.py @ 7167

Last change on this file since 7167 was 7070, checked in by Henrik Bettermann, 13 years ago

Add more tests and increase test coverage.

  • Property svn:keywords set to Id
File size: 2.2 KB
Line 
1"""Vocabularies and sources for the accommodation section.
2"""
3from  grok import getSite
4from zope.component import getUtility
5from zope.catalog.interfaces import ICatalog
6from zc.sourcefactory.contextual import BasicContextualSourceFactory
7from zc.sourcefactory.basic import BasicSourceFactory
8from waeup.sirp.interfaces import SimpleWAeUPVocabulary
9
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        existing_students = [
22            context.__parent__[key].owner
23            for key in context.__parent__.keys()]
24        students = [student for student in students
25                      if not student.student_id in existing_students]
26        students = sorted(list(students),
27                          key=lambda value: value.student_id)
28        return dict([(student.student_id,student.fullname) for student in students])
29
30    def getValues(self, context):
31        return self.acco_students(context).keys()
32
33    def getToken(self, context, value):
34        return value
35
36    def getTitle(self, context, value):
37        return "%s - %s" % (value, self.acco_students(context)[value])
38
39bed_letters = SimpleWAeUPVocabulary(
40    ('Bed A','A'),
41    ('Bed B','B'),
42    ('Bed C','C'),
43    ('Bed D','D'),
44    ('Bed E','E'),
45    ('Bed F','F'),
46    ('Bed G','G'),
47    ('Bed H','H'),
48    ('Bed I','I'),
49    )
50
51blocks = SimpleWAeUPVocabulary(
52    ('Block A','A'),
53    ('Block B','B'),
54    ('Block C','C'),
55    ('Block D','D'),
56    ('Block E','E'),
57    ('Block F','F'),
58    ('Block G','G'),
59    ('Block H','H'),
60    ('Block I','I'),
61    ('Block K','K'),
62    ('Block L','L'),
63    ('Block M','M'),
64    ('Block N','N'),
65    ('Block O','O'),
66    ('Block P','P'),
67    )
68
69special_handling = SimpleWAeUPVocabulary(
70    ('Regular Hostel','regular'),
71    ('Blocked Hostel','blocked'),
72    ('Postgraduate Hostel','pg'),
73    )
Note: See TracBrowser for help on using the repository browser.