source: main/waeup.sirp/trunk/src/waeup/sirp/university/vocabularies.py @ 11094

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

Fix sources.

  • Property svn:keywords set to Id
File size: 3.9 KB
RevLine 
[7195]1## $Id: vocabularies.py 7688 2012-02-23 12:25:23Z 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
[7681]24from waeup.sirp.interfaces import SimpleSIRPVocabulary, ISIRPUtils
25from waeup.sirp.interfaces import MessageFactory as _
[6091]26
[7321]27course_levels = SimpleSIRPVocabulary(
[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
[7681]39class SemesterSource(BasicContextualSourceFactory):
40    """An institution type source delivers semester or term descriptors.
41    """
42    def getValues(self, context):
[7688]43        semesters_dict = getUtility(ISIRPUtils).getSemesterDict()
44        return semesters_dict.keys()
[6091]45
[7681]46    def getToken(self, context, value):
47        return str(value)
[6091]48
[7681]49    def getTitle(self, context, value):
[7688]50        semesters_dict = getUtility(ISIRPUtils).getSemesterDict()
51        return semesters_dict[value]
[6091]52
[7681]53class InstTypeSource(BasicContextualSourceFactory):
54    """An institution type source delivers types of institutions
55    in the portal.
56    """
57    def getValues(self, context):
[7688]58        insttypes_dict = getUtility(ISIRPUtils).getInstTypeDict()
59        return sorted(insttypes_dict.keys())
[7681]60
61    def getToken(self, context, value):
62        return value
63
64    def getTitle(self, context, value):
[7688]65        insttypes_dict = getUtility(ISIRPUtils).getInstTypeDict()
66        return insttypes_dict[value]
[7681]67
68class AppCatSource(BasicContextualSourceFactory):
69    """A application category source delivers all application categories
70    provided in the portal.
71    """
72    def getValues(self, context):
[7688]73        appcats_dict = getUtility(ISIRPUtils).getAppCatDict()
74        return sorted(appcats_dict.keys())
[7681]75
76    def getToken(self, context, value):
77        return value
78
79    def getTitle(self, context, value):
[7688]80        appcats_dict = getUtility(ISIRPUtils).getAppCatDict()
81        return appcats_dict[value]
[7681]82
83class StudyModeSource(BasicContextualSourceFactory):
84    """A study modes source delivers all study modes provided
85    in the portal.
86    """
87    def getValues(self, context):
[7688]88        studymodes_dict = getUtility(ISIRPUtils).getStudyModesDict()
89        return sorted(studymodes_dict.keys())
[7681]90
91    def getToken(self, context, value):
92        return value
93
94    def getTitle(self, context, value):
[7688]95        studymodes_dict = getUtility(ISIRPUtils).getStudyModesDict()
96        return studymodes_dict[value]
[7681]97
[6091]98class CourseSource(BasicSourceFactory):
99    """A course source delivers all courses inside the portal by looking
100       up a catalog.
101    """
102    def getValues(self):
103        catalog = getUtility(ICatalog, name='courses_catalog')
[6092]104        return sorted(list(
105                catalog.searchResults(
106                    code=('', 'z*'))),key=lambda value: value.code)
[6091]107
108    def getToken(self, value):
109        return value.code
110
111    def getTitle(self, value):
112        return "%s - %s" % (value.code, value.title[:64])
Note: See TracBrowser for help on using the repository browser.