source: main/waeup.sirp/trunk/src/waeup/sirp/applicants/vocabularies.py @ 6607

Last change on this file since 6607 was 6393, checked in by uli, 13 years ago

* empty log message *

  • Property svn:keywords set to Id
File size: 3.3 KB
Line 
1"""Vocabularies and sources for the application section.
2"""
3from datetime import datetime
4from zope.component import getUtility
5from zope.catalog.interfaces import ICatalog
6from zc.sourcefactory.basic import BasicSourceFactory
7from zc.sourcefactory.contextual import BasicContextualSourceFactory
8from waeup.sirp.interfaces import SimpleWAeUPVocabulary
9from waeup.sirp.applicants.lgas import LGAS
10
11#: Types of applications we support.
12APPLICATION_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.
27application_types_vocab = SimpleWAeUPVocabulary(
28    *[(x[0],x[1]) for x in APPLICATION_TYPES])
29application_pins_vocab = SimpleWAeUPVocabulary(
30    *[(u"%s (%s)" % (x[2],x[0]),x[2]) for x in APPLICATION_TYPES])
31lgas_vocab = SimpleWAeUPVocabulary(
32    *sorted([(x[1],x[0]) for x in LGAS]))
33
34def year_range():
35    curr_year = datetime.now().year
36    return range(curr_year - 2, curr_year + 5)
37
38def 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
43entry_session_vocab = SimpleWAeUPVocabulary(*entry_sessions())
44
45class 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
62class 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
75class GenderSource(BasicSourceFactory):
76    """A gender source delivers basically a mapping
77       ``{'m': 'Male', 'f': 'Female'}``
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':
91            return 'Male'
92        if value == 'f':
93            return 'Female'
Note: See TracBrowser for help on using the repository browser.