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 - 10, 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 | # This will become a source with probation and |
---|
26 | # splill-over levels too |
---|
27 | study_levels = SimpleWAeUPVocabulary( |
---|
28 | ('Pre-Studies',0), |
---|
29 | ('100 (Year 1)',100), |
---|
30 | ('200 (Year 2)',200), |
---|
31 | ('300 (Year 3)',300), |
---|
32 | ('400 (Year 4)',400), |
---|
33 | ('500 (Year 5)',500), |
---|
34 | ('600 (Year 6)',600), |
---|
35 | ('700 (Year 7)',700), |
---|
36 | ('800 (Year 8)',800), |
---|
37 | ) |
---|
38 | |
---|
39 | verdicts = SimpleWAeUPVocabulary( |
---|
40 | ('Successful student','A'), |
---|
41 | ('Student with carryover courses','B'), |
---|
42 | ('Student on probation','C'), |
---|
43 | ('Student who were previously on probation','E'), |
---|
44 | ('Medical case','F'), |
---|
45 | ('Absent from examination','G'), |
---|
46 | ('Withheld results','H'), |
---|
47 | ('Expelled/rusticated/suspended student','I'), |
---|
48 | ('Temporary withdrawn from the university','J'), |
---|
49 | ('Unregistered student','K'), |
---|
50 | ('Referred student','L'), |
---|
51 | ('Reinstatement','M'), |
---|
52 | ('Student on transfer','N'), |
---|
53 | ('NCE-III repeater','O'), |
---|
54 | ('New 300 level student','X'), |
---|
55 | ('No previous verdict','Y'), |
---|
56 | ('Successful student (provisional)','Z'), |
---|
57 | ('First Class','A1'), |
---|
58 | ('Second Class Upper','A2'), |
---|
59 | ('Second Class Lower','A3'), |
---|
60 | ('Third Class','A4'), |
---|
61 | ('Pass','A5'), |
---|
62 | ('Distinction','A6'), |
---|
63 | ('Credit','A7'), |
---|
64 | ('Merit','A8'), |
---|
65 | ) |
---|
66 | |
---|
67 | |
---|
68 | class CertificateSource(BasicContextualSourceFactory): |
---|
69 | """A certificate source delivers all certificates provided |
---|
70 | in the portal. |
---|
71 | """ |
---|
72 | def getValues(self, context): |
---|
73 | catalog = getUtility(ICatalog, name='certificates_catalog') |
---|
74 | return sorted(list( |
---|
75 | catalog.searchResults( |
---|
76 | code=('', 'z*'))), |
---|
77 | key=lambda value: value.code) |
---|
78 | |
---|
79 | def getToken(self, context, value): |
---|
80 | return value.code |
---|
81 | |
---|
82 | def getTitle(self, context, value): |
---|
83 | return "%s - %s" % (value.code, value.title[:64]) |
---|
84 | |
---|
85 | |
---|
86 | class GenderSource(BasicSourceFactory): |
---|
87 | """A gender source delivers basically a mapping |
---|
88 | ``{'m': 'Male', 'f': 'Female'}`` |
---|
89 | |
---|
90 | Using a source, we make sure that the tokens (which are |
---|
91 | stored/expected for instance from CSV files) are something one |
---|
92 | can expect and not cryptic IntIDs. |
---|
93 | """ |
---|
94 | def getValues(self): |
---|
95 | return ['m', 'f'] |
---|
96 | |
---|
97 | def getToken(self, value): |
---|
98 | return value[0].lower() |
---|
99 | |
---|
100 | def getTitle(self, value): |
---|
101 | if value == 'm': |
---|
102 | return 'Male' |
---|
103 | if value == 'f': |
---|
104 | return 'Female' |
---|