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

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

Replace the static study_levels vocab by a StudyLevelSource?.

The StudyLevelSource? is based on and extends the
course_levels vocabulary defined in the university package.
Repeating study levels are denoted by increments of 10, the
first spillover level by the certificate's end level plus 100
and the second spillover level by the end level plus 110.

  • Property svn:keywords set to Id
File size: 4.3 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
10from waeup.sirp.university.vocabularies import course_levels
11
12def year_range():
13    curr_year = datetime.now().year
14    return range(curr_year - 2, curr_year + 5)
15
16def entry_sessions():
17    curr_year = datetime.now().year
18    year_range = range(curr_year - 10, curr_year + 2)
19    return [('%s/%s' % (year,year+1), '%s' % year) for year in year_range]
20
21entry_session_vocab = SimpleWAeUPVocabulary(*entry_sessions())
22
23lgas_vocab = SimpleWAeUPVocabulary(
24    *sorted([(x[1],x[0]) for x in LGAS]))
25
26def study_levels(studycourse):
27    try:
28        start_level = int(studycourse.certificate.start_level)
29        end_level = int(studycourse.certificate.end_level)
30        levels = [level for level in range(start_level,end_level+200,10)
31                   if level % 100 < 30 and level < end_level + 120]
32        return levels
33    except AttributeError:
34        return []
35   
36class StudyLevelSource(BasicContextualSourceFactory):
37    """The StudyLevelSource is based on and extends the
38    course_levels vocabulary defined in the university package.
39    Repeating study levels are denoted by increments of 10, the
40    first spillover level by the certificate's end level plus 100
41    and the second spillover level by the end level plus 110.
42    """
43    def getValues(self, context):
44        return study_levels(context)
45
46    def getToken(self, context, value):
47        return str(value)
48
49    def getTitle(self, context, value):
50        end_level = int(context.certificate.end_level)
51        level,repeat = divmod(value, 100)
52        level = level * 100
53        repeat = repeat//10
54        title = course_levels.by_value[level].title
55        if level > end_level and repeat:
56            title = course_levels.by_value[level-100].title
57            title = "%s 2nd spillover" % title
58        elif level > end_level:
59            title = course_levels.by_value[level-100].title
60            title = "%s spillover" % title
61        elif repeat:
62            title = "%s on %d. probation" % (title, repeat)
63        return title
64
65verdicts = SimpleWAeUPVocabulary(
66    ('Successful student','A'),
67    ('Student with carryover courses','B'),
68    ('Student on probation','C'),
69    ('Student who were previously on probation','E'),
70    ('Medical case','F'),
71    ('Absent from examination','G'),
72    ('Withheld results','H'),
73    ('Expelled/rusticated/suspended student','I'),
74    ('Temporary withdrawn from the university','J'),
75    ('Unregistered student','K'),
76    ('Referred student','L'),
77    ('Reinstatement','M'),
78    ('Student on transfer','N'),
79    ('NCE-III repeater','O'),
80    ('New 300 level student','X'),
81    ('No previous verdict','Y'),
82    ('Successful student (provisional)','Z'),
83    ('First Class','A1'),
84    ('Second Class Upper','A2'),
85    ('Second Class Lower','A3'),
86    ('Third Class','A4'),
87    ('Pass','A5'),
88    ('Distinction','A6'),
89    ('Credit','A7'),
90    ('Merit','A8'),
91    )
92
93
94class CertificateSource(BasicContextualSourceFactory):
95    """A certificate source delivers all certificates provided
96    in the portal.
97    """
98    def getValues(self, context):
99        catalog = getUtility(ICatalog, name='certificates_catalog')
100        return sorted(list(
101                catalog.searchResults(
102                    code=('', 'z*'))),
103                    key=lambda value: value.code)
104
105    def getToken(self, context, value):
106        return value.code
107
108    def getTitle(self, context, value):
109        return "%s - %s" % (value.code, value.title[:64])
110
111
112class GenderSource(BasicSourceFactory):
113    """A gender source delivers basically a mapping
114       ``{'m': 'Male', 'f': 'Female'}``
115
116       Using a source, we make sure that the tokens (which are
117       stored/expected for instance from CSV files) are something one
118       can expect and not cryptic IntIDs.
119    """
120    def getValues(self):
121        return ['m', 'f']
122
123    def getToken(self, value):
124        return value[0].lower()
125
126    def getTitle(self, value):
127        if value == 'm':
128            return 'Male'
129        if value == 'f':
130            return 'Female'
Note: See TracBrowser for help on using the repository browser.