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 | from waeup.sirp.university.vocabularies import course_levels |
---|
11 | |
---|
12 | def year_range(): |
---|
13 | curr_year = datetime.now().year |
---|
14 | return range(curr_year - 2, curr_year + 5) |
---|
15 | |
---|
16 | def 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 | |
---|
21 | entry_session_vocab = SimpleWAeUPVocabulary(*entry_sessions()) |
---|
22 | |
---|
23 | lgas_vocab = SimpleWAeUPVocabulary( |
---|
24 | *sorted([(x[1],x[0]) for x in LGAS])) |
---|
25 | |
---|
26 | def 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 | |
---|
36 | class 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 | |
---|
65 | verdicts = 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 | |
---|
94 | class 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 | |
---|
112 | class 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' |
---|