[7195] | 1 | ## $Id: vocabularies.py 7841 2012-03-12 08:04:03Z 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 |
---|
[7819] | 24 | from waeup.kofa.interfaces import SimpleKofaVocabulary, IKofaUtils |
---|
[7811] | 25 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
[6091] | 26 | |
---|
[7819] | 27 | course_levels = SimpleKofaVocabulary( |
---|
[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 | |
---|
[7838] | 39 | class SemesterSource(BasicSourceFactory): |
---|
[7681] | 40 | """An institution type source delivers semester or term descriptors. |
---|
| 41 | """ |
---|
[7838] | 42 | def getValues(self): |
---|
| 43 | try: |
---|
| 44 | # We have to 'try', don't know why (henrik) |
---|
| 45 | # Alternatively, we can use BasicContextualSourceFactory, |
---|
| 46 | # see sources below |
---|
| 47 | from waeup.kofa.interfaces import IKofaUtils |
---|
[7841] | 48 | return getUtility(IKofaUtils).SEMESTER_DICT.keys() |
---|
[7838] | 49 | except: |
---|
| 50 | return [9] |
---|
| 51 | |
---|
| 52 | def getToken(self, value): |
---|
[7681] | 53 | return str(value) |
---|
[6091] | 54 | |
---|
[7838] | 55 | def getTitle(self, value): |
---|
| 56 | try: |
---|
| 57 | from waeup.kofa.interfaces import IKofaUtils |
---|
[7841] | 58 | semesters_dict = getUtility(IKofaUtils).SEMESTER_DICT |
---|
[7838] | 59 | return semesters_dict[value] |
---|
| 60 | except: |
---|
| 61 | value |
---|
[6091] | 62 | |
---|
[7681] | 63 | class InstTypeSource(BasicContextualSourceFactory): |
---|
| 64 | """An institution type source delivers types of institutions |
---|
| 65 | in the portal. |
---|
| 66 | """ |
---|
| 67 | def getValues(self, context): |
---|
[7841] | 68 | insttypes_dict = getUtility(IKofaUtils).INST_TYPES_DICT |
---|
[7688] | 69 | return sorted(insttypes_dict.keys()) |
---|
[7681] | 70 | |
---|
| 71 | def getToken(self, context, value): |
---|
| 72 | return value |
---|
| 73 | |
---|
| 74 | def getTitle(self, context, value): |
---|
[7841] | 75 | insttypes_dict = getUtility(IKofaUtils).INST_TYPES_DICT |
---|
[7688] | 76 | return insttypes_dict[value] |
---|
[7681] | 77 | |
---|
| 78 | class AppCatSource(BasicContextualSourceFactory): |
---|
| 79 | """A application category source delivers all application categories |
---|
| 80 | provided in the portal. |
---|
| 81 | """ |
---|
| 82 | def getValues(self, context): |
---|
[7841] | 83 | appcats_dict = getUtility(IKofaUtils).APP_CATS_DICT |
---|
[7688] | 84 | return sorted(appcats_dict.keys()) |
---|
[7681] | 85 | |
---|
| 86 | def getToken(self, context, value): |
---|
| 87 | return value |
---|
| 88 | |
---|
| 89 | def getTitle(self, context, value): |
---|
[7841] | 90 | appcats_dict = getUtility(IKofaUtils).APP_CATS_DICT |
---|
[7688] | 91 | return appcats_dict[value] |
---|
[7681] | 92 | |
---|
| 93 | class StudyModeSource(BasicContextualSourceFactory): |
---|
| 94 | """A study modes source delivers all study modes provided |
---|
| 95 | in the portal. |
---|
| 96 | """ |
---|
| 97 | def getValues(self, context): |
---|
[7841] | 98 | studymodes_dict = getUtility(IKofaUtils).STUDY_MODES_DICT |
---|
[7688] | 99 | return sorted(studymodes_dict.keys()) |
---|
[7681] | 100 | |
---|
| 101 | def getToken(self, context, value): |
---|
| 102 | return value |
---|
| 103 | |
---|
| 104 | def getTitle(self, context, value): |
---|
[7841] | 105 | studymodes_dict = getUtility(IKofaUtils).STUDY_MODES_DICT |
---|
[7688] | 106 | return studymodes_dict[value] |
---|
[7681] | 107 | |
---|
[6091] | 108 | class CourseSource(BasicSourceFactory): |
---|
| 109 | """A course source delivers all courses inside the portal by looking |
---|
| 110 | up a catalog. |
---|
| 111 | """ |
---|
| 112 | def getValues(self): |
---|
| 113 | catalog = getUtility(ICatalog, name='courses_catalog') |
---|
[6092] | 114 | return sorted(list( |
---|
| 115 | catalog.searchResults( |
---|
| 116 | code=('', 'z*'))),key=lambda value: value.code) |
---|
[6091] | 117 | |
---|
| 118 | def getToken(self, value): |
---|
| 119 | return value.code |
---|
| 120 | |
---|
| 121 | def getTitle(self, value): |
---|
| 122 | return "%s - %s" % (value.code, value.title[:64]) |
---|