[7195] | 1 | ## $Id: vocabularies.py 7195 2011-11-25 07:34:07Z henrik $ |
---|
| 2 | ## |
---|
| 3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
| 4 | ## This program is free software; you can redistribute it and/or modify |
---|
| 5 | ## it under the terms of the GNU General Public License as published by |
---|
| 6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
| 7 | ## (at your option) any later version. |
---|
| 8 | ## |
---|
| 9 | ## This program is distributed in the hope that it will be useful, |
---|
| 10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | ## GNU General Public License for more details. |
---|
| 13 | ## |
---|
| 14 | ## You should have received a copy of the GNU General Public License |
---|
| 15 | ## along with this program; if not, write to the Free Software |
---|
| 16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 17 | ## |
---|
[6958] | 18 | """Vocabularies and sources for the accommodation section. |
---|
| 19 | """ |
---|
[7068] | 20 | from grok import getSite |
---|
| 21 | from zope.component import getUtility |
---|
| 22 | from zope.catalog.interfaces import ICatalog |
---|
| 23 | from zc.sourcefactory.contextual import BasicContextualSourceFactory |
---|
[6958] | 24 | from zc.sourcefactory.basic import BasicSourceFactory |
---|
| 25 | from waeup.sirp.interfaces import SimpleWAeUPVocabulary |
---|
| 26 | |
---|
[7068] | 27 | NOT_OCCUPIED = u'not occupied' |
---|
[6958] | 28 | |
---|
[7068] | 29 | class StudentSource(BasicContextualSourceFactory): |
---|
| 30 | """A students source delivers all students in accommodation session. |
---|
| 31 | """ |
---|
| 32 | |
---|
| 33 | def acco_students(self, context): |
---|
| 34 | catalog = getUtility(ICatalog, name='students_catalog') |
---|
| 35 | accommodation_session = getSite()['configuration'].accommodation_session |
---|
| 36 | students = catalog.searchResults(current_session=( |
---|
| 37 | accommodation_session,accommodation_session)) |
---|
[7070] | 38 | existing_students = [ |
---|
| 39 | context.__parent__[key].owner |
---|
| 40 | for key in context.__parent__.keys()] |
---|
[7068] | 41 | students = [student for student in students |
---|
| 42 | if not student.student_id in existing_students] |
---|
| 43 | students = sorted(list(students), |
---|
| 44 | key=lambda value: value.student_id) |
---|
| 45 | return dict([(student.student_id,student.fullname) for student in students]) |
---|
| 46 | |
---|
| 47 | def getValues(self, context): |
---|
| 48 | return self.acco_students(context).keys() |
---|
| 49 | |
---|
| 50 | def getToken(self, context, value): |
---|
| 51 | return value |
---|
| 52 | |
---|
| 53 | def getTitle(self, context, value): |
---|
| 54 | return "%s - %s" % (value, self.acco_students(context)[value]) |
---|
| 55 | |
---|
[6958] | 56 | bed_letters = SimpleWAeUPVocabulary( |
---|
| 57 | ('Bed A','A'), |
---|
| 58 | ('Bed B','B'), |
---|
| 59 | ('Bed C','C'), |
---|
| 60 | ('Bed D','D'), |
---|
| 61 | ('Bed E','E'), |
---|
| 62 | ('Bed F','F'), |
---|
| 63 | ('Bed G','G'), |
---|
| 64 | ('Bed H','H'), |
---|
| 65 | ('Bed I','I'), |
---|
| 66 | ) |
---|
| 67 | |
---|
| 68 | blocks = SimpleWAeUPVocabulary( |
---|
| 69 | ('Block A','A'), |
---|
| 70 | ('Block B','B'), |
---|
| 71 | ('Block C','C'), |
---|
| 72 | ('Block D','D'), |
---|
| 73 | ('Block E','E'), |
---|
| 74 | ('Block F','F'), |
---|
| 75 | ('Block G','G'), |
---|
| 76 | ('Block H','H'), |
---|
| 77 | ('Block I','I'), |
---|
| 78 | ('Block K','K'), |
---|
| 79 | ('Block L','L'), |
---|
| 80 | ('Block M','M'), |
---|
| 81 | ('Block N','N'), |
---|
| 82 | ('Block O','O'), |
---|
| 83 | ('Block P','P'), |
---|
| 84 | ) |
---|
[6970] | 85 | |
---|
| 86 | special_handling = SimpleWAeUPVocabulary( |
---|
[6973] | 87 | ('Regular Hostel','regular'), |
---|
| 88 | ('Blocked Hostel','blocked'), |
---|
[6970] | 89 | ('Postgraduate Hostel','pg'), |
---|
| 90 | ) |
---|