[7195] | 1 | ## $Id: vocabularies.py 10831 2013-12-10 06:24: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 |
---|
[6557] | 21 | from zope.catalog.interfaces import ICatalog |
---|
[7916] | 22 | from zope.component import getUtility, queryUtility |
---|
[7819] | 23 | from waeup.kofa.interfaces import SimpleKofaVocabulary, IKofaUtils |
---|
[7811] | 24 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
[8606] | 25 | from waeup.kofa.sourcefactory import SmartBasicContextualSourceFactory |
---|
[7916] | 26 | from waeup.kofa.utils.utils import KofaUtils |
---|
[6091] | 27 | |
---|
[7819] | 28 | course_levels = SimpleKofaVocabulary( |
---|
[7681] | 29 | (_('Pre-Studies'),10), |
---|
| 30 | (_('100 (Year 1)'),100), |
---|
| 31 | (_('200 (Year 2)'),200), |
---|
| 32 | (_('300 (Year 3)'),300), |
---|
| 33 | (_('400 (Year 4)'),400), |
---|
| 34 | (_('500 (Year 5)'),500), |
---|
| 35 | (_('600 (Year 6)'),600), |
---|
| 36 | (_('700 (Year 7)'),700), |
---|
| 37 | (_('800 (Year 8)'),800), |
---|
[8084] | 38 | (_('900 (Year 9)'),900), |
---|
[8471] | 39 | (_('Postgraduate Level'),999), |
---|
[6091] | 40 | ) |
---|
| 41 | |
---|
[7916] | 42 | #: An instance of :class:`waeup.kofa.utils.utils.KofaUtils` for fallback. |
---|
| 43 | KOFA_UTILS = KofaUtils() |
---|
[6091] | 44 | |
---|
[8606] | 45 | class ContextualDictSourceFactoryBase(SmartBasicContextualSourceFactory): |
---|
[7916] | 46 | """A base for contextual sources based on KofaUtils dicts. |
---|
[6091] | 47 | |
---|
[7916] | 48 | To create a real source, you have to set the `DICT_NAME` attribute |
---|
| 49 | which should be the name of a dictionary in KofaUtils. |
---|
[7681] | 50 | """ |
---|
| 51 | def getValues(self, context): |
---|
[7916] | 52 | utils = queryUtility(IKofaUtils, default=KOFA_UTILS) |
---|
| 53 | return sorted(getattr(utils, self.DICT_NAME).keys()) |
---|
[7681] | 54 | |
---|
| 55 | def getToken(self, context, value): |
---|
[7916] | 56 | return str(value) |
---|
[7681] | 57 | |
---|
| 58 | def getTitle(self, context, value): |
---|
[7916] | 59 | utils = queryUtility(IKofaUtils, default=KOFA_UTILS) |
---|
| 60 | return getattr(utils, self.DICT_NAME)[value] |
---|
[7681] | 61 | |
---|
[7916] | 62 | class SemesterSource(ContextualDictSourceFactoryBase): |
---|
[10436] | 63 | """An institution type source delivers semester and/or term descriptors. |
---|
[7916] | 64 | """ |
---|
| 65 | #: name of dict to deliver from kofa utils. |
---|
| 66 | DICT_NAME = 'SEMESTER_DICT' |
---|
| 67 | |
---|
| 68 | class InstTypeSource(ContextualDictSourceFactoryBase): |
---|
| 69 | """An institution type source delivers types of institutions |
---|
| 70 | in the portal. |
---|
| 71 | """ |
---|
| 72 | #: name of dict to deliver from kofa utils. |
---|
| 73 | DICT_NAME = 'INST_TYPES_DICT' |
---|
| 74 | |
---|
| 75 | class AppCatSource(ContextualDictSourceFactoryBase): |
---|
[7681] | 76 | """A application category source delivers all application categories |
---|
| 77 | provided in the portal. |
---|
| 78 | """ |
---|
[7916] | 79 | #: name of dict to deliver from kofa utils. |
---|
| 80 | DICT_NAME = 'APP_CATS_DICT' |
---|
[7681] | 81 | |
---|
[7916] | 82 | class StudyModeSource(ContextualDictSourceFactoryBase): |
---|
[7681] | 83 | """A study modes source delivers all study modes provided |
---|
| 84 | in the portal. |
---|
| 85 | """ |
---|
[7916] | 86 | #: name of dict to deliver from kofa utils. |
---|
| 87 | DICT_NAME = 'STUDY_MODES_DICT' |
---|
[7681] | 88 | |
---|
[6091] | 89 | class CourseSource(BasicSourceFactory): |
---|
| 90 | """A course source delivers all courses inside the portal by looking |
---|
| 91 | up a catalog. |
---|
| 92 | """ |
---|
| 93 | def getValues(self): |
---|
| 94 | catalog = getUtility(ICatalog, name='courses_catalog') |
---|
[6092] | 95 | return sorted(list( |
---|
| 96 | catalog.searchResults( |
---|
[7916] | 97 | code=(None, None))),key=lambda value: value.code) |
---|
[6091] | 98 | |
---|
| 99 | def getToken(self, value): |
---|
| 100 | return value.code |
---|
| 101 | |
---|
| 102 | def getTitle(self, value): |
---|
| 103 | return "%s - %s" % (value.code, value.title[:64]) |
---|
[7915] | 104 | |
---|
[8606] | 105 | |
---|
| 106 | |
---|
| 107 | class CertificateSource(SmartBasicContextualSourceFactory): |
---|
[7915] | 108 | """A certificate source delivers all certificates provided |
---|
| 109 | in the portal. |
---|
| 110 | """ |
---|
| 111 | def getValues(self, context): |
---|
| 112 | catalog = getUtility(ICatalog, name='certificates_catalog') |
---|
| 113 | return sorted(list( |
---|
[7916] | 114 | catalog.searchResults( |
---|
| 115 | code=(None, None))), |
---|
| 116 | key=lambda value: value.code) |
---|
[7915] | 117 | |
---|
| 118 | def getToken(self, context, value): |
---|
| 119 | return value.code |
---|
| 120 | |
---|
| 121 | def getTitle(self, context, value): |
---|
[8439] | 122 | return "%s - %s" % (value.code, value.title) |
---|
[10831] | 123 | |
---|
| 124 | class SpecialApplicationSource(ContextualDictSourceFactoryBase): |
---|
| 125 | """A special application source delivers all types of |
---|
| 126 | applications which are not linked with certificates. |
---|
| 127 | """ |
---|
| 128 | #: name of dict to deliver from kofa utils. |
---|
| 129 | DICT_NAME = 'SPECIAL_APP_DICT' |
---|