[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 |
---|
[1411] | 53 | student_from_cat = res[0] |
---|
[1317] | 54 | |
---|
| 55 | res = returning(matric_no = matric_no) |
---|
[1411] | 56 | student_from_returning = res[0] |
---|
[1317] | 57 | res = results(matric_no = matric_no) |
---|
[1174] | 58 | results = res |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | sem1 = [] |
---|
| 62 | sem2 = [] |
---|
| 63 | with_courses_cat = hasattr(context,'courses_catalog') |
---|
| 64 | fields = context.results_import.schema() |
---|
[1179] | 65 | gpa = 0 |
---|
| 66 | course_count = 0 |
---|
[1183] | 67 | verdict = None |
---|
| 68 | session = None |
---|
[1174] | 69 | for r in results: |
---|
[1183] | 70 | if verdict is None: |
---|
| 71 | verdict = r.Verdict |
---|
| 72 | session = r.Session |
---|
[1174] | 73 | result = {} |
---|
| 74 | for field in fields: |
---|
| 75 | result[field] = getattr(r,field) |
---|
| 76 | if with_courses_cat: |
---|
| 77 | res = context.courses_catalog(code = r.CosCode) |
---|
| 78 | if with_courses_cat and res: |
---|
| 79 | result['title'] = res[0].title |
---|
[1179] | 80 | result['credits'] = res[0].credits |
---|
| 81 | try: |
---|
| 82 | weight = int(result['WEIGHT']) |
---|
| 83 | credits = int(res[0].credits) |
---|
| 84 | gpa_course = int(res[0].credits) * weight |
---|
| 85 | gpa += gpa_course |
---|
| 86 | course_count += credits |
---|
| 87 | result['gpa'] = 'ok' |
---|
| 88 | except: |
---|
| 89 | result['gpa'] = 'na' |
---|
[1174] | 90 | else: |
---|
[1179] | 91 | result['title'] = "na" |
---|
| 92 | result['credits'] = "na" |
---|
| 93 | result['gpa'] = 'na' |
---|
[1174] | 94 | if r.Semester == '2': |
---|
| 95 | sem2.append(result) |
---|
| 96 | else: |
---|
| 97 | sem1.append(result) |
---|
[1179] | 98 | if course_count: |
---|
| 99 | gpa = float(gpa) / course_count |
---|
| 100 | gpa = "%4.2f" % gpa |
---|
[1411] | 101 | if student_from_cat.sex: |
---|
| 102 | info['sex'] = 'F' |
---|
| 103 | else: |
---|
| 104 | info['sex'] = 'M' |
---|
| 105 | info['level'] = int(student_from_cat.level)-100 |
---|
[1183] | 106 | info['verdict'] = verdict |
---|
| 107 | info['session'] = session |
---|
[1179] | 108 | info['gpa'] = gpa |
---|
[1174] | 109 | info['results'] = (sem1, sem2) |
---|
[1411] | 110 | info['student_from_returning'] = student_from_returning |
---|
| 111 | info['student'] = student_from_cat |
---|
[1174] | 112 | info['s_id'] = student_id |
---|
| 113 | return info |
---|
[1179] | 114 | |
---|