source: WAeUP_SRP/trunk/skins/waeup_ois/getStudyLevelInfo.py @ 4350

Last change on this file since 4350 was 4303, checked in by Henrik Bettermann, 15 years ago

calculate and show position in course (see also previous revision)

File size: 6.4 KB
Line 
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"""
12return Info about the Studylevel
13try:
14    from Products.zdb import set_trace
15except:
16    def set_trace():
17        pass
18"""
19
20import DateTime
21
22info = context.waeup_tool.getAccessInfo(context)
23student_id = info['student_id']
24if student_id is None:
25    return None
26
27mtool = context.portal_membership
28pprops = context.portal_properties
29member = mtool.getAuthenticatedMember()
30member_id = str(member)
31
32course_results = context.course_results
33request = context.REQUEST
34response = request.RESPONSE
35import logging
36logger = logging.getLogger('Skins.getStudyLevelInfo')
37
38level_id  =  context.getId()
39level_doc = info['doc'] = context.getContent()
40
41info['is_so'] = is_so = info['is_sectionofficer']
42#info['is_student'] = is_student = context.isStudent()
43info['is_ca'] = is_ca = context.isCourseAdviser()
44#info['student'] = student = context.students_catalog(id=student_id)[0]
45info['student'] = student = context.students_catalog.getRecordByKey(student_id)
46info['review_state'] = review_state = student.review_state
47is_current_level = level_id == student.level
48school_fee_paid =  review_state == 'school_fee_paid'
49info['is_current_level'] = is_current_level
50info['has_verdict'] = has_verdict = level_doc.verdict
51
52info['submission_allowed']= school_fee_paid and is_current_level and not has_verdict
53info['validation_allowed']= review_state == 'courses_registered' and is_current_level
54info['rejection_allowed']= review_state in ('courses_registered', 'courses_validated',) and is_current_level
55info['validated'] = review_state == 'courses_validated' and is_current_level
56
57info['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
61info['verdict'] = context.portal_vocabularies.verdicts.get(level_doc.verdict).upper()
62info['session'] = context.portal_vocabularies.sessions.get(level_doc.session)
63info['level_str'] = context.portal_vocabularies.student_levels.get(level_id)
64
65info['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
79cert_id = student.course
80info['cert_id'] = cert_id
81total_credits,gpa,carry_overs,normal1,normal2,normal3 = course_results.getCourses(student_id,level_id)
82info['total_credits'] = total_credits
83
84#start customization
85
86
87
88max_credits = 58
89info['without_score'] = False
90info['without_cascore'] = False
91
92items = []
93subobjects = context.objectValues()
94for 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)
99info['items'] = items
100
101complete1 = 0
102score_calc_average_1 = 0
103for r in normal1:
104    if r['grade'] and r['atl']:
105        complete1 += 1
106        score_calc_average_1 += r['score_calc']
107if len(normal1) == complete1:
108    complete1 =  True
109else:
110    complete1 = False
111if len(normal1):
112    score_calc_average_1 /= len(normal1)   
113info['complete1'] = complete1     
114info['score_calc_average_1'] = '%.2f' % score_calc_average_1 
115
116complete2 = 0
117score_calc_average_2 = 0
118for r in normal2:
119    if r['grade'] and r['atl']:
120        score_calc_average_2 += r['score_calc']
121        complete2 += 1
122if len(normal2) == complete2:
123    complete2 =  True
124else:
125    complete2 = False
126if len(normal2):
127    score_calc_average_2 /= len(normal2)
128info['complete2'] = complete2
129info['score_calc_average_2'] = '%.2f' % score_calc_average_2 
130
131complete3 = 0
132score_calc_average_3 = 0
133for r in normal3:
134    if r['grade'] and r['atl']:
135        complete3 += 1
136        score_calc_average_3 += r['score_calc']
137if len(normal3) == complete3:
138    complete3 =  True
139else:
140    complete3 = False
141if len(normal3):
142    score_calc_average_3 /= len(normal3)   
143info['complete3'] = complete3
144info['score_calc_average_3'] =  '%.2f' % score_calc_average_3 
145
146session_id = level_doc.session
147yga1,yga2,yga3,counter1,counter2,counter3,yg1,yg2,yg3 = course_results.getYearGroupAverage(session_id,level_id)
148info['yga1'] = yga1
149info['yga2'] = yga2
150info['yga3'] = yga3
151info['counter1'] = counter1
152info['counter2'] = counter2
153info['counter3'] = counter3
154
155
156#yg1.sort(reverse=True)
157#if not len(yg1):
158#    pos1 = 'no result'
159#for pos1 in range(len(yg1)):
160#    if yg1[pos1] <= float(score_calc_average_1):
161#        break
162#info['pos1'] = '%d of %d' % (pos1+1,len(yg1))
163
164#end customization
165
166info['max_credits'] = max_credits
167info['credits_exceeded'] = total_credits > max_credits
168current_session = student.session
169
170info['gpa'] = gpa
171if gpa and total_credits:
172    info['gpa'] = "%4.2f" % (float(gpa)/int(total_credits))
173
174info['carry_overs'] = carry_overs
175normal1.sort(cmp=lambda x,y: cmp( x['title'],y['title']))
176normal2.sort(cmp=lambda x,y: cmp( x['title'],y['title']))
177normal3.sort(cmp=lambda x,y: cmp( x['title'],y['title']))
178
179info['normal1'] = normal1
180info['normal2'] = normal2
181info['normal3'] = normal3
182
183info['data_missing'] = not info['normal1'] and not info['normal2'] and not info['normal3']
184info['spillover'] = student.level > student.end_level
185
186students_object = context.portal_url.getPortalObject().campus.students
187student = getattr(students_object, student_id)
188info['app'] = student.application
189info['app_doc'] = student.application.getContent()
190
191if pprops.session == info['session']:
192    info['date1'] = DateTime.DateTime(pprops.date1).strftime('%d/%m/%Y')
193    info['date2'] = DateTime.DateTime(pprops.date2).strftime('%d/%m/%Y')
194    info['date3'] = DateTime.DateTime(pprops.date3).strftime('%d/%m/%Y')
195else:
196    info['date1'] = 'n/a'
197    info['date2'] = 'n/a'
198    info['date3'] = 'n/a'
199
200
201return info
Note: See TracBrowser for help on using the repository browser.