[1174] | 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() |
---|
[1510] | 8 | try: |
---|
| 9 | from Products.zdb import set_trace |
---|
| 10 | except: |
---|
| 11 | def set_trace(): |
---|
| 12 | pass |
---|
[1174] | 13 | pr = context.portal_registration |
---|
[1417] | 14 | request = context.REQUEST |
---|
[1174] | 15 | returning = context.returning_import |
---|
| 16 | results = context.results_import |
---|
[1317] | 17 | scatalog = context.students_catalog |
---|
[1174] | 18 | |
---|
| 19 | mtool = context.portal_membership |
---|
| 20 | member = mtool.getAuthenticatedMember() |
---|
| 21 | member_id = str(member) |
---|
| 22 | |
---|
| 23 | if mtool.isAnonymousUser(): |
---|
| 24 | return None |
---|
| 25 | info = {} |
---|
| 26 | requested_id = context.getStudentId() |
---|
| 27 | if requested_id and not context.isStaff() and member_id != requested_id: |
---|
[1258] | 28 | import logging |
---|
[1593] | 29 | logger = logging.getLogger('Skins.getSessionResults') |
---|
| 30 | logger.info('%s tried to access %s' % (member_id,requested_id)) |
---|
[1174] | 31 | return None |
---|
| 32 | elif context.isStaff(): |
---|
| 33 | student_id = requested_id |
---|
| 34 | else: |
---|
| 35 | student_id = member_id |
---|
| 36 | |
---|
| 37 | students_object = context.portal_url.getPortalObject().campus.students |
---|
[1315] | 38 | ##student = getattr(students_object, student_id) |
---|
| 39 | ##clear = getattr(student,'clearance',None) |
---|
| 40 | ##if clear: |
---|
| 41 | ## value = clear.getContent().matric_no |
---|
| 42 | ##else: |
---|
| 43 | ## return None |
---|
[1174] | 44 | |
---|
[1317] | 45 | res = scatalog(id = student_id) |
---|
| 46 | matric_no = res[0].matric_no |
---|
[1448] | 47 | student_from_cat = res[0] |
---|
[1317] | 48 | |
---|
| 49 | res = returning(matric_no = matric_no) |
---|
[1417] | 50 | if res: |
---|
| 51 | student_from_returning = res[0] |
---|
| 52 | else: |
---|
| 53 | return None |
---|
| 54 | |
---|
[1317] | 55 | res = results(matric_no = matric_no) |
---|
[1174] | 56 | results = res |
---|
| 57 | |
---|
| 58 | |
---|
| 59 | sem1 = [] |
---|
| 60 | sem2 = [] |
---|
| 61 | with_courses_cat = hasattr(context,'courses_catalog') |
---|
| 62 | fields = context.results_import.schema() |
---|
[1179] | 63 | gpa = 0 |
---|
| 64 | course_count = 0 |
---|
[1183] | 65 | session = None |
---|
[1468] | 66 | |
---|
[1174] | 67 | for r in results: |
---|
[1468] | 68 | if session is None: |
---|
[1183] | 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: |
---|
[1448] | 86 | result['gpa'] = 'N/A' |
---|
[1174] | 87 | else: |
---|
[1448] | 88 | result['title'] = "" |
---|
| 89 | result['credits'] = "N/A" |
---|
| 90 | result['gpa'] = 'N/A' |
---|
| 91 | result['WEIGHT'] = 'N/A' |
---|
| 92 | result['GRADE'] = 'N/A' |
---|
[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 |
---|
[1413] | 100 | |
---|
[1593] | 101 | #set_trace() |
---|
[1510] | 102 | verdict_voc = context.portal_vocabularies.verdicts |
---|
[1653] | 103 | verdict_code = student_from_cat.verdict |
---|
[1593] | 104 | if verdict_code: |
---|
| 105 | info['verdict'] = verdict = verdict_voc.get(verdict_code,'N/A').upper() |
---|
[1468] | 106 | else: |
---|
[1593] | 107 | info['verdict'] = verdict = 'N/A' |
---|
[1468] | 108 | |
---|
[1429] | 109 | if student_from_cat.level: |
---|
| 110 | if student_from_cat.sex: |
---|
| 111 | info['sex'] = 'F' |
---|
| 112 | else: |
---|
| 113 | info['sex'] = 'M' |
---|
[1524] | 114 | if verdict in ('A','B'): |
---|
| 115 | info['level'] = int(student_from_cat.level)-100 |
---|
| 116 | else: |
---|
| 117 | info['level'] = int(student_from_cat.level) |
---|
[1448] | 118 | else: |
---|
| 119 | info['sex'] = 'N/A' |
---|
| 120 | info['level'] = 'N/A' |
---|
[1429] | 121 | |
---|
[1183] | 122 | info['session'] = session |
---|
[1179] | 123 | info['gpa'] = gpa |
---|
[1174] | 124 | info['results'] = (sem1, sem2) |
---|
[1411] | 125 | info['student_from_returning'] = student_from_returning |
---|
| 126 | info['student'] = student_from_cat |
---|
[1174] | 127 | info['s_id'] = student_id |
---|
| 128 | return info |
---|
[1179] | 129 | |
---|