1 | ## Script (Python) "getStudyLevelInfo"
|
---|
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: getStudyLevelInfo.py 2760 2007-11-26 07:39:15Z henrik $
|
---|
11 | """
|
---|
12 | return Info about the Studylevel
|
---|
13 | try:
|
---|
14 | from Products.zdb import set_trace
|
---|
15 | except:
|
---|
16 | def set_trace():
|
---|
17 | pass
|
---|
18 | """
|
---|
19 |
|
---|
20 | import DateTime
|
---|
21 |
|
---|
22 | info = context.waeup_tool.getAccessInfo(context)
|
---|
23 | student_id = info['student_id']
|
---|
24 | if student_id is None:
|
---|
25 | return None
|
---|
26 |
|
---|
27 | mtool = context.portal_membership
|
---|
28 | pprops = context.portal_properties
|
---|
29 | member = mtool.getAuthenticatedMember()
|
---|
30 | member_id = str(member)
|
---|
31 |
|
---|
32 | course_results = context.course_results
|
---|
33 | request = context.REQUEST
|
---|
34 | response = request.RESPONSE
|
---|
35 | import logging
|
---|
36 | logger = logging.getLogger('Skins.getStudyLevelInfo')
|
---|
37 |
|
---|
38 | level_id = context.getId()
|
---|
39 | level_doc = info['doc'] = context.getContent()
|
---|
40 |
|
---|
41 | info['is_so'] = is_so = info['is_sectionofficer']
|
---|
42 | #info['is_student'] = is_student = context.isStudent()
|
---|
43 | info['is_ca'] = is_ca = context.isCourseAdviser()
|
---|
44 | #info['student'] = student = context.students_catalog(id=student_id)[0]
|
---|
45 | info['student'] = student = context.students_catalog.getRecordByKey(student_id)
|
---|
46 | info['review_state'] = review_state = student.review_state
|
---|
47 | is_current_level = level_id == student.level
|
---|
48 | school_fee_paid = review_state == 'school_fee_paid'
|
---|
49 | info['is_current_level'] = is_current_level
|
---|
50 | info['has_verdict'] = has_verdict = level_doc.verdict
|
---|
51 |
|
---|
52 | info['submission_allowed']= school_fee_paid and is_current_level and not has_verdict
|
---|
53 | info['validation_allowed']= review_state == 'courses_registered' and is_current_level
|
---|
54 | info['rejection_allowed']= review_state in ('courses_registered', 'courses_validated',) and is_current_level
|
---|
55 | info['validated'] = review_state == 'courses_validated' and is_current_level
|
---|
56 |
|
---|
57 | info['show_check_boxes'] = (is_ca and school_fee_paid and is_current_level and not has_verdict) or\
|
---|
58 | (info['is_student'] and school_fee_paid and is_current_level and not has_verdict) or\
|
---|
59 | (is_so and is_current_level and not has_verdict)
|
---|
60 |
|
---|
61 | info['verdict'] = context.portal_vocabularies.verdicts.get(level_doc.verdict).upper()
|
---|
62 | info['session'] = context.portal_vocabularies.sessions.get(level_doc.session)
|
---|
63 | info['level_str'] = context.portal_vocabularies.student_levels.get(level_id)
|
---|
64 |
|
---|
65 | info['choosen_ids'] = request.get('ids',[])
|
---|
66 |
|
---|
67 | #info['status_info'] = ""
|
---|
68 | #if is_student:
|
---|
69 | # if review_state == 'courses_registered':
|
---|
70 | # info['status_info'] = "Request for course validation pending"
|
---|
71 | # elif review_state == 'courses_validated':
|
---|
72 | # info['status_info'] = "Courses validated"
|
---|
73 | #elif is_ca:
|
---|
74 | # if review_state == 'courses_registered':
|
---|
75 | # info['status_info'] = "Please validate these courses"
|
---|
76 | # elif review_state == 'courses_validated':
|
---|
77 | # info['status_info'] = "Courses validated"
|
---|
78 |
|
---|
79 | cert_id = student.course
|
---|
80 | info['cert_id'] = cert_id
|
---|
81 | total_credits,gpa,carry_overs,normal1,normal2,normal3 = course_results.getCourses(student_id,level_id)
|
---|
82 | info['total_credits'] = total_credits
|
---|
83 |
|
---|
84 | #start customization
|
---|
85 |
|
---|
86 |
|
---|
87 |
|
---|
88 | max_credits = 100
|
---|
89 | info['without_score'] = False
|
---|
90 | info['without_cascore'] = False
|
---|
91 |
|
---|
92 | items = []
|
---|
93 | subobjects = context.objectValues()
|
---|
94 | for subobject in subobjects:
|
---|
95 | row = {}
|
---|
96 | row['id'] = subobject.getId()
|
---|
97 | row['title'] = '%s' % context.portal_vocabularies.terms.get(subobject.getId())
|
---|
98 | items.append(row)
|
---|
99 | info['items'] = items
|
---|
100 |
|
---|
101 | complete1 = 0
|
---|
102 | score_calc_average_1 = 0
|
---|
103 | for r in normal1:
|
---|
104 | if r['grade'] and r['atl']:
|
---|
105 | complete1 += 1
|
---|
106 | score_calc_average_1 += r['score_calc']
|
---|
107 | if len(normal1) == complete1:
|
---|
108 | complete1 = True
|
---|
109 | else:
|
---|
110 | complete1 = False
|
---|
111 | if len(normal1):
|
---|
112 | score_calc_average_1 /= len(normal1)
|
---|
113 | info['complete1'] = complete1
|
---|
114 | info['score_calc_average_1'] = '%.2f' % score_calc_average_1
|
---|
115 |
|
---|
116 | complete2 = 0
|
---|
117 | score_calc_average_2 = 0
|
---|
118 | for r in normal2:
|
---|
119 | if r['grade'] and r['atl']:
|
---|
120 | score_calc_average_2 += r['score_calc']
|
---|
121 | complete2 += 1
|
---|
122 | if len(normal2) == complete2:
|
---|
123 | complete2 = True
|
---|
124 | else:
|
---|
125 | complete2 = False
|
---|
126 | if len(normal2):
|
---|
127 | score_calc_average_2 /= len(normal2)
|
---|
128 | info['complete2'] = complete2
|
---|
129 | info['score_calc_average_2'] = '%.2f' % score_calc_average_2
|
---|
130 |
|
---|
131 | complete3 = 0
|
---|
132 | score_calc_average_3 = 0
|
---|
133 | for r in normal3:
|
---|
134 | if r['grade'] and r['atl']:
|
---|
135 | complete3 += 1
|
---|
136 | score_calc_average_3 += r['score_calc']
|
---|
137 | if len(normal3) == complete3:
|
---|
138 | complete3 = True
|
---|
139 | else:
|
---|
140 | complete3 = False
|
---|
141 | if len(normal3):
|
---|
142 | score_calc_average_3 /= len(normal3)
|
---|
143 | info['complete3'] = complete3
|
---|
144 | info['score_calc_average_3'] = '%.2f' % score_calc_average_3
|
---|
145 |
|
---|
146 | terms_completed = bool(score_calc_average_1) + bool(score_calc_average_2) + bool(score_calc_average_3)
|
---|
147 |
|
---|
148 | if terms_completed:
|
---|
149 | score_calc_average_cum = (score_calc_average_1 + score_calc_average_2 + score_calc_average_3)/terms_completed
|
---|
150 | else:
|
---|
151 | score_calc_average_cum = 0
|
---|
152 |
|
---|
153 | info['score_calc_average_cum'] = '%.2f' % score_calc_average_cum
|
---|
154 |
|
---|
155 | session_id = level_doc.session
|
---|
156 | yga1,yga2,yga3,counter1,counter2,counter3,yg1,yg2,yg3 = course_results.getYearGroupAverage(session_id,level_id)
|
---|
157 | info['yga1'] = yga1
|
---|
158 | info['yga2'] = yga2
|
---|
159 | info['yga3'] = yga3
|
---|
160 | info['counter1'] = counter1
|
---|
161 | info['counter2'] = counter2
|
---|
162 | info['counter3'] = counter3
|
---|
163 |
|
---|
164 |
|
---|
165 | #yg1.sort(reverse=True)
|
---|
166 | #if not len(yg1):
|
---|
167 | # pos1 = 'no result'
|
---|
168 | #for pos1 in range(len(yg1)):
|
---|
169 | # if yg1[pos1] <= float(score_calc_average_1):
|
---|
170 | # break
|
---|
171 | #info['pos1'] = '%d of %d' % (pos1+1,len(yg1))
|
---|
172 |
|
---|
173 | #end customization
|
---|
174 |
|
---|
175 | info['max_credits'] = max_credits
|
---|
176 | info['credits_exceeded'] = total_credits > max_credits
|
---|
177 | current_session = student.session
|
---|
178 |
|
---|
179 | info['gpa'] = gpa
|
---|
180 | if gpa and total_credits:
|
---|
181 | info['gpa'] = "%4.2f" % (float(gpa)/int(total_credits))
|
---|
182 |
|
---|
183 | info['carry_overs'] = carry_overs
|
---|
184 | normal1.sort(cmp=lambda x,y: cmp( x['title'],y['title']))
|
---|
185 | normal2.sort(cmp=lambda x,y: cmp( x['title'],y['title']))
|
---|
186 | normal3.sort(cmp=lambda x,y: cmp( x['title'],y['title']))
|
---|
187 |
|
---|
188 | info['normal1'] = normal1
|
---|
189 | info['normal2'] = normal2
|
---|
190 | info['normal3'] = normal3
|
---|
191 |
|
---|
192 | info['data_missing'] = not info['normal1'] and not info['normal2'] and not info['normal3']
|
---|
193 | info['spillover'] = student.level > student.end_level
|
---|
194 |
|
---|
195 | students_object = context.portal_url.getPortalObject().campus.students
|
---|
196 | student = getattr(students_object, student_id)
|
---|
197 | info['app'] = student.application
|
---|
198 | info['app_doc'] = student.application.getContent()
|
---|
199 |
|
---|
200 | if pprops.session == info['session']:
|
---|
201 | info['date1'] = DateTime.DateTime(pprops.date1).strftime('%d/%m/%Y')
|
---|
202 | info['date2'] = DateTime.DateTime(pprops.date2).strftime('%d/%m/%Y')
|
---|
203 | info['date3'] = DateTime.DateTime(pprops.date3).strftime('%d/%m/%Y')
|
---|
204 | else:
|
---|
205 | info['date1'] = 'n/a'
|
---|
206 | info['date2'] = 'n/a'
|
---|
207 | info['date3'] = 'n/a'
|
---|
208 |
|
---|
209 | info['over_pos_term1'] = getattr(level_doc, 'over_pos_term1','n/a')
|
---|
210 | info['no_stud_term1'] = getattr(level_doc, 'no_stud_term1','n/a')
|
---|
211 | info['over_pos_term2'] = getattr(level_doc, 'over_pos_term2','n/a')
|
---|
212 | info['no_stud_term2'] = getattr(level_doc, 'no_stud_term2','n/a')
|
---|
213 | info['over_pos_term3'] = getattr(level_doc, 'over_pos_term3','n/a')
|
---|
214 | info['no_stud_term3'] = getattr(level_doc, 'no_stud_term3','n/a')
|
---|
215 | info['over_pos_cum'] = getattr(level_doc, 'over_pos_cum','n/a')
|
---|
216 | info['no_stud_cum'] = getattr(level_doc, 'no_stud_cum','n/a')
|
---|
217 |
|
---|
218 | return info
|
---|