# 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 1494 2007-02-26 09:16:06Z joachim $ """ return Info about the Studylevel """ try: from Products.zdb import set_trace except: def set_trace(): pass from Products.AdvancedQuery import Eq, Between, Le,In aq_portal = 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 = [] credits_total = 0 for id,obj in context.objectItems(): try: credit = int(obj.getContent().credits) except ValueError: credit = 3 credits_total += credit if id.endswith('_co'): d = context.getCourseInfo(id[:-3]) d['id'] = id d['grade'] = obj.getContent().grade carry_overs.append(d) else: d = context.getCourseInfo(id) d['id'] = id coe = obj.getContent().core_or_elective d['coe'] = 'Core' if not coe: d['coe'] = 'Elective' normal.append(d) info['credits_total'] = credits_total carry_overs.sort(cmp_semester) info['carry_overs'] = carry_overs normal.sort(cmp_semester) info['normal'] = normal return info