[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 |
---|
[1317] | 21 | scatalog = context.students_catalog |
---|
[1174] | 22 | |
---|
| 23 | mtool = context.portal_membership |
---|
| 24 | member = mtool.getAuthenticatedMember() |
---|
| 25 | member_id = str(member) |
---|
| 26 | |
---|
| 27 | if mtool.isAnonymousUser(): |
---|
| 28 | return None |
---|
| 29 | info = {} |
---|
| 30 | #from Products.zdb import set_trace |
---|
| 31 | #set_trace() |
---|
| 32 | requested_id = context.getStudentId() |
---|
| 33 | if requested_id and not context.isStaff() and member_id != requested_id: |
---|
[1258] | 34 | import logging |
---|
| 35 | logger = logging.getLogger('Student.SessionResults.Info') |
---|
[1174] | 36 | logger.info('"%s", "tried to access", "%s"' % (member_id,requested_id)) |
---|
| 37 | return None |
---|
| 38 | elif context.isStaff(): |
---|
| 39 | student_id = requested_id |
---|
| 40 | else: |
---|
| 41 | student_id = member_id |
---|
| 42 | |
---|
| 43 | students_object = context.portal_url.getPortalObject().campus.students |
---|
[1315] | 44 | ##student = getattr(students_object, student_id) |
---|
| 45 | ##clear = getattr(student,'clearance',None) |
---|
| 46 | ##if clear: |
---|
| 47 | ## value = clear.getContent().matric_no |
---|
| 48 | ##else: |
---|
| 49 | ## return None |
---|
[1174] | 50 | |
---|
[1317] | 51 | res = scatalog(id = student_id) |
---|
| 52 | matric_no = res[0].matric_no |
---|
| 53 | |
---|
| 54 | res = returning(matric_no = matric_no) |
---|
[1174] | 55 | student = res[0] |
---|
[1317] | 56 | res = results(matric_no = matric_no) |
---|
[1174] | 57 | results = res |
---|
| 58 | |
---|
| 59 | |
---|
| 60 | sem1 = [] |
---|
| 61 | sem2 = [] |
---|
| 62 | with_courses_cat = hasattr(context,'courses_catalog') |
---|
| 63 | fields = context.results_import.schema() |
---|
[1179] | 64 | gpa = 0 |
---|
| 65 | course_count = 0 |
---|
[1183] | 66 | verdict = None |
---|
| 67 | session = None |
---|
[1174] | 68 | for r in results: |
---|
[1183] | 69 | if verdict is None: |
---|
| 70 | verdict = r.Verdict |
---|
| 71 | session = r.Session |
---|
[1174] | 72 | result = {} |
---|
| 73 | for field in fields: |
---|
| 74 | result[field] = getattr(r,field) |
---|
| 75 | if with_courses_cat: |
---|
| 76 | res = context.courses_catalog(code = r.CosCode) |
---|
| 77 | if with_courses_cat and res: |
---|
| 78 | result['title'] = res[0].title |
---|
[1179] | 79 | result['credits'] = res[0].credits |
---|
| 80 | try: |
---|
| 81 | weight = int(result['WEIGHT']) |
---|
| 82 | credits = int(res[0].credits) |
---|
| 83 | gpa_course = int(res[0].credits) * weight |
---|
| 84 | gpa += gpa_course |
---|
| 85 | course_count += credits |
---|
| 86 | result['gpa'] = 'ok' |
---|
| 87 | except: |
---|
| 88 | result['gpa'] = 'na' |
---|
[1174] | 89 | else: |
---|
[1179] | 90 | result['title'] = "na" |
---|
| 91 | result['credits'] = "na" |
---|
| 92 | result['gpa'] = 'na' |
---|
[1174] | 93 | if r.Semester == '2': |
---|
| 94 | sem2.append(result) |
---|
| 95 | else: |
---|
| 96 | sem1.append(result) |
---|
[1179] | 97 | if course_count: |
---|
| 98 | gpa = float(gpa) / course_count |
---|
| 99 | gpa = "%4.2f" % gpa |
---|
[1183] | 100 | info['verdict'] = verdict |
---|
| 101 | info['session'] = session |
---|
[1179] | 102 | info['gpa'] = gpa |
---|
[1174] | 103 | info['results'] = (sem1, sem2) |
---|
| 104 | info['student'] = student |
---|
| 105 | info['s_id'] = student_id |
---|
| 106 | return info |
---|
[1179] | 107 | |
---|