1 | """Vocabularies and sources for the student section. |
---|
2 | """ |
---|
3 | from datetime import datetime |
---|
4 | from zope.component import getUtility |
---|
5 | from zope.catalog.interfaces import ICatalog |
---|
6 | from zc.sourcefactory.basic import BasicSourceFactory |
---|
7 | from zc.sourcefactory.contextual import BasicContextualSourceFactory |
---|
8 | from waeup.sirp.interfaces import SimpleWAeUPVocabulary |
---|
9 | from waeup.sirp.students.lgas import LGAS |
---|
10 | |
---|
11 | def year_range(): |
---|
12 | curr_year = datetime.now().year |
---|
13 | return range(curr_year - 2, curr_year + 5) |
---|
14 | |
---|
15 | def entry_sessions(): |
---|
16 | curr_year = datetime.now().year |
---|
17 | year_range = range(curr_year - 5, curr_year + 2) |
---|
18 | return [('%s/%s' % (year,year+1), '%s' % year) for year in year_range] |
---|
19 | |
---|
20 | entry_session_vocab = SimpleWAeUPVocabulary(*entry_sessions()) |
---|
21 | |
---|
22 | lgas_vocab = SimpleWAeUPVocabulary( |
---|
23 | *sorted([(x[1],x[0]) for x in LGAS])) |
---|
24 | |
---|
25 | class CertificateSource(BasicContextualSourceFactory): |
---|
26 | """A certificate source delivers all certificates provided |
---|
27 | in the portal. |
---|
28 | """ |
---|
29 | def getValues(self, context): |
---|
30 | catalog = getUtility(ICatalog, name='certificates_catalog') |
---|
31 | return sorted(list( |
---|
32 | catalog.searchResults( |
---|
33 | code=('', 'z*'))), |
---|
34 | key=lambda value: value.code) |
---|
35 | |
---|
36 | def getToken(self, context, value): |
---|
37 | return value.code |
---|
38 | |
---|
39 | def getTitle(self, context, value): |
---|
40 | return "%s - %s" % (value.code, value.title[:64]) |
---|
41 | |
---|
42 | |
---|
43 | class GenderSource(BasicSourceFactory): |
---|
44 | """A gender source delivers basically a mapping |
---|
45 | ``{'m': 'Male', 'f': 'Female'}`` |
---|
46 | |
---|
47 | Using a source, we make sure that the tokens (which are |
---|
48 | stored/expected for instance from CSV files) are something one |
---|
49 | can expect and not cryptic IntIDs. |
---|
50 | """ |
---|
51 | def getValues(self): |
---|
52 | return ['m', 'f'] |
---|
53 | |
---|
54 | def getToken(self, value): |
---|
55 | return value[0].lower() |
---|
56 | |
---|
57 | def getTitle(self, value): |
---|
58 | if value == 'm': |
---|
59 | return 'Male' |
---|
60 | if value == 'f': |
---|
61 | return 'Female' |
---|