# $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() 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 = {} #from Products.zdb import set_trace #set_trace() requested_id = context.getStudentId() if requested_id and not context.isStaff() and member_id != requested_id: import logging logger = logging.getLogger('Student.SessionResults.Info') 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 if student_from_cat.verdict: verdict_voc = context.portal_vocabularies.verdicts info['verdict'] = verdict_voc.get(student_from_cat.verdict) else: info['verdict'] = 'N/A' if student_from_cat.level: if student_from_cat.sex: info['sex'] = 'F' else: info['sex'] = 'M' info['level'] = int(student_from_cat.level)-100 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