# Script (Python) "getStudyLevelInfo" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=student=None ##title= ## # $Id: getStudyLevelInfo.py 1380 2007-01-31 16:24:18Z joachim $ """ return Info about the Studylevel """ from Products.AdvancedQuery import Eq, Between, Le,In evalAdvancedQuery = context.portal_catalog.evalAdvancedQuery request = context.REQUEST session = request.SESSION response = request.RESPONSE def calculateGPA(): """calculate the gpa""" sum = 0 course_count = 0 for sc in context.objectValues(): result = sc.getContent() if not result.grade: continue res = context.portal_catalog({'meta_type': 'Course', 'id': sc.aq_parent.id}) if len(res) < 1: continue course = res[0].getObject().getContent() if course_count: return sum/course_count return 0.0 def cmp_semester(a,b): if a['semester'] == b['semester']: return 0 if a['semester'] > b['semester']: return 1 return -1 wf = context.portal_workflow mtool = context.portal_membership student_id = context.getStudentId() info = {} info['student'] = student = context.students_catalog(id=student_id)[0] info['choosen_ids'] = request.get('ids',[]) info['doc'] = context.getContent() ##study_course = context.aq_parent.getContent() ##cert_id = study_course.study_course cert_id = student.course info['cert_id'] = cert_id normal = [] carry_overs = [] for id,obj in context.objectItems(): if id.endswith('_co'): d = context.getCourseInfo(id[:-3]) d['grade'] = obj.getContent().grade carry_overs.append(d) else: d = context.getCourseInfo(id) coe = obj.getContent().core_or_elective d['coe'] = 'Core' if not coe: d['coe'] = 'Elective' normal.append(d) carry_overs.sort(cmp_semester) info['carry_overs'] = carry_overs normal.sort(cmp_semester) info['normal'] = normal return info