1 | ##parameters=key=None |
---|
2 | # $Id: getStudentLevelsVoc.py 6858 2011-10-04 06:05:39Z henrik $ |
---|
3 | """ |
---|
4 | Return the levels as an vocabulary |
---|
5 | """ |
---|
6 | student_id = context.getStudentId() |
---|
7 | end_level = 800 |
---|
8 | if student_id: |
---|
9 | end_level = context.students_catalog(id = student_id)[0].end_level |
---|
10 | if end_level and end_level.isdigit(): |
---|
11 | end_level = int(end_level) |
---|
12 | else: |
---|
13 | end_level = 700 |
---|
14 | |
---|
15 | if key is None: |
---|
16 | levels = [l for l in range(0,end_level+200,10) |
---|
17 | if l % 100 < 30 and l < end_level + 120] |
---|
18 | voc = [('','')] |
---|
19 | for l in levels: |
---|
20 | level_nr,repeat = divmod(l, 100) |
---|
21 | if level_nr > end_level/100 and repeat: |
---|
22 | voc += ("%s" % l,"%s (2nd spillover)" % context.portal_vocabularies.levels.get("%d00" % (level_nr - 1))), |
---|
23 | elif level_nr > end_level/100: |
---|
24 | voc += ("%s" % l,"%s (spillover)" % context.portal_vocabularies.levels.get("%d00" % (level_nr - 1))), |
---|
25 | elif repeat > 0: |
---|
26 | voc += ("%s" % l,"%s (on %d. probation)" % |
---|
27 | (context.portal_vocabularies.levels.get("%d00" % (level_nr)), |
---|
28 | (repeat // 10))), |
---|
29 | else: |
---|
30 | voc += ("%03d" % l,"%s" % |
---|
31 | (context.portal_vocabularies.levels.get("%d00" % (level_nr)))), |
---|
32 | return voc |
---|
33 | |
---|
34 | if key and key.isdigit(): |
---|
35 | ikey = int(key) |
---|
36 | else: |
---|
37 | raise KeyError |
---|
38 | |
---|
39 | # FUTMinna only |
---|
40 | if ikey == 501: |
---|
41 | return "100 Level Carryover Courses" |
---|
42 | |
---|
43 | level_nr,repeat = divmod(ikey, 100) |
---|
44 | l = [] |
---|
45 | |
---|
46 | level = context.portal_vocabularies.levels.get("%d00" % level_nr,None) |
---|
47 | if level is None: |
---|
48 | raise KeyError |
---|
49 | |
---|
50 | if level_nr > end_level/100 and repeat: |
---|
51 | return "%s 2nd Spillover" % context.portal_vocabularies.levels.get("%d00" % (level_nr - 1)) |
---|
52 | elif level_nr > end_level/100: |
---|
53 | return "%s Spillover" % context.portal_vocabularies.levels.get("%d00" % (level_nr - 1)) |
---|
54 | |
---|
55 | if repeat > 0: |
---|
56 | level += " on %d. Probation" % (repeat // 10) |
---|
57 | |
---|
58 | return level |
---|
59 | |
---|