from waeup.sirp.interfaces import SimpleWAeUPVocabulary from zc.sourcefactory.basic import BasicSourceFactory try: from zope.catalog.interfaces import ICatalog except ImportError: # BBB from zope.app.catalog.interfaces import ICatalog from zope.component import getUtility course_levels = SimpleWAeUPVocabulary( ('Year 1 (100)',100), ('Year 2 (200)',200), ('Year 3 (300)',300), ('Year 4 (400)',400), ('Year 5 (500)',500), ('Year 6 (600)',600), ('Year 7 (700)',700), ('Year 8 (800)',800), ) semester = SimpleWAeUPVocabulary( ('N/A', 0), ('First Semester', 1), ('Second Semester', 2), ('Combined', 3)) class CourseSource(BasicSourceFactory): """A course source delivers all courses inside the portal by looking up a catalog. """ def getValues(self): catalog = getUtility(ICatalog, name='courses_catalog') return sorted(list(catalog.searchResults(code=('', 'z*'))),key=lambda value: value.code) def getToken(self, value): return value.code def getTitle(self, value): return "%s - %s" % (value.code, value.title[:64])