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

Last change on this file since 17929 was 17376, checked in by Henrik Bettermann, 20 months ago

Enable customization of certificate select box entries also in the students section.

  • Property svn:keywords set to Id
File size: 4.5 KB
RevLine 
[7195]1## $Id: vocabularies.py 17376 2023-04-06 17:29:31Z 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),
[16812]42    (_('Modules Level'),1000),
[6091]43    )
44
[7916]45class SemesterSource(ContextualDictSourceFactoryBase):
[10436]46    """An institution type source delivers semester and/or term descriptors.
[7916]47    """
48    #: name of dict to deliver from kofa utils.
49    DICT_NAME = 'SEMESTER_DICT'
50
51class InstTypeSource(ContextualDictSourceFactoryBase):
52    """An institution type source delivers types of institutions
53    in the portal.
54    """
55    #: name of dict to deliver from kofa utils.
56    DICT_NAME = 'INST_TYPES_DICT'
57
58class AppCatSource(ContextualDictSourceFactoryBase):
[7681]59    """A application category source delivers all application categories
60    provided in the portal.
61    """
[7916]62    #: name of dict to deliver from kofa utils.
63    DICT_NAME = 'APP_CATS_DICT'
[7681]64
[7916]65class StudyModeSource(ContextualDictSourceFactoryBase):
[7681]66    """A study modes source delivers all study modes provided
67    in the portal.
68    """
[7916]69    #: name of dict to deliver from kofa utils.
70    DICT_NAME = 'STUDY_MODES_DICT'
[7681]71
[13617]72class DegreeSource(ContextualDictSourceFactoryBase):
73    """A source for certificate degrees
74    """
75    #: name of dict to deliver from kofa utils.
76    DICT_NAME = 'DEGREES_DICT'
77
78    def getTitle(self, context, value):
79        utils = getUtility(IKofaUtils)
80        return "%s (%s)" % (getattr(utils, self.DICT_NAME)[value], value)
81
[6091]82class CourseSource(BasicSourceFactory):
83    """A course source delivers all courses inside the portal by looking
84       up a catalog.
85    """
86    def getValues(self):
87        catalog = getUtility(ICatalog, name='courses_catalog')
[6092]88        return sorted(list(
89                catalog.searchResults(
[7916]90                    code=(None, None))),key=lambda value: value.code)
[6091]91
92    def getToken(self, value):
93        return value.code
94
95    def getTitle(self, value):
96        return "%s - %s" % (value.code, value.title[:64])
[7915]97
[14638]98class CourseCategorySource(ContextualDictSourceFactoryBase):
99    """A course category source provides additional information on
100    the course.
101    """
102    #: name of dict to deliver from kofa utils.
103    DICT_NAME = 'COURSE_CATEGORY_DICT'
[8606]104
105
106class CertificateSource(SmartBasicContextualSourceFactory):
[7915]107    """A certificate source delivers all certificates provided
108    in the portal.
109    """
110
111    def getToken(self, context, value):
112        return value.code
113
[17376]114    def getValues(self, context):
115        catalog = getUtility(ICatalog, name='certificates_catalog')
116        result = catalog.searchResults(code=(None, None))
117        resultlist = getUtility(
118            IKofaUtils).sortCertificates(context, result)
119        return resultlist
120
[7915]121    def getTitle(self, context, value):
[17376]122        return getUtility(
123            IKofaUtils).getCertTitle(context, value)
[10831]124
125class SpecialApplicationSource(ContextualDictSourceFactoryBase):
126    """A special application source delivers all types of
127    applications which are not linked with certificates.
128    """
129    #: name of dict to deliver from kofa utils.
130    DICT_NAME = 'SPECIAL_APP_DICT'
Note: See TracBrowser for help on using the repository browser.