## Script (Python) "getSessionResults" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters= ##title= ## # $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 returning = context.returning_import results = context.results_import 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: 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 = returning(matric_no = value) student = res[0] res = results(matric_no = value) results = res sem1 = [] sem2 = [] with_courses_cat = hasattr(context,'courses_catalog') fields = context.results_import.schema() gpa = 0 course_count = 0 verdict = None session = None for r in results: if verdict is None: verdict = r.Verdict 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'] = 'na' else: result['title'] = "na" result['credits'] = "na" result['gpa'] = 'na' if r.Semester == '2': sem2.append(result) else: sem1.append(result) if course_count: gpa = float(gpa) / course_count gpa = "%4.2f" % gpa info['verdict'] = verdict info['session'] = session info['gpa'] = gpa info['results'] = (sem1, sem2) info['student'] = student info['s_id'] = student_id return info