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