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