Changeset 7916 for main/waeup.kofa/trunk
- Timestamp:
- 19 Mar 2012, 05:23:01 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/university/vocabularies.py
r7915 r7916 21 21 from zc.sourcefactory.contextual import BasicContextualSourceFactory 22 22 from zope.catalog.interfaces import ICatalog 23 from zope.component import getUtility 23 from zope.component import getUtility, queryUtility 24 24 from waeup.kofa.interfaces import SimpleKofaVocabulary, IKofaUtils 25 25 from waeup.kofa.interfaces import MessageFactory as _ 26 from waeup.kofa.utils.utils import KofaUtils 26 27 27 28 course_levels = SimpleKofaVocabulary( … … 37 38 ) 38 39 39 class SemesterSource(BasicSourceFactory): 40 #: An instance of :class:`waeup.kofa.utils.utils.KofaUtils` for fallback. 41 KOFA_UTILS = KofaUtils() 42 43 class ContextualDictSourceFactoryBase(BasicContextualSourceFactory): 44 """A base for contextual sources based on KofaUtils dicts. 45 46 To create a real source, you have to set the `DICT_NAME` attribute 47 which should be the name of a dictionary in KofaUtils. 48 """ 49 def getValues(self, context): 50 utils = queryUtility(IKofaUtils, default=KOFA_UTILS) 51 return sorted(getattr(utils, self.DICT_NAME).keys()) 52 53 def getToken(self, context, value): 54 return str(value) 55 56 def getTitle(self, context, value): 57 utils = queryUtility(IKofaUtils, default=KOFA_UTILS) 58 return getattr(utils, self.DICT_NAME)[value] 59 60 class SemesterSource(ContextualDictSourceFactoryBase): 40 61 """An institution type source delivers semester or term descriptors. 41 62 """ 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) 63 #: name of dict to deliver from kofa utils. 64 DICT_NAME = 'SEMESTER_DICT' 54 65 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 63 class InstTypeSource(BasicContextualSourceFactory): 66 class InstTypeSource(ContextualDictSourceFactoryBase): 64 67 """An institution type source delivers types of institutions 65 68 in the portal. 66 69 """ 67 def getValues(self, context): 68 insttypes_dict = getUtility(IKofaUtils).INST_TYPES_DICT 69 return sorted(insttypes_dict.keys()) 70 #: name of dict to deliver from kofa utils. 71 DICT_NAME = 'INST_TYPES_DICT' 70 72 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 78 class AppCatSource(BasicContextualSourceFactory): 73 class AppCatSource(ContextualDictSourceFactoryBase): 79 74 """A application category source delivers all application categories 80 75 provided in the portal. 81 76 """ 82 def getValues(self, context): 83 appcats_dict = getUtility(IKofaUtils).APP_CATS_DICT 84 return sorted(appcats_dict.keys()) 77 #: name of dict to deliver from kofa utils. 78 DICT_NAME = 'APP_CATS_DICT' 85 79 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 93 class StudyModeSource(BasicContextualSourceFactory): 80 class StudyModeSource(ContextualDictSourceFactoryBase): 94 81 """A study modes source delivers all study modes provided 95 82 in the portal. 96 83 """ 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] 84 #: name of dict to deliver from kofa utils. 85 DICT_NAME = 'STUDY_MODES_DICT' 107 86 108 87 class CourseSource(BasicSourceFactory): … … 114 93 return sorted(list( 115 94 catalog.searchResults( 116 code=( '', 'z*'))),key=lambda value: value.code)95 code=(None, None))),key=lambda value: value.code) 117 96 118 97 def getToken(self, value): … … 129 108 catalog = getUtility(ICatalog, name='certificates_catalog') 130 109 return sorted(list( 131 132 code=('', 'z*'))),133 key=lambda value: value.code)110 catalog.searchResults( 111 code=(None, None))), 112 key=lambda value: value.code) 134 113 135 114 def getToken(self, context, value):
Note: See TracChangeset for help on using the changeset viewer.