[6256] | 1 | """Vocabularies and sources for the application section. |
---|
| 2 | """ |
---|
| 3 | from datetime import datetime |
---|
[6393] | 4 | from zope.component import getUtility |
---|
[6256] | 5 | from zope.catalog.interfaces import ICatalog |
---|
| 6 | from zc.sourcefactory.basic import BasicSourceFactory |
---|
| 7 | from zc.sourcefactory.contextual import BasicContextualSourceFactory |
---|
[6393] | 8 | from waeup.sirp.interfaces import SimpleWAeUPVocabulary |
---|
[6256] | 9 | from waeup.sirp.applicants.lgas import LGAS |
---|
| 10 | |
---|
| 11 | #: Types of applications we support. |
---|
| 12 | APPLICATION_TYPES = ( |
---|
| 13 | ('General Studies', 'app','APP'), |
---|
| 14 | ('Pre-NCE Programme', 'prence','PRE'), |
---|
| 15 | ('Post UME Screening Test', 'pume','PUME'), |
---|
| 16 | ('Post UDE Screening', 'pude','PUDE'), |
---|
| 17 | ('Part Time Degree in Education', 'sandwich','SAND'), |
---|
| 18 | ('Part-Time Degree Programmes', 'pt','PTP'), |
---|
| 19 | ('Diploma Programmes', 'dp','DPP'), |
---|
| 20 | ('PCE Screening', 'pce','PCE'), |
---|
| 21 | ('Certificate Programmes', 'ct','CTP'), |
---|
| 22 | ('Common Entry Screening Test', 'cest','CEST'), |
---|
| 23 | ) |
---|
| 24 | |
---|
| 25 | #: A :class:`waeup.sirp.interfaces.SimpleWAeUPVocabulary` of supported |
---|
| 26 | #: application or screening types. |
---|
| 27 | application_types_vocab = SimpleWAeUPVocabulary( |
---|
| 28 | *[(x[0],x[1]) for x in APPLICATION_TYPES]) |
---|
| 29 | application_pins_vocab = SimpleWAeUPVocabulary( |
---|
| 30 | *[(u"%s (%s)" % (x[2],x[0]),x[2]) for x in APPLICATION_TYPES]) |
---|
| 31 | lgas_vocab = SimpleWAeUPVocabulary( |
---|
| 32 | *sorted([(x[1],x[0]) for x in LGAS])) |
---|
| 33 | |
---|
| 34 | def year_range(): |
---|
| 35 | curr_year = datetime.now().year |
---|
| 36 | return range(curr_year - 2, curr_year + 5) |
---|
| 37 | |
---|
| 38 | def entry_sessions(): |
---|
| 39 | curr_year = datetime.now().year |
---|
| 40 | year_range = range(curr_year - 5, curr_year + 2) |
---|
| 41 | return [('%s/%s' % (year,year+1), '%s' % year) for year in year_range] |
---|
| 42 | |
---|
| 43 | entry_session_vocab = SimpleWAeUPVocabulary(*entry_sessions()) |
---|
| 44 | |
---|
| 45 | class CertificateSource(BasicContextualSourceFactory): |
---|
| 46 | """A certificate source delivers all certificates provided |
---|
| 47 | in the portal. |
---|
| 48 | """ |
---|
| 49 | def getValues(self, context): |
---|
| 50 | catalog = getUtility(ICatalog, name='certificates_catalog') |
---|
| 51 | return sorted(list( |
---|
| 52 | catalog.searchResults( |
---|
| 53 | code=('', 'z*'))), |
---|
| 54 | key=lambda value: value.code) |
---|
| 55 | |
---|
| 56 | def getToken(self, context, value): |
---|
| 57 | return value.code |
---|
| 58 | |
---|
| 59 | def getTitle(self, context, value): |
---|
| 60 | return "%s - %s" % (value.code, value.title[:64]) |
---|
| 61 | |
---|
| 62 | class AppCatCertificateSource(CertificateSource): |
---|
| 63 | """An application certificate source delivers all courses which belong to |
---|
| 64 | a certain application_category. |
---|
| 65 | """ |
---|
| 66 | def getValues(self, context): |
---|
| 67 | appcat = context.__parent__.application_category |
---|
| 68 | catalog = getUtility(ICatalog, name='certificates_catalog') |
---|
| 69 | return sorted(list( |
---|
| 70 | catalog.searchResults( |
---|
| 71 | code=('', 'z*'), |
---|
| 72 | application_category=(appcat,appcat))), |
---|
| 73 | key=lambda value: value.code) |
---|
| 74 | |
---|
| 75 | class GenderSource(BasicSourceFactory): |
---|
| 76 | """A gender source delivers basically a mapping |
---|
[6340] | 77 | ``{'m': 'Male', 'f': 'Female'}`` |
---|
[6256] | 78 | |
---|
| 79 | Using a source, we make sure that the tokens (which are |
---|
| 80 | stored/expected for instance from CSV files) are something one |
---|
| 81 | can expect and not cryptic IntIDs. |
---|
| 82 | """ |
---|
| 83 | def getValues(self): |
---|
| 84 | return ['m', 'f'] |
---|
| 85 | |
---|
| 86 | def getToken(self, value): |
---|
| 87 | return value[0].lower() |
---|
| 88 | |
---|
| 89 | def getTitle(self, value): |
---|
| 90 | if value == 'm': |
---|
[6340] | 91 | return 'Male' |
---|
[6256] | 92 | if value == 'f': |
---|
[6340] | 93 | return 'Female' |
---|