[845] | 1 | # Script (Python) "getStudyLevelInfo" |
---|
[723] | 2 | ##bind container=container |
---|
| 3 | ##bind context=context |
---|
| 4 | ##bind namespace= |
---|
| 5 | ##bind script=script |
---|
| 6 | ##bind subpath=traverse_subpath |
---|
| 7 | ##parameters=student=None |
---|
| 8 | ##title= |
---|
| 9 | ## |
---|
[805] | 10 | # $Id: getStudyLevelInfo.py 1380 2007-01-31 16:24:18Z joachim $ |
---|
[723] | 11 | """ |
---|
| 12 | return Info about the Studylevel |
---|
| 13 | """ |
---|
[1380] | 14 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
| 15 | evalAdvancedQuery = context.portal_catalog.evalAdvancedQuery |
---|
| 16 | request = context.REQUEST |
---|
| 17 | session = request.SESSION |
---|
| 18 | response = request.RESPONSE |
---|
| 19 | |
---|
[723] | 20 | def calculateGPA(): |
---|
| 21 | """calculate the gpa""" |
---|
| 22 | sum = 0 |
---|
| 23 | course_count = 0 |
---|
| 24 | for sc in context.objectValues(): |
---|
| 25 | result = sc.getContent() |
---|
| 26 | if not result.grade: |
---|
| 27 | continue |
---|
| 28 | res = context.portal_catalog({'meta_type': 'Course', |
---|
| 29 | 'id': sc.aq_parent.id}) |
---|
| 30 | if len(res) < 1: |
---|
| 31 | continue |
---|
| 32 | course = res[0].getObject().getContent() |
---|
| 33 | if course_count: |
---|
| 34 | return sum/course_count |
---|
| 35 | return 0.0 |
---|
| 36 | |
---|
[1380] | 37 | def cmp_semester(a,b): |
---|
| 38 | if a['semester'] == b['semester']: |
---|
| 39 | return 0 |
---|
| 40 | if a['semester'] > b['semester']: |
---|
| 41 | return 1 |
---|
| 42 | return -1 |
---|
[723] | 43 | |
---|
[1380] | 44 | |
---|
[723] | 45 | wf = context.portal_workflow |
---|
| 46 | mtool = context.portal_membership |
---|
[1380] | 47 | student_id = context.getStudentId() |
---|
| 48 | |
---|
[723] | 49 | info = {} |
---|
[1380] | 50 | info['student'] = student = context.students_catalog(id=student_id)[0] |
---|
[723] | 51 | info['choosen_ids'] = request.get('ids',[]) |
---|
| 52 | info['doc'] = context.getContent() |
---|
[1380] | 53 | ##study_course = context.aq_parent.getContent() |
---|
| 54 | ##cert_id = study_course.study_course |
---|
| 55 | cert_id = student.course |
---|
[723] | 56 | info['cert_id'] = cert_id |
---|
[1380] | 57 | normal = [] |
---|
| 58 | carry_overs = [] |
---|
| 59 | for id,obj in context.objectItems(): |
---|
| 60 | if id.endswith('_co'): |
---|
| 61 | d = context.getCourseInfo(id[:-3]) |
---|
| 62 | d['grade'] = obj.getContent().grade |
---|
| 63 | carry_overs.append(d) |
---|
| 64 | else: |
---|
| 65 | d = context.getCourseInfo(id) |
---|
| 66 | coe = obj.getContent().core_or_elective |
---|
| 67 | d['coe'] = 'Core' |
---|
| 68 | if not coe: |
---|
| 69 | d['coe'] = 'Elective' |
---|
| 70 | normal.append(d) |
---|
[723] | 71 | |
---|
[1380] | 72 | carry_overs.sort(cmp_semester) |
---|
| 73 | info['carry_overs'] = carry_overs |
---|
| 74 | normal.sort(cmp_semester) |
---|
| 75 | info['normal'] = normal |
---|
[723] | 76 | return info |
---|