[7195] | 1 | ## $Id: vocabularies.py 7681 2012-02-22 21:14:09Z 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 | ## |
---|
[6091] | 18 | """Vocabularies and sources for the academics section. |
---|
| 19 | """ |
---|
| 20 | from zc.sourcefactory.basic import BasicSourceFactory |
---|
[7681] | 21 | from zc.sourcefactory.contextual import BasicContextualSourceFactory |
---|
[6557] | 22 | from zope.catalog.interfaces import ICatalog |
---|
[6091] | 23 | from zope.component import getUtility |
---|
[7681] | 24 | from waeup.sirp.interfaces import SimpleSIRPVocabulary, ISIRPUtils |
---|
| 25 | from waeup.sirp.interfaces import MessageFactory as _ |
---|
[6091] | 26 | |
---|
[7321] | 27 | course_levels = SimpleSIRPVocabulary( |
---|
[7681] | 28 | (_('Pre-Studies'),10), |
---|
| 29 | (_('100 (Year 1)'),100), |
---|
| 30 | (_('200 (Year 2)'),200), |
---|
| 31 | (_('300 (Year 3)'),300), |
---|
| 32 | (_('400 (Year 4)'),400), |
---|
| 33 | (_('500 (Year 5)'),500), |
---|
| 34 | (_('600 (Year 6)'),600), |
---|
| 35 | (_('700 (Year 7)'),700), |
---|
| 36 | (_('800 (Year 8)'),800), |
---|
[6091] | 37 | ) |
---|
| 38 | |
---|
[7681] | 39 | class SemesterSource(BasicContextualSourceFactory): |
---|
| 40 | """An institution type source delivers semester or term descriptors. |
---|
| 41 | """ |
---|
| 42 | def getValues(self, context): |
---|
| 43 | self.semesters_dict = getUtility(ISIRPUtils).getSemesterDict() |
---|
| 44 | return self.semesters_dict.keys() |
---|
[6091] | 45 | |
---|
[7681] | 46 | def getToken(self, context, value): |
---|
| 47 | return str(value) |
---|
[6091] | 48 | |
---|
[7681] | 49 | def getTitle(self, context, value): |
---|
| 50 | return self.semesters_dict[value] |
---|
[6091] | 51 | |
---|
[7681] | 52 | class InstTypeSource(BasicContextualSourceFactory): |
---|
| 53 | """An institution type source delivers types of institutions |
---|
| 54 | in the portal. |
---|
| 55 | """ |
---|
| 56 | def getValues(self, context): |
---|
| 57 | self.insttypes_dict = getUtility(ISIRPUtils).getInstTypeDict() |
---|
| 58 | return sorted(self.insttypes_dict.keys()) |
---|
| 59 | |
---|
| 60 | def getToken(self, context, value): |
---|
| 61 | return value |
---|
| 62 | |
---|
| 63 | def getTitle(self, context, value): |
---|
| 64 | return self.insttypes_dict[value] |
---|
| 65 | |
---|
| 66 | class AppCatSource(BasicContextualSourceFactory): |
---|
| 67 | """A application category source delivers all application categories |
---|
| 68 | provided in the portal. |
---|
| 69 | """ |
---|
| 70 | def getValues(self, context): |
---|
| 71 | self.appcats_dict = getUtility(ISIRPUtils).getAppCatDict() |
---|
| 72 | return sorted(self.appcats_dict.keys()) |
---|
| 73 | |
---|
| 74 | def getToken(self, context, value): |
---|
| 75 | return value |
---|
| 76 | |
---|
| 77 | def getTitle(self, context, value): |
---|
| 78 | return self.appcats_dict[value] |
---|
| 79 | |
---|
| 80 | class StudyModeSource(BasicContextualSourceFactory): |
---|
| 81 | """A study modes source delivers all study modes provided |
---|
| 82 | in the portal. |
---|
| 83 | """ |
---|
| 84 | def getValues(self, context): |
---|
| 85 | self.studymodes_dict = getUtility(ISIRPUtils).getStudyModesDict() |
---|
| 86 | return sorted(self.studymodes_dict.keys()) |
---|
| 87 | |
---|
| 88 | def getToken(self, context, value): |
---|
| 89 | return value |
---|
| 90 | |
---|
| 91 | def getTitle(self, context, value): |
---|
| 92 | return self.studymodes_dict[value] |
---|
| 93 | |
---|
[6091] | 94 | class CourseSource(BasicSourceFactory): |
---|
| 95 | """A course source delivers all courses inside the portal by looking |
---|
| 96 | up a catalog. |
---|
| 97 | """ |
---|
| 98 | def getValues(self): |
---|
| 99 | catalog = getUtility(ICatalog, name='courses_catalog') |
---|
[6092] | 100 | return sorted(list( |
---|
| 101 | catalog.searchResults( |
---|
| 102 | code=('', 'z*'))),key=lambda value: value.code) |
---|
[6091] | 103 | |
---|
| 104 | def getToken(self, value): |
---|
| 105 | return value.code |
---|
| 106 | |
---|
| 107 | def getTitle(self, value): |
---|
| 108 | return "%s - %s" % (value.code, value.title[:64]) |
---|