[1513] | 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 1515 2007-03-03 11:45:58Z henrik $ |
---|
[723] | 11 | """ |
---|
| 12 | return Info about the Studylevel |
---|
| 13 | """ |
---|
[1494] | 14 | try: |
---|
| 15 | from Products.zdb import set_trace |
---|
| 16 | except: |
---|
| 17 | def set_trace(): |
---|
| 18 | pass |
---|
[1380] | 19 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
[1494] | 20 | aq_portal = context.portal_catalog.evalAdvancedQuery |
---|
[1380] | 21 | request = context.REQUEST |
---|
| 22 | session = request.SESSION |
---|
| 23 | response = request.RESPONSE |
---|
| 24 | |
---|
[723] | 25 | def calculateGPA(): |
---|
| 26 | """calculate the gpa""" |
---|
| 27 | sum = 0 |
---|
| 28 | course_count = 0 |
---|
| 29 | for sc in context.objectValues(): |
---|
| 30 | result = sc.getContent() |
---|
| 31 | if not result.grade: |
---|
| 32 | continue |
---|
| 33 | res = context.portal_catalog({'meta_type': 'Course', |
---|
| 34 | 'id': sc.aq_parent.id}) |
---|
| 35 | if len(res) < 1: |
---|
| 36 | continue |
---|
| 37 | course = res[0].getObject().getContent() |
---|
| 38 | if course_count: |
---|
| 39 | return sum/course_count |
---|
| 40 | return 0.0 |
---|
| 41 | |
---|
[1380] | 42 | def cmp_semester(a,b): |
---|
| 43 | if a['semester'] == b['semester']: |
---|
| 44 | return 0 |
---|
| 45 | if a['semester'] > b['semester']: |
---|
| 46 | return 1 |
---|
| 47 | return -1 |
---|
[723] | 48 | |
---|
[1380] | 49 | |
---|
[723] | 50 | wf = context.portal_workflow |
---|
| 51 | mtool = context.portal_membership |
---|
[1380] | 52 | student_id = context.getStudentId() |
---|
| 53 | |
---|
[1515] | 54 | |
---|
| 55 | |
---|
[723] | 56 | info = {} |
---|
[1515] | 57 | info['is_so'] = is_so = context.isSectionOfficer() |
---|
| 58 | info['is_student'] = is_student = context.isStudent() |
---|
| 59 | info['is_ca'] = is_ca = context.isCourseAdviser() |
---|
[1380] | 60 | info['student'] = student = context.students_catalog(id=student_id)[0] |
---|
[1513] | 61 | info['review_state'] = review_state = context.getStudentReviewState() |
---|
[1515] | 62 | info['view_only'] = review_state != "school_fee_paid" |
---|
| 63 | info['show_check_boxes'] = (is_ca and review_state in ('courses_registered',)) or\ |
---|
| 64 | (is_student and context.getStudentReviewState() == "school_fee_paid") or\ |
---|
| 65 | (is_so) |
---|
[723] | 66 | info['choosen_ids'] = request.get('ids',[]) |
---|
[1513] | 67 | info['status_info'] = "" |
---|
| 68 | if is_student: |
---|
[1515] | 69 | if review_state == 'courses_registered': |
---|
[1513] | 70 | info['status_info'] = "Request for Course Validation pending" |
---|
[1515] | 71 | elif review_state == 'courses_validated': |
---|
[1513] | 72 | info['status_info'] = "Courses validated" |
---|
| 73 | elif is_ca: |
---|
[1515] | 74 | if review_state == 'courses_registered': |
---|
[1513] | 75 | info['status_info'] = "Please validate these Courses" |
---|
[1515] | 76 | elif review_state == 'courses_validated': |
---|
[1513] | 77 | info['status_info'] = "Courses validated" |
---|
[723] | 78 | info['doc'] = context.getContent() |
---|
[1380] | 79 | ##study_course = context.aq_parent.getContent() |
---|
| 80 | ##cert_id = study_course.study_course |
---|
| 81 | cert_id = student.course |
---|
[723] | 82 | info['cert_id'] = cert_id |
---|
[1380] | 83 | normal = [] |
---|
| 84 | carry_overs = [] |
---|
[1482] | 85 | credits_total = 0 |
---|
[1380] | 86 | for id,obj in context.objectItems(): |
---|
[1482] | 87 | try: |
---|
| 88 | credit = int(obj.getContent().credits) |
---|
| 89 | except ValueError: |
---|
| 90 | credit = 3 |
---|
| 91 | credits_total += credit |
---|
[1380] | 92 | if id.endswith('_co'): |
---|
| 93 | d = context.getCourseInfo(id[:-3]) |
---|
[1494] | 94 | d['id'] = id |
---|
[1380] | 95 | d['grade'] = obj.getContent().grade |
---|
| 96 | carry_overs.append(d) |
---|
| 97 | else: |
---|
| 98 | d = context.getCourseInfo(id) |
---|
[1494] | 99 | d['id'] = id |
---|
[1380] | 100 | coe = obj.getContent().core_or_elective |
---|
| 101 | d['coe'] = 'Core' |
---|
| 102 | if not coe: |
---|
| 103 | d['coe'] = 'Elective' |
---|
| 104 | normal.append(d) |
---|
[1482] | 105 | info['credits_total'] = credits_total |
---|
[1380] | 106 | carry_overs.sort(cmp_semester) |
---|
| 107 | info['carry_overs'] = carry_overs |
---|
| 108 | normal.sort(cmp_semester) |
---|
| 109 | info['normal'] = normal |
---|
[723] | 110 | return info |
---|