Index: /main/waeup.kofa/trunk/src/waeup/kofa/university/vocabularies.py
===================================================================
--- /main/waeup.kofa/trunk/src/waeup/kofa/university/vocabularies.py	(revision 7915)
+++ /main/waeup.kofa/trunk/src/waeup/kofa/university/vocabularies.py	(revision 7916)
@@ -21,7 +21,8 @@
 from zc.sourcefactory.contextual import BasicContextualSourceFactory
 from zope.catalog.interfaces import ICatalog
-from zope.component import getUtility
+from zope.component import getUtility, queryUtility
 from waeup.kofa.interfaces import SimpleKofaVocabulary, IKofaUtils
 from waeup.kofa.interfaces import MessageFactory as _
+from waeup.kofa.utils.utils import KofaUtils
 
 course_levels = SimpleKofaVocabulary(
@@ -37,72 +38,50 @@
     )
 
-class SemesterSource(BasicSourceFactory):
+#: An instance of :class:`waeup.kofa.utils.utils.KofaUtils` for fallback.
+KOFA_UTILS = KofaUtils()
+
+class ContextualDictSourceFactoryBase(BasicContextualSourceFactory):
+    """A base for contextual sources based on KofaUtils dicts.
+
+    To create a real source, you have to set the `DICT_NAME` attribute
+    which should be the name of a dictionary in KofaUtils.
+    """
+    def getValues(self, context):
+        utils = queryUtility(IKofaUtils, default=KOFA_UTILS)
+        return sorted(getattr(utils, self.DICT_NAME).keys())
+
+    def getToken(self, context, value):
+        return str(value)
+
+    def getTitle(self, context, value):
+        utils = queryUtility(IKofaUtils, default=KOFA_UTILS)
+        return getattr(utils, self.DICT_NAME)[value]
+
+class SemesterSource(ContextualDictSourceFactoryBase):
     """An institution type source delivers semester or term descriptors.
     """
-    def getValues(self):
-        try:
-            # We have to 'try', don't know why (henrik)
-            # Alternatively, we can use BasicContextualSourceFactory,
-            # see sources below
-            from waeup.kofa.interfaces import IKofaUtils
-            return getUtility(IKofaUtils).SEMESTER_DICT.keys()
-        except:
-            return [9]
-        
-    def getToken(self, value):
-        return str(value)
+    #: name of dict to deliver from kofa utils.
+    DICT_NAME = 'SEMESTER_DICT'
 
-    def getTitle(self, value):
-        try:
-            from waeup.kofa.interfaces import IKofaUtils
-            semesters_dict = getUtility(IKofaUtils).SEMESTER_DICT
-            return semesters_dict[value]
-        except:
-            value
-
-class InstTypeSource(BasicContextualSourceFactory):
+class InstTypeSource(ContextualDictSourceFactoryBase):
     """An institution type source delivers types of institutions
     in the portal.
     """
-    def getValues(self, context):
-        insttypes_dict = getUtility(IKofaUtils).INST_TYPES_DICT
-        return sorted(insttypes_dict.keys())
+    #: name of dict to deliver from kofa utils.
+    DICT_NAME = 'INST_TYPES_DICT'
 
-    def getToken(self, context, value):
-        return value
-
-    def getTitle(self, context, value):
-        insttypes_dict = getUtility(IKofaUtils).INST_TYPES_DICT
-        return insttypes_dict[value]
-
-class AppCatSource(BasicContextualSourceFactory):
+class AppCatSource(ContextualDictSourceFactoryBase):
     """A application category source delivers all application categories
     provided in the portal.
     """
-    def getValues(self, context):
-        appcats_dict = getUtility(IKofaUtils).APP_CATS_DICT
-        return sorted(appcats_dict.keys())
+    #: name of dict to deliver from kofa utils.
+    DICT_NAME = 'APP_CATS_DICT'
 
-    def getToken(self, context, value):
-        return value
-
-    def getTitle(self, context, value):
-        appcats_dict = getUtility(IKofaUtils).APP_CATS_DICT
-        return appcats_dict[value]
-
-class StudyModeSource(BasicContextualSourceFactory):
+class StudyModeSource(ContextualDictSourceFactoryBase):
     """A study modes source delivers all study modes provided
     in the portal.
     """
-    def getValues(self, context):
-        studymodes_dict = getUtility(IKofaUtils).STUDY_MODES_DICT
-        return sorted(studymodes_dict.keys())
-
-    def getToken(self, context, value):
-        return value
-
-    def getTitle(self, context, value):
-        studymodes_dict = getUtility(IKofaUtils).STUDY_MODES_DICT
-        return studymodes_dict[value]
+    #: name of dict to deliver from kofa utils.
+    DICT_NAME = 'STUDY_MODES_DICT'
 
 class CourseSource(BasicSourceFactory):
@@ -114,5 +93,5 @@
         return sorted(list(
                 catalog.searchResults(
-                    code=('', 'z*'))),key=lambda value: value.code)
+                    code=(None, None))),key=lambda value: value.code)
 
     def getToken(self, value):
@@ -129,7 +108,7 @@
         catalog = getUtility(ICatalog, name='certificates_catalog')
         return sorted(list(
-                catalog.searchResults(
-                    code=('', 'z*'))),
-                    key=lambda value: value.code)
+            catalog.searchResults(
+                code=(None, None))),
+                      key=lambda value: value.code)
 
     def getToken(self, context, value):
