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

Last change on this file since 7856 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
RevLine 
[7195]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##
[6091]18"""Vocabularies and sources for the academics section.
19"""
20from zc.sourcefactory.basic import BasicSourceFactory
[7681]21from zc.sourcefactory.contextual import BasicContextualSourceFactory
[6557]22from zope.catalog.interfaces import ICatalog
[6091]23from zope.component import getUtility
[7819]24from waeup.kofa.interfaces import SimpleKofaVocabulary, IKofaUtils
[7811]25from waeup.kofa.interfaces import MessageFactory as _
[6091]26
[7819]27course_levels = SimpleKofaVocabulary(
[7681]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),
[6091]37    )
38
[7838]39class SemesterSource(BasicSourceFactory):
[7681]40    """An institution type source delivers semester or term descriptors.
41    """
[7838]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
[7841]48            return getUtility(IKofaUtils).SEMESTER_DICT.keys()
[7838]49        except:
50            return [9]
51       
52    def getToken(self, value):
[7681]53        return str(value)
[6091]54
[7838]55    def getTitle(self, value):
56        try:
57            from waeup.kofa.interfaces import IKofaUtils
[7841]58            semesters_dict = getUtility(IKofaUtils).SEMESTER_DICT
[7838]59            return semesters_dict[value]
60        except:
61            value
[6091]62
[7681]63class InstTypeSource(BasicContextualSourceFactory):
64    """An institution type source delivers types of institutions
65    in the portal.
66    """
67    def getValues(self, context):
[7841]68        insttypes_dict = getUtility(IKofaUtils).INST_TYPES_DICT
[7688]69        return sorted(insttypes_dict.keys())
[7681]70
71    def getToken(self, context, value):
72        return value
73
74    def getTitle(self, context, value):
[7841]75        insttypes_dict = getUtility(IKofaUtils).INST_TYPES_DICT
[7688]76        return insttypes_dict[value]
[7681]77
78class AppCatSource(BasicContextualSourceFactory):
79    """A application category source delivers all application categories
80    provided in the portal.
81    """
82    def getValues(self, context):
[7841]83        appcats_dict = getUtility(IKofaUtils).APP_CATS_DICT
[7688]84        return sorted(appcats_dict.keys())
[7681]85
86    def getToken(self, context, value):
87        return value
88
89    def getTitle(self, context, value):
[7841]90        appcats_dict = getUtility(IKofaUtils).APP_CATS_DICT
[7688]91        return appcats_dict[value]
[7681]92
93class StudyModeSource(BasicContextualSourceFactory):
94    """A study modes source delivers all study modes provided
95    in the portal.
96    """
97    def getValues(self, context):
[7841]98        studymodes_dict = getUtility(IKofaUtils).STUDY_MODES_DICT
[7688]99        return sorted(studymodes_dict.keys())
[7681]100
101    def getToken(self, context, value):
102        return value
103
104    def getTitle(self, context, value):
[7841]105        studymodes_dict = getUtility(IKofaUtils).STUDY_MODES_DICT
[7688]106        return studymodes_dict[value]
[7681]107
[6091]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')
[6092]114        return sorted(list(
115                catalog.searchResults(
116                    code=('', 'z*'))),key=lambda value: value.code)
[6091]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.