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

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

We don't need methods to fetch dictionaries.

Update interfaces.

  • Property svn:keywords set to Id
File size: 4.2 KB
Line 
1## $Id: vocabularies.py 7841 2012-03-12 08:04: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##
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
24from waeup.kofa.interfaces import SimpleKofaVocabulary, IKofaUtils
25from waeup.kofa.interfaces import MessageFactory as _
26
27course_levels = SimpleKofaVocabulary(
28    (_('Pre-Studies'),10),
29    (_('100 (Year 1)'),100),
30    (_('200 (Year 2)'),200),
31    (_('300 (Year 3)'),300),
32    (_('400 (Year 4)'),400),
33    (_('500 (Year 5)'),500),
34    (_('600 (Year 6)'),600),
35    (_('700 (Year 7)'),700),
36    (_('800 (Year 8)'),800),
37    )
38
39class SemesterSource(BasicSourceFactory):
40    """An institution type source delivers semester or term descriptors.
41    """
42    def getValues(self):
43        try:
44            # We have to 'try', don't know why (henrik)
45            # Alternatively, we can use BasicContextualSourceFactory,
46            # see sources below
47            from waeup.kofa.interfaces import IKofaUtils
48            return getUtility(IKofaUtils).SEMESTER_DICT.keys()
49        except:
50            return [9]
51       
52    def getToken(self, value):
53        return str(value)
54
55    def getTitle(self, value):
56        try:
57            from waeup.kofa.interfaces import IKofaUtils
58            semesters_dict = getUtility(IKofaUtils).SEMESTER_DICT
59            return semesters_dict[value]
60        except:
61            value
62
63class InstTypeSource(BasicContextualSourceFactory):
64    """An institution type source delivers types of institutions
65    in the portal.
66    """
67    def getValues(self, context):
68        insttypes_dict = getUtility(IKofaUtils).INST_TYPES_DICT
69        return sorted(insttypes_dict.keys())
70
71    def getToken(self, context, value):
72        return value
73
74    def getTitle(self, context, value):
75        insttypes_dict = getUtility(IKofaUtils).INST_TYPES_DICT
76        return insttypes_dict[value]
77
78class AppCatSource(BasicContextualSourceFactory):
79    """A application category source delivers all application categories
80    provided in the portal.
81    """
82    def getValues(self, context):
83        appcats_dict = getUtility(IKofaUtils).APP_CATS_DICT
84        return sorted(appcats_dict.keys())
85
86    def getToken(self, context, value):
87        return value
88
89    def getTitle(self, context, value):
90        appcats_dict = getUtility(IKofaUtils).APP_CATS_DICT
91        return appcats_dict[value]
92
93class StudyModeSource(BasicContextualSourceFactory):
94    """A study modes source delivers all study modes provided
95    in the portal.
96    """
97    def getValues(self, context):
98        studymodes_dict = getUtility(IKofaUtils).STUDY_MODES_DICT
99        return sorted(studymodes_dict.keys())
100
101    def getToken(self, context, value):
102        return value
103
104    def getTitle(self, context, value):
105        studymodes_dict = getUtility(IKofaUtils).STUDY_MODES_DICT
106        return studymodes_dict[value]
107
108class CourseSource(BasicSourceFactory):
109    """A course source delivers all courses inside the portal by looking
110       up a catalog.
111    """
112    def getValues(self):
113        catalog = getUtility(ICatalog, name='courses_catalog')
114        return sorted(list(
115                catalog.searchResults(
116                    code=('', 'z*'))),key=lambda value: value.code)
117
118    def getToken(self, value):
119        return value.code
120
121    def getTitle(self, value):
122        return "%s - %s" % (value.code, value.title[:64])
Note: See TracBrowser for help on using the repository browser.