## $Id: vocabularies.py 7341 2011-12-14 13:38:59Z henrik $ ## ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## """Vocabularies and sources for the application section. """ from zope.component import getUtility from zope.catalog.interfaces import ICatalog from waeup.sirp.interfaces import SimpleSIRPVocabulary from zc.sourcefactory.contextual import BasicContextualSourceFactory #: Types of applications we support. APPLICATION_TYPES = ( ('General Studies', 'app','APP'), ('Pre-NCE Programme', 'prence','PRE'), ('Post UME Screening Test', 'pume','PUME'), ('Post UDE Screening', 'pude','PUDE'), ('Part Time Degree in Education', 'sandwich','SAND'), ('Part-Time Degree Programmes', 'pt','PTP'), ('Diploma Programmes', 'dp','DPP'), ('PCE Screening', 'pce','PCE'), ('Certificate Programmes', 'ct','CTP'), ('Common Entry Screening Test', 'cest','CEST'), ) #: A :class:`waeup.sirp.interfaces.SimpleSIRPVocabulary` of supported #: application or screening types. application_types_vocab = SimpleSIRPVocabulary( *[(x[0],x[1]) for x in APPLICATION_TYPES]) application_pins_vocab = SimpleSIRPVocabulary( *[(u"%s (%s)" % (x[2],x[0]),x[2]) for x in APPLICATION_TYPES]) class CertificateTitleSource(BasicContextualSourceFactory): """A certificate title source delivers all certificates titles provided in the portal. """ def getValues(self, context): catalog = getUtility(ICatalog, name='certificates_catalog') certs = list(catalog.searchResults(code=('', 'z*'))) certs = [dict( code = i.code, title = i.title, dep = i.__parent__.__parent__.longtitle(), fac = i.__parent__.__parent__.__parent__.longtitle() ) for i in certs] return sorted(certs, 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 AppCatCertificateTitleSource(CertificateTitleSource): """An application certificate source delivers all course titles which belong to a certain application_category. """ def getValues(self, context): appcat = context.__parent__.application_category catalog = getUtility(ICatalog, name='certificates_catalog') certs = list(catalog.searchResults(code=('', 'z*'), application_category=(appcat,appcat))) certs = [dict( code = i.code, title = i.title, dep = i.__parent__.__parent__.longtitle(), fac = i.__parent__.__parent__.__parent__.longtitle() ) for i in certs] return sorted(certs, key=lambda value: value['code'])