source: main/waeup.sirp/trunk/src/waeup/sirp/students/vocabularies.py @ 6684

Last change on this file since 6684 was 6648, checked in by Henrik Bettermann, 13 years ago

Reorganize vocabularies. The vocabs of the students package are the basis. In the application package only additional sources and vocabs should be defined.

  • Property svn:keywords set to Id
File size: 1.9 KB
Line 
1"""Vocabularies and sources for the student 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.students.lgas import LGAS
10
11def year_range():
12    curr_year = datetime.now().year
13    return range(curr_year - 2, curr_year + 5)
14
15def 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
20entry_session_vocab = SimpleWAeUPVocabulary(*entry_sessions())
21
22lgas_vocab = SimpleWAeUPVocabulary(
23    *sorted([(x[1],x[0]) for x in LGAS]))
24
25class 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
43class 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'
Note: See TracBrowser for help on using the repository browser.