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

Last change on this file since 8565 was 8471, checked in by Henrik Bettermann, 13 years ago

Add new workflow transitions for postgraduate students. Take care for correct payment. Since pg students bypass course registration, we need new names and titles for session activation button and page.

  • Property svn:keywords set to Id
File size: 4.2 KB
Line 
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##
18"""Vocabularies and sources for the academics section.
19"""
20from zc.sourcefactory.basic import BasicSourceFactory
21from zc.sourcefactory.contextual import BasicContextualSourceFactory
22from zope.catalog.interfaces import ICatalog
23from zope.component import getUtility, queryUtility
24from waeup.kofa.interfaces import SimpleKofaVocabulary, IKofaUtils
25from waeup.kofa.interfaces import MessageFactory as _
26from waeup.kofa.utils.utils import KofaUtils
27
28course_levels = SimpleKofaVocabulary(
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),
38    (_('900 (Year 9)'),900),
39    (_('Postgraduate Level'),999),
40    )
41
42#: An instance of :class:`waeup.kofa.utils.utils.KofaUtils` for fallback.
43KOFA_UTILS = KofaUtils()
44
45class ContextualDictSourceFactoryBase(BasicContextualSourceFactory):
46    """A base for contextual sources based on KofaUtils dicts.
47
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.
50    """
51    def getValues(self, context):
52        utils = queryUtility(IKofaUtils, default=KOFA_UTILS)
53        return sorted(getattr(utils, self.DICT_NAME).keys())
54
55    def getToken(self, context, value):
56        return str(value)
57
58    def getTitle(self, context, value):
59        utils = queryUtility(IKofaUtils, default=KOFA_UTILS)
60        return getattr(utils, self.DICT_NAME)[value]
61
62class 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
68class 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
75class AppCatSource(ContextualDictSourceFactoryBase):
76    """A application category source delivers all application categories
77    provided in the portal.
78    """
79    #: name of dict to deliver from kofa utils.
80    DICT_NAME = 'APP_CATS_DICT'
81
82class StudyModeSource(ContextualDictSourceFactoryBase):
83    """A study modes source delivers all study modes provided
84    in the portal.
85    """
86    #: name of dict to deliver from kofa utils.
87    DICT_NAME = 'STUDY_MODES_DICT'
88
89class 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')
95        return sorted(list(
96                catalog.searchResults(
97                    code=(None, None))),key=lambda value: value.code)
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])
104
105class 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(
112            catalog.searchResults(
113                code=(None, None))),
114                      key=lambda value: value.code)
115
116    def getToken(self, context, value):
117        return value.code
118
119    def getTitle(self, context, value):
120        return "%s - %s" % (value.code, value.title)
Note: See TracBrowser for help on using the repository browser.