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

Last change on this file since 11704 was 11450, checked in by Henrik Bettermann, 11 years ago

Move ContextualDictSourceFactoryBase? to waeup.kofa.interfaces to avoid circular imports.

  • Property svn:keywords set to Id
File size: 3.8 KB
Line 
1## $Id: vocabularies.py 11450 2014-02-27 06:25:18Z 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##
18"""Vocabularies and sources for the academics section.
19"""
20from zc.sourcefactory.basic import BasicSourceFactory
21from zope.catalog.interfaces import ICatalog
22from zope.component import getUtility, queryUtility
23from waeup.kofa.interfaces import (
24    SimpleKofaVocabulary, IKofaUtils, ContextualDictSourceFactoryBase)
25from waeup.kofa.interfaces import MessageFactory as _
26from waeup.kofa.sourcefactory import SmartBasicContextualSourceFactory
27from waeup.kofa.utils.utils import KofaUtils
28
29course_levels = SimpleKofaVocabulary(
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),
39    (_('900 (Year 9)'),900),
40    (_('Postgraduate Level'),999),
41    )
42
43class SemesterSource(ContextualDictSourceFactoryBase):
44    """An institution type source delivers semester and/or term descriptors.
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):
57    """A application category source delivers all application categories
58    provided in the portal.
59    """
60    #: name of dict to deliver from kofa utils.
61    DICT_NAME = 'APP_CATS_DICT'
62
63class StudyModeSource(ContextualDictSourceFactoryBase):
64    """A study modes source delivers all study modes provided
65    in the portal.
66    """
67    #: name of dict to deliver from kofa utils.
68    DICT_NAME = 'STUDY_MODES_DICT'
69
70class CourseSource(BasicSourceFactory):
71    """A course source delivers all courses inside the portal by looking
72       up a catalog.
73    """
74    def getValues(self):
75        catalog = getUtility(ICatalog, name='courses_catalog')
76        return sorted(list(
77                catalog.searchResults(
78                    code=(None, None))),key=lambda value: value.code)
79
80    def getToken(self, value):
81        return value.code
82
83    def getTitle(self, value):
84        return "%s - %s" % (value.code, value.title[:64])
85
86
87
88class CertificateSource(SmartBasicContextualSourceFactory):
89    """A certificate source delivers all certificates provided
90    in the portal.
91    """
92    def getValues(self, context):
93        catalog = getUtility(ICatalog, name='certificates_catalog')
94        return sorted(list(
95            catalog.searchResults(
96                code=(None, None))),
97                      key=lambda value: value.code)
98
99    def getToken(self, context, value):
100        return value.code
101
102    def getTitle(self, context, value):
103        return "%s - %s" % (value.code, value.title)
104
105class SpecialApplicationSource(ContextualDictSourceFactoryBase):
106    """A special application source delivers all types of
107    applications which are not linked with certificates.
108    """
109    #: name of dict to deliver from kofa utils.
110    DICT_NAME = 'SPECIAL_APP_DICT'
Note: See TracBrowser for help on using the repository browser.