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

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

Extend vocaularies for Uniben.

  • Property svn:keywords set to Id
File size: 4.2 KB
RevLine 
[7195]1## $Id: vocabularies.py 8084 2012-04-10 06:09:02Z 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
[7916]23from zope.component import getUtility, queryUtility
[7819]24from waeup.kofa.interfaces import SimpleKofaVocabulary, IKofaUtils
[7811]25from waeup.kofa.interfaces import MessageFactory as _
[7916]26from waeup.kofa.utils.utils import KofaUtils
[6091]27
[7819]28course_levels = SimpleKofaVocabulary(
[7681]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),
[8084]38    (_('900 (Year 9)'),900),
[6091]39    )
40
[7916]41#: An instance of :class:`waeup.kofa.utils.utils.KofaUtils` for fallback.
42KOFA_UTILS = KofaUtils()
[6091]43
[7916]44class ContextualDictSourceFactoryBase(BasicContextualSourceFactory):
45    """A base for contextual sources based on KofaUtils dicts.
[6091]46
[7916]47    To create a real source, you have to set the `DICT_NAME` attribute
48    which should be the name of a dictionary in KofaUtils.
[7681]49    """
50    def getValues(self, context):
[7916]51        utils = queryUtility(IKofaUtils, default=KOFA_UTILS)
52        return sorted(getattr(utils, self.DICT_NAME).keys())
[7681]53
54    def getToken(self, context, value):
[7916]55        return str(value)
[7681]56
57    def getTitle(self, context, value):
[7916]58        utils = queryUtility(IKofaUtils, default=KOFA_UTILS)
59        return getattr(utils, self.DICT_NAME)[value]
[7681]60
[7916]61class SemesterSource(ContextualDictSourceFactoryBase):
62    """An institution type source delivers semester or term descriptors.
63    """
64    #: name of dict to deliver from kofa utils.
65    DICT_NAME = 'SEMESTER_DICT'
66
67class InstTypeSource(ContextualDictSourceFactoryBase):
68    """An institution type source delivers types of institutions
69    in the portal.
70    """
71    #: name of dict to deliver from kofa utils.
72    DICT_NAME = 'INST_TYPES_DICT'
73
74class AppCatSource(ContextualDictSourceFactoryBase):
[7681]75    """A application category source delivers all application categories
76    provided in the portal.
77    """
[7916]78    #: name of dict to deliver from kofa utils.
79    DICT_NAME = 'APP_CATS_DICT'
[7681]80
[7916]81class StudyModeSource(ContextualDictSourceFactoryBase):
[7681]82    """A study modes source delivers all study modes provided
83    in the portal.
84    """
[7916]85    #: name of dict to deliver from kofa utils.
86    DICT_NAME = 'STUDY_MODES_DICT'
[7681]87
[6091]88class CourseSource(BasicSourceFactory):
89    """A course source delivers all courses inside the portal by looking
90       up a catalog.
91    """
92    def getValues(self):
93        catalog = getUtility(ICatalog, name='courses_catalog')
[6092]94        return sorted(list(
95                catalog.searchResults(
[7916]96                    code=(None, None))),key=lambda value: value.code)
[6091]97
98    def getToken(self, value):
99        return value.code
100
101    def getTitle(self, value):
102        return "%s - %s" % (value.code, value.title[:64])
[7915]103
104class CertificateSource(BasicContextualSourceFactory):
105    """A certificate source delivers all certificates provided
106    in the portal.
107    """
108    def getValues(self, context):
109        catalog = getUtility(ICatalog, name='certificates_catalog')
110        return sorted(list(
[7916]111            catalog.searchResults(
112                code=(None, None))),
113                      key=lambda value: value.code)
[7915]114
115    def getToken(self, context, value):
116        return value.code
117
118    def getTitle(self, context, value):
119        return "%s - %s" % (value.code, value.title[:64])
Note: See TracBrowser for help on using the repository browser.