[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 |
---|
[1571] | 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 | |
---|
[1753] | 49 | #res = returning(matric_no = matric_no) |
---|
| 50 | #if res: |
---|
| 51 | # student_from_returning = res[0] |
---|
| 52 | #else: |
---|
| 53 | # return None |
---|
[1417] | 54 | |
---|
[1900] | 55 | if matric_no: |
---|
| 56 | res = results(matric_no = matric_no) |
---|
| 57 | results = res |
---|
[2466] | 58 | else: |
---|
[1900] | 59 | results = [] |
---|
[1174] | 60 | |
---|
| 61 | |
---|
| 62 | sem1 = [] |
---|
| 63 | sem2 = [] |
---|
| 64 | with_courses_cat = hasattr(context,'courses_catalog') |
---|
| 65 | fields = context.results_import.schema() |
---|
[1179] | 66 | gpa = 0 |
---|
| 67 | course_count = 0 |
---|
[1183] | 68 | session = None |
---|
[2466] | 69 | level = None |
---|
[2485] | 70 | verdict = None |
---|
[1468] | 71 | |
---|
[1174] | 72 | for r in results: |
---|
[1468] | 73 | if session is None: |
---|
[1183] | 74 | session = r.Session |
---|
[2466] | 75 | if level is None: |
---|
[2485] | 76 | level = r.Level |
---|
| 77 | if verdict is None: |
---|
[2486] | 78 | verdict = r.Verdict |
---|
[1174] | 79 | result = {} |
---|
| 80 | for field in fields: |
---|
| 81 | result[field] = getattr(r,field) |
---|
| 82 | if with_courses_cat: |
---|
| 83 | res = context.courses_catalog(code = r.CosCode) |
---|
| 84 | if with_courses_cat and res: |
---|
| 85 | result['title'] = res[0].title |
---|
[1179] | 86 | result['credits'] = res[0].credits |
---|
| 87 | try: |
---|
| 88 | weight = int(result['WEIGHT']) |
---|
| 89 | credits = int(res[0].credits) |
---|
| 90 | gpa_course = int(res[0].credits) * weight |
---|
| 91 | gpa += gpa_course |
---|
| 92 | course_count += credits |
---|
| 93 | result['gpa'] = 'ok' |
---|
| 94 | except: |
---|
[1448] | 95 | result['gpa'] = 'N/A' |
---|
[1174] | 96 | else: |
---|
[1448] | 97 | result['title'] = "" |
---|
| 98 | result['credits'] = "N/A" |
---|
| 99 | result['gpa'] = 'N/A' |
---|
[1684] | 100 | #result['WEIGHT'] = 'N/A' |
---|
| 101 | #result['GRADE'] = 'N/A' |
---|
[1174] | 102 | if r.Semester == '2': |
---|
| 103 | sem2.append(result) |
---|
| 104 | else: |
---|
| 105 | sem1.append(result) |
---|
[1179] | 106 | if course_count: |
---|
| 107 | gpa = float(gpa) / course_count |
---|
| 108 | gpa = "%4.2f" % gpa |
---|
[1413] | 109 | |
---|
[1543] | 110 | #set_trace() |
---|
[2485] | 111 | #verdict_voc = context.portal_vocabularies.verdicts |
---|
| 112 | #verdict_code = student_from_cat.verdict |
---|
| 113 | #if verdict_code: |
---|
| 114 | # info['verdict'] = verdict = verdict_voc.get(verdict_code,'N/A').upper() |
---|
| 115 | #else: |
---|
| 116 | # info['verdict'] = verdict = 'N/A' |
---|
[1468] | 117 | |
---|
[2485] | 118 | if verdict: |
---|
| 119 | info['verdict'] = verdict |
---|
[2486] | 120 | else: |
---|
| 121 | info['verdict'] = 'N/A' |
---|
[2466] | 122 | if session: |
---|
| 123 | info['session'] = session |
---|
[1448] | 124 | else: |
---|
[2466] | 125 | info['session'] = 'N/A' |
---|
| 126 | if level: |
---|
| 127 | info['level'] = level |
---|
| 128 | else: |
---|
[1448] | 129 | info['level'] = 'N/A' |
---|
[1179] | 130 | info['gpa'] = gpa |
---|
[1174] | 131 | info['results'] = (sem1, sem2) |
---|
[1753] | 132 | #info['student_from_returning'] = student_from_returning |
---|
[1411] | 133 | info['student'] = student_from_cat |
---|
[1174] | 134 | info['s_id'] = student_id |
---|
| 135 | return info |
---|
[1179] | 136 | |
---|