1 | ## Script (Python) "getStudyCourseInfo" |
---|
2 | ##bind container=container |
---|
3 | ##bind context=context |
---|
4 | ##bind namespace= |
---|
5 | ##bind script=script |
---|
6 | ##bind subpath=traverse_subpath |
---|
7 | ##parameters=student=None |
---|
8 | ##title= |
---|
9 | ## |
---|
10 | # $Id: getStudyCourseInfo.py 2855 2007-12-04 15:47:06Z joachim $ |
---|
11 | """ |
---|
12 | return Info about the Students StudyCourse |
---|
13 | """ |
---|
14 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
15 | |
---|
16 | mtool = context.portal_membership |
---|
17 | if mtool.isAnonymousUser(): |
---|
18 | return None |
---|
19 | |
---|
20 | try: |
---|
21 | from Products.zdb import set_trace |
---|
22 | except: |
---|
23 | def set_trace(): |
---|
24 | pass |
---|
25 | |
---|
26 | request = context.REQUEST |
---|
27 | |
---|
28 | wftool = context.portal_workflow |
---|
29 | path_info = request.get('PATH_INFO').split('/') |
---|
30 | |
---|
31 | info = {} |
---|
32 | info['is_so'] = context.isSectionOfficer() |
---|
33 | info['action'] = "%s" % context.absolute_url() |
---|
34 | info['choosen_ids'] = request.get('ids',[]) |
---|
35 | course = info['doc'] = context.getContent() |
---|
36 | student_id = context.getStudentId() |
---|
37 | res = context.students_catalog(id = student_id) |
---|
38 | if not res: |
---|
39 | return None |
---|
40 | sbrain = res[0] |
---|
41 | info['student'] = sbrain |
---|
42 | cert_id = sbrain.course |
---|
43 | res = context.portal_catalog_real.evalAdvancedQuery(Eq('id', cert_id) & |
---|
44 | Eq('portal_type', "Certificate")) |
---|
45 | ci = {} |
---|
46 | if res: |
---|
47 | info['cert_id'] = cert_id |
---|
48 | brain = res[0] |
---|
49 | ci['study_course'] = brain.getId |
---|
50 | ci['title'] = brain.Title |
---|
51 | pl = brain.getPath().split('/') |
---|
52 | ci['faculty'] = pl[-4] |
---|
53 | ci['department'] = pl[-3] |
---|
54 | info['course_doc'] = ci |
---|
55 | else: |
---|
56 | info['cert_id'] = 'N/A' |
---|
57 | ci['study_course'] = 'N/A' |
---|
58 | ci['title'] = 'N/A' |
---|
59 | ci['faculty'] = 'N/A' |
---|
60 | ci['department'] = 'N/A' |
---|
61 | info['course_doc'] = ci |
---|
62 | |
---|
63 | items = [] |
---|
64 | |
---|
65 | if hasattr(course,'current_verdict'): |
---|
66 | try: |
---|
67 | info['verdict'] = context.portal_vocabularies.verdicts.get(course.current_verdict).upper() |
---|
68 | except: |
---|
69 | info['verdict'] = course.current_verdict |
---|
70 | else: |
---|
71 | info['verdict'] = '' |
---|
72 | |
---|
73 | if hasattr(course,'previous_verdict'): |
---|
74 | try: |
---|
75 | previous_verdict = course.previous_verdict |
---|
76 | info['previous_verdict'] = context.portal_vocabularies.verdicts.get(course.previous_verdict).upper() |
---|
77 | except: |
---|
78 | info['previous_verdict'] = course.previous_verdict |
---|
79 | else: |
---|
80 | info['previous_verdict'] = '' |
---|
81 | previous_verdict = '' |
---|
82 | |
---|
83 | |
---|
84 | current_level = sbrain.level |
---|
85 | levels = context.objectIds() |
---|
86 | review_state = wftool.getInfoFor(context,'review_state',None) |
---|
87 | student_review_state = sbrain.review_state |
---|
88 | #if review_state != 'content_addable' and student_review_state == 'school_fee_paid': #and context.isStudent(): |
---|
89 | # wftool.doActionFor(context,'close_for_edit') |
---|
90 | |
---|
91 | has_paid = student_review_state == 'school_fee_paid' |
---|
92 | |
---|
93 | may_register = has_paid and\ |
---|
94 | current_level not in levels and\ |
---|
95 | (previous_verdict in ('A','B','C','F','J','L','M') or\ |
---|
96 | current_level == '100' or\ |
---|
97 | (sbrain.mode.startswith('de') and current_level == '200')) |
---|
98 | |
---|
99 | missing_data = has_paid and\ |
---|
100 | current_level not in levels and\ |
---|
101 | not (previous_verdict or sbrain.level) and\ |
---|
102 | not (current_level == '100' or\ |
---|
103 | (sbrain.mode.startswith('de') and current_level == '200')) |
---|
104 | |
---|
105 | info['missing_data'] = missing_data |
---|
106 | levels.sort() |
---|
107 | info['create_level'] = None |
---|
108 | student_levels_voc = context.portal_vocabularies.student_levels |
---|
109 | if may_register: |
---|
110 | info['create_level'] = current_level |
---|
111 | info['create_level_str'] = student_levels_voc.get(current_level) |
---|
112 | for l in levels: |
---|
113 | row = {} |
---|
114 | row['id'] = l |
---|
115 | #row['title'] = "Level %s" % l |
---|
116 | row['title'] = student_levels_voc.get(l) |
---|
117 | row['url'] = "%s/%s" % (context.absolute_url(),l) |
---|
118 | items.append(row) |
---|
119 | |
---|
120 | info['items'] = items |
---|
121 | |
---|
122 | |
---|
123 | |
---|
124 | return info |
---|
125 | |
---|