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