1 | # $Id: display_session_results.py 1166 2006-12-31 18:11:47Z henrik $ |
---|
2 | """ |
---|
3 | process the Application Form |
---|
4 | return html renderer + psm |
---|
5 | """ |
---|
6 | import DateTime |
---|
7 | current = DateTime.DateTime() |
---|
8 | pr = context.portal_registration |
---|
9 | |
---|
10 | returning = context.returning_import |
---|
11 | results = context.results_import |
---|
12 | scatalog = context.students_catalog |
---|
13 | |
---|
14 | mtool = context.portal_membership |
---|
15 | member = mtool.getAuthenticatedMember() |
---|
16 | member_id = str(member) |
---|
17 | |
---|
18 | if mtool.isAnonymousUser(): |
---|
19 | return None |
---|
20 | info = {} |
---|
21 | #from Products.zdb import set_trace |
---|
22 | #set_trace() |
---|
23 | requested_id = context.getStudentId() |
---|
24 | if requested_id and not context.isStaff() and member_id != requested_id: |
---|
25 | import logging |
---|
26 | logger = logging.getLogger('Student.SessionResults.Info') |
---|
27 | logger.info('"%s", "tried to access", "%s"' % (member_id,requested_id)) |
---|
28 | return None |
---|
29 | elif context.isStaff(): |
---|
30 | student_id = requested_id |
---|
31 | else: |
---|
32 | student_id = member_id |
---|
33 | |
---|
34 | students_object = context.portal_url.getPortalObject().campus.students |
---|
35 | ##student = getattr(students_object, student_id) |
---|
36 | ##clear = getattr(student,'clearance',None) |
---|
37 | ##if clear: |
---|
38 | ## value = clear.getContent().matric_no |
---|
39 | ##else: |
---|
40 | ## return None |
---|
41 | |
---|
42 | res = scatalog(id = student_id) |
---|
43 | matric_no = res[0].matric_no |
---|
44 | student_from_cat = res[0] |
---|
45 | |
---|
46 | res = returning(matric_no = matric_no) |
---|
47 | student_from_returning = res[0] |
---|
48 | res = results(matric_no = matric_no) |
---|
49 | results = res |
---|
50 | |
---|
51 | |
---|
52 | sem1 = [] |
---|
53 | sem2 = [] |
---|
54 | with_courses_cat = hasattr(context,'courses_catalog') |
---|
55 | fields = context.results_import.schema() |
---|
56 | gpa = 0 |
---|
57 | course_count = 0 |
---|
58 | verdict = None |
---|
59 | session = None |
---|
60 | for r in results: |
---|
61 | if verdict is None: |
---|
62 | verdict = r.Verdict |
---|
63 | session = r.Session |
---|
64 | result = {} |
---|
65 | for field in fields: |
---|
66 | result[field] = getattr(r,field) |
---|
67 | if with_courses_cat: |
---|
68 | res = context.courses_catalog(code = r.CosCode) |
---|
69 | if with_courses_cat and res: |
---|
70 | result['title'] = res[0].title |
---|
71 | result['credits'] = res[0].credits |
---|
72 | try: |
---|
73 | weight = int(result['WEIGHT']) |
---|
74 | credits = int(res[0].credits) |
---|
75 | gpa_course = int(res[0].credits) * weight |
---|
76 | gpa += gpa_course |
---|
77 | course_count += credits |
---|
78 | result['gpa'] = 'ok' |
---|
79 | except: |
---|
80 | result['gpa'] = 'na' |
---|
81 | else: |
---|
82 | result['title'] = "na" |
---|
83 | result['credits'] = "na" |
---|
84 | result['gpa'] = 'na' |
---|
85 | if r.Semester == '2': |
---|
86 | sem2.append(result) |
---|
87 | else: |
---|
88 | sem1.append(result) |
---|
89 | if course_count: |
---|
90 | gpa = float(gpa) / course_count |
---|
91 | gpa = "%4.2f" % gpa |
---|
92 | |
---|
93 | # not available at the beginning |
---|
94 | #if student_from_cat.sex: |
---|
95 | # info['sex'] = 'F' |
---|
96 | #else: |
---|
97 | # info['sex'] = 'M' |
---|
98 | #info['level'] = int(student_from_cat.level)-100 |
---|
99 | |
---|
100 | info['verdict'] = verdict |
---|
101 | info['session'] = session |
---|
102 | info['gpa'] = gpa |
---|
103 | info['results'] = (sem1, sem2) |
---|
104 | info['student_from_returning'] = student_from_returning |
---|
105 | info['student'] = student_from_cat |
---|
106 | info['s_id'] = student_id |
---|
107 | return info |
---|
108 | |
---|