[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 1482 2007-02-23 16:56:46Z 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 = [] |
---|
[1482] | 59 | credits_total = 0 |
---|
[1380] | 60 | for id,obj in context.objectItems(): |
---|
[1482] | 61 | try: |
---|
| 62 | credit = int(obj.getContent().credits) |
---|
| 63 | except ValueError: |
---|
| 64 | credit = 3 |
---|
| 65 | credits_total += credit |
---|
[1380] | 66 | if id.endswith('_co'): |
---|
| 67 | d = context.getCourseInfo(id[:-3]) |
---|
| 68 | d['grade'] = obj.getContent().grade |
---|
| 69 | carry_overs.append(d) |
---|
| 70 | else: |
---|
| 71 | d = context.getCourseInfo(id) |
---|
| 72 | coe = obj.getContent().core_or_elective |
---|
| 73 | d['coe'] = 'Core' |
---|
| 74 | if not coe: |
---|
| 75 | d['coe'] = 'Elective' |
---|
| 76 | normal.append(d) |
---|
[1482] | 77 | info['credits_total'] = credits_total |
---|
[1380] | 78 | carry_overs.sort(cmp_semester) |
---|
| 79 | info['carry_overs'] = carry_overs |
---|
| 80 | normal.sort(cmp_semester) |
---|
| 81 | info['normal'] = normal |
---|
[723] | 82 | return info |
---|