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

Last change on this file since 14220 was 13617, checked in by Henrik Bettermann, 9 years ago

Add DegreeSource? and degree field to Certificate. Plugins must be updated!

  • Property svn:keywords set to Id
File size: 4.1 KB
RevLine 
[7195]1## $Id: vocabularies.py 13617 2016-01-15 15:34: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##
[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(
[7681]30    (_('Pre-Studies'),10),
31    (_('100 (Year 1)'),100),
32    (_('200 (Year 2)'),200),
33    (_('300 (Year 3)'),300),
34    (_('400 (Year 4)'),400),
35    (_('500 (Year 5)'),500),
36    (_('600 (Year 6)'),600),
37    (_('700 (Year 7)'),700),
38    (_('800 (Year 8)'),800),
[8084]39    (_('900 (Year 9)'),900),
[8471]40    (_('Postgraduate Level'),999),
[6091]41    )
42
[7916]43class SemesterSource(ContextualDictSourceFactoryBase):
[10436]44    """An institution type source delivers semester and/or term descriptors.
[7916]45    """
46    #: name of dict to deliver from kofa utils.
47    DICT_NAME = 'SEMESTER_DICT'
48
49class InstTypeSource(ContextualDictSourceFactoryBase):
50    """An institution type source delivers types of institutions
51    in the portal.
52    """
53    #: name of dict to deliver from kofa utils.
54    DICT_NAME = 'INST_TYPES_DICT'
55
56class AppCatSource(ContextualDictSourceFactoryBase):
[7681]57    """A application category source delivers all application categories
58    provided in the portal.
59    """
[7916]60    #: name of dict to deliver from kofa utils.
61    DICT_NAME = 'APP_CATS_DICT'
[7681]62
[7916]63class StudyModeSource(ContextualDictSourceFactoryBase):
[7681]64    """A study modes source delivers all study modes provided
65    in the portal.
66    """
[7916]67    #: name of dict to deliver from kofa utils.
68    DICT_NAME = 'STUDY_MODES_DICT'
[7681]69
[13617]70class DegreeSource(ContextualDictSourceFactoryBase):
71    """A source for certificate degrees
72    """
73    #: name of dict to deliver from kofa utils.
74    DICT_NAME = 'DEGREES_DICT'
75
76    def getTitle(self, context, value):
77        utils = getUtility(IKofaUtils)
78        return "%s (%s)" % (getattr(utils, self.DICT_NAME)[value], value)
79
[6091]80class CourseSource(BasicSourceFactory):
81    """A course source delivers all courses inside the portal by looking
82       up a catalog.
83    """
84    def getValues(self):
85        catalog = getUtility(ICatalog, name='courses_catalog')
[6092]86        return sorted(list(
87                catalog.searchResults(
[7916]88                    code=(None, None))),key=lambda value: value.code)
[6091]89
90    def getToken(self, value):
91        return value.code
92
93    def getTitle(self, value):
94        return "%s - %s" % (value.code, value.title[:64])
[7915]95
[8606]96
97
98class CertificateSource(SmartBasicContextualSourceFactory):
[7915]99    """A certificate source delivers all certificates provided
100    in the portal.
101    """
102    def getValues(self, context):
103        catalog = getUtility(ICatalog, name='certificates_catalog')
104        return sorted(list(
[7916]105            catalog.searchResults(
106                code=(None, None))),
107                      key=lambda value: value.code)
[7915]108
109    def getToken(self, context, value):
110        return value.code
111
112    def getTitle(self, context, value):
[8439]113        return "%s - %s" % (value.code, value.title)
[10831]114
115class SpecialApplicationSource(ContextualDictSourceFactoryBase):
116    """A special application source delivers all types of
117    applications which are not linked with certificates.
118    """
119    #: name of dict to deliver from kofa utils.
120    DICT_NAME = 'SPECIAL_APP_DICT'
Note: See TracBrowser for help on using the repository browser.