source: main/waeup.kofa/trunk/src/waeup/kofa/university/vocabularies.py @ 15476

Last change on this file since 15476 was 15446, checked in by Henrik Bettermann, 6 years ago

Add level 0 (None) to course levels.

  • Property svn:keywords set to Id
File size: 4.4 KB
RevLine 
[7195]1## $Id: vocabularies.py 15446 2019-06-03 10:32:23Z 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##
[12862]18"""Vocabularies and sources for the academic section.
[6091]19"""
20from zc.sourcefactory.basic import BasicSourceFactory
[6557]21from zope.catalog.interfaces import ICatalog
[7916]22from zope.component import getUtility, queryUtility
[11450]23from waeup.kofa.interfaces import (
24    SimpleKofaVocabulary, IKofaUtils, ContextualDictSourceFactoryBase)
[7811]25from waeup.kofa.interfaces import MessageFactory as _
[8606]26from waeup.kofa.sourcefactory import SmartBasicContextualSourceFactory
[7916]27from waeup.kofa.utils.utils import KofaUtils
[6091]28
[7819]29course_levels = SimpleKofaVocabulary(
[15446]30    (_('None'),0),
[7681]31    (_('Pre-Studies'),10),
32    (_('100 (Year 1)'),100),
33    (_('200 (Year 2)'),200),
34    (_('300 (Year 3)'),300),
35    (_('400 (Year 4)'),400),
36    (_('500 (Year 5)'),500),
37    (_('600 (Year 6)'),600),
38    (_('700 (Year 7)'),700),
39    (_('800 (Year 8)'),800),
[8084]40    (_('900 (Year 9)'),900),
[8471]41    (_('Postgraduate Level'),999),
[6091]42    )
43
[7916]44class SemesterSource(ContextualDictSourceFactoryBase):
[10436]45    """An institution type source delivers semester and/or term descriptors.
[7916]46    """
47    #: name of dict to deliver from kofa utils.
48    DICT_NAME = 'SEMESTER_DICT'
49
50class InstTypeSource(ContextualDictSourceFactoryBase):
51    """An institution type source delivers types of institutions
52    in the portal.
53    """
54    #: name of dict to deliver from kofa utils.
55    DICT_NAME = 'INST_TYPES_DICT'
56
57class AppCatSource(ContextualDictSourceFactoryBase):
[7681]58    """A application category source delivers all application categories
59    provided in the portal.
60    """
[7916]61    #: name of dict to deliver from kofa utils.
62    DICT_NAME = 'APP_CATS_DICT'
[7681]63
[7916]64class StudyModeSource(ContextualDictSourceFactoryBase):
[7681]65    """A study modes source delivers all study modes provided
66    in the portal.
67    """
[7916]68    #: name of dict to deliver from kofa utils.
69    DICT_NAME = 'STUDY_MODES_DICT'
[7681]70
[13617]71class DegreeSource(ContextualDictSourceFactoryBase):
72    """A source for certificate degrees
73    """
74    #: name of dict to deliver from kofa utils.
75    DICT_NAME = 'DEGREES_DICT'
76
77    def getTitle(self, context, value):
78        utils = getUtility(IKofaUtils)
79        return "%s (%s)" % (getattr(utils, self.DICT_NAME)[value], value)
80
[6091]81class CourseSource(BasicSourceFactory):
82    """A course source delivers all courses inside the portal by looking
83       up a catalog.
84    """
85    def getValues(self):
86        catalog = getUtility(ICatalog, name='courses_catalog')
[6092]87        return sorted(list(
88                catalog.searchResults(
[7916]89                    code=(None, None))),key=lambda value: value.code)
[6091]90
91    def getToken(self, value):
92        return value.code
93
94    def getTitle(self, value):
95        return "%s - %s" % (value.code, value.title[:64])
[7915]96
[14638]97class CourseCategorySource(ContextualDictSourceFactoryBase):
98    """A course category source provides additional information on
99    the course.
100    """
101    #: name of dict to deliver from kofa utils.
102    DICT_NAME = 'COURSE_CATEGORY_DICT'
[8606]103
104
105class CertificateSource(SmartBasicContextualSourceFactory):
[7915]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)
[10831]121
122class SpecialApplicationSource(ContextualDictSourceFactoryBase):
123    """A special application source delivers all types of
124    applications which are not linked with certificates.
125    """
126    #: name of dict to deliver from kofa utils.
127    DICT_NAME = 'SPECIAL_APP_DICT'
Note: See TracBrowser for help on using the repository browser.