[7192] | 1 | ## $Id: vocabularies.py 7350 2011-12-15 11:54:05Z uli $ |
---|
| 2 | ## |
---|
| 3 | ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann |
---|
| 4 | ## This program is free software; you can redistribute it and/or modify |
---|
| 5 | ## it under the terms of the GNU General Public License as published by |
---|
| 6 | ## the Free Software Foundation; either version 2 of the License, or |
---|
| 7 | ## (at your option) any later version. |
---|
| 8 | ## |
---|
| 9 | ## This program is distributed in the hope that it will be useful, |
---|
| 10 | ## but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 11 | ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 12 | ## GNU General Public License for more details. |
---|
| 13 | ## |
---|
| 14 | ## You should have received a copy of the GNU General Public License |
---|
| 15 | ## along with this program; if not, write to the Free Software |
---|
| 16 | ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 17 | ## |
---|
[6256] | 18 | """Vocabularies and sources for the application section. |
---|
| 19 | """ |
---|
[6393] | 20 | from zope.component import getUtility |
---|
[6256] | 21 | from zope.catalog.interfaces import ICatalog |
---|
[7321] | 22 | from waeup.sirp.interfaces import SimpleSIRPVocabulary |
---|
[7347] | 23 | from waeup.sirp.students.vocabularies import CertificateSource |
---|
[6256] | 24 | |
---|
| 25 | #: Types of applications we support. |
---|
| 26 | APPLICATION_TYPES = ( |
---|
| 27 | ('General Studies', 'app','APP'), |
---|
| 28 | ('Pre-NCE Programme', 'prence','PRE'), |
---|
| 29 | ('Post UME Screening Test', 'pume','PUME'), |
---|
| 30 | ('Post UDE Screening', 'pude','PUDE'), |
---|
| 31 | ('Part Time Degree in Education', 'sandwich','SAND'), |
---|
| 32 | ('Part-Time Degree Programmes', 'pt','PTP'), |
---|
| 33 | ('Diploma Programmes', 'dp','DPP'), |
---|
| 34 | ('PCE Screening', 'pce','PCE'), |
---|
| 35 | ('Certificate Programmes', 'ct','CTP'), |
---|
| 36 | ('Common Entry Screening Test', 'cest','CEST'), |
---|
| 37 | ) |
---|
| 38 | |
---|
[7321] | 39 | #: A :class:`waeup.sirp.interfaces.SimpleSIRPVocabulary` of supported |
---|
[6256] | 40 | #: application or screening types. |
---|
[7321] | 41 | application_types_vocab = SimpleSIRPVocabulary( |
---|
[6256] | 42 | *[(x[0],x[1]) for x in APPLICATION_TYPES]) |
---|
[7321] | 43 | application_pins_vocab = SimpleSIRPVocabulary( |
---|
[6256] | 44 | *[(u"%s (%s)" % (x[2],x[0]),x[2]) for x in APPLICATION_TYPES]) |
---|
| 45 | |
---|
| 46 | |
---|
[7347] | 47 | class AppCatCertificateSource(CertificateSource): |
---|
| 48 | """An application certificate source delivers all courses which belong to |
---|
[6256] | 49 | a certain application_category. |
---|
| 50 | """ |
---|
| 51 | def getValues(self, context): |
---|
[7350] | 52 | # appliction category not available when certificate was deleted. |
---|
| 53 | # shouldn't that info be part of applicant info instead? |
---|
| 54 | # when we cannot determine the appcat, we will display all courses. |
---|
| 55 | appcat = getattr(getattr(context, '__parent__', None), |
---|
| 56 | 'application_category', None) |
---|
[6256] | 57 | catalog = getUtility(ICatalog, name='certificates_catalog') |
---|
[7350] | 58 | result = catalog.searchResults( |
---|
| 59 | application_category=(appcat,appcat)) |
---|
| 60 | curr_course = context.course1 |
---|
| 61 | if curr_course is not None and curr_course not in result: |
---|
| 62 | # display also current course even if it is not catalogued |
---|
| 63 | # (any more) |
---|
| 64 | result = [curr_course,] + result |
---|
| 65 | return sorted(result, key=lambda value: value.code) |
---|