# $Id: display_session_results.py 1166 2006-12-31 18:11:47Z henrik $ """ process the Application Form return html renderer + psm """ import DateTime current = DateTime.DateTime() try: from Products.zdb import set_trace except: def set_trace(): pass pr = context.portal_registration request = context.REQUEST returning = context.returning_import results = context.results_import scatalog = context.students_catalog mtool = context.portal_membership member = mtool.getAuthenticatedMember() member_id = str(member) if mtool.isAnonymousUser(): return None info = {} requested_id = context.getStudentId() if requested_id and not context.isStaff() and member_id != requested_id: import logging logger = logging.getLogger('Skins.getSessionResults') logger.info('%s tried to access %s' % (member_id,requested_id)) return None elif context.isStaff(): student_id = requested_id else: student_id = member_id students_object = context.portal_url.getPortalObject().campus.students ##student = getattr(students_object, student_id) ##clear = getattr(student,'clearance',None) ##if clear: ## value = clear.getContent().matric_no ##else: ## return None res = scatalog(id = student_id) matric_no = res[0].matric_no student_from_cat = res[0] res = returning(matric_no = matric_no) if res: student_from_returning = res[0] else: return None res = results(matric_no = matric_no) results = res sem1 = [] sem2 = [] with_courses_cat = hasattr(context,'courses_catalog') fields = context.results_import.schema() gpa = 0 course_count = 0 session = None for r in results: if session is None: session = r.Session result = {} for field in fields: result[field] = getattr(r,field) if with_courses_cat: res = context.courses_catalog(code = r.CosCode) if with_courses_cat and res: result['title'] = res[0].title result['credits'] = res[0].credits try: weight = int(result['WEIGHT']) credits = int(res[0].credits) gpa_course = int(res[0].credits) * weight gpa += gpa_course course_count += credits result['gpa'] = 'ok' except: result['gpa'] = 'N/A' else: result['title'] = "" result['credits'] = "N/A" result['gpa'] = 'N/A' #result['WEIGHT'] = 'N/A' #result['GRADE'] = 'N/A' if r.Semester == '2': sem2.append(result) else: sem1.append(result) if course_count: gpa = float(gpa) / course_count gpa = "%4.2f" % gpa #set_trace() verdict_voc = context.portal_vocabularies.verdicts verdict_code = student_from_cat.verdict if verdict_code: info['verdict'] = verdict = verdict_voc.get(verdict_code,'N/A').upper() else: info['verdict'] = verdict = 'N/A' if student_from_cat.level: if student_from_cat.sex: info['sex'] = 'F' else: info['sex'] = 'M' if verdict in ('A','B'): info['level'] = int(student_from_cat.level)-100 else: info['level'] = int(student_from_cat.level) else: info['sex'] = 'N/A' info['level'] = 'N/A' info['session'] = session info['gpa'] = gpa info['results'] = (sem1, sem2) info['student_from_returning'] = student_from_returning info['student'] = student_from_cat info['s_id'] = student_id return info