[7195] | 1 | ## $Id: vocabularies.py 8471 2012-05-20 05:46: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 | ## |
---|
[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 |
---|
[7916] | 23 | from zope.component import getUtility, queryUtility |
---|
[7819] | 24 | from waeup.kofa.interfaces import SimpleKofaVocabulary, IKofaUtils |
---|
[7811] | 25 | from waeup.kofa.interfaces import MessageFactory as _ |
---|
[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 | |
---|
[7916] | 45 | class ContextualDictSourceFactoryBase(BasicContextualSourceFactory): |
---|
| 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): |
---|
| 63 | """An institution type source delivers semester or term descriptors. |
---|
| 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 | |
---|
| 105 | class CertificateSource(BasicContextualSourceFactory): |
---|
| 106 | """A certificate source delivers all certificates provided |
---|
| 107 | in the portal. |
---|
| 108 | """ |
---|
| 109 | def getValues(self, context): |
---|
| 110 | catalog = getUtility(ICatalog, name='certificates_catalog') |
---|
| 111 | return sorted(list( |
---|
[7916] | 112 | catalog.searchResults( |
---|
| 113 | code=(None, None))), |
---|
| 114 | key=lambda value: value.code) |
---|
[7915] | 115 | |
---|
| 116 | def getToken(self, context, value): |
---|
| 117 | return value.code |
---|
| 118 | |
---|
| 119 | def getTitle(self, context, value): |
---|
[8439] | 120 | return "%s - %s" % (value.code, value.title) |
---|