"""Vocabularies and sources for the student section. """ from datetime import datetime from zope.component import getUtility from zope.catalog.interfaces import ICatalog from zc.sourcefactory.basic import BasicSourceFactory from zc.sourcefactory.contextual import BasicContextualSourceFactory from waeup.sirp.interfaces import SimpleWAeUPVocabulary from waeup.sirp.students.lgas import LGAS def year_range(): curr_year = datetime.now().year return range(curr_year - 2, curr_year + 5) def entry_sessions(): curr_year = datetime.now().year year_range = range(curr_year - 5, curr_year + 2) return [('%s/%s' % (year,year+1), '%s' % year) for year in year_range] entry_session_vocab = SimpleWAeUPVocabulary(*entry_sessions()) lgas_vocab = SimpleWAeUPVocabulary( *sorted([(x[1],x[0]) for x in LGAS])) class CertificateSource(BasicContextualSourceFactory): """A certificate source delivers all certificates provided in the portal. """ def getValues(self, context): catalog = getUtility(ICatalog, name='certificates_catalog') return sorted(list( catalog.searchResults( code=('', 'z*'))), key=lambda value: value.code) def getToken(self, context, value): return value.code def getTitle(self, context, value): return "%s - %s" % (value.code, value.title[:64]) class GenderSource(BasicSourceFactory): """A gender source delivers basically a mapping ``{'m': 'Male', 'f': 'Female'}`` Using a source, we make sure that the tokens (which are stored/expected for instance from CSV files) are something one can expect and not cryptic IntIDs. """ def getValues(self): return ['m', 'f'] def getToken(self, value): return value[0].lower() def getTitle(self, value): if value == 'm': return 'Male' if value == 'f': return 'Female'