1 | ## Script (Python) "getStudyLevelInfo" |
---|
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 | ## |
---|
10 | # $Id: getStudyLevelInfo.py 1515 2007-03-03 11:45:58Z henrik $ |
---|
11 | """ |
---|
12 | return Info about the Studylevel |
---|
13 | """ |
---|
14 | try: |
---|
15 | from Products.zdb import set_trace |
---|
16 | except: |
---|
17 | def set_trace(): |
---|
18 | pass |
---|
19 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
20 | aq_portal = context.portal_catalog.evalAdvancedQuery |
---|
21 | request = context.REQUEST |
---|
22 | session = request.SESSION |
---|
23 | response = request.RESPONSE |
---|
24 | |
---|
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 | |
---|
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 |
---|
48 | |
---|
49 | |
---|
50 | wf = context.portal_workflow |
---|
51 | mtool = context.portal_membership |
---|
52 | student_id = context.getStudentId() |
---|
53 | |
---|
54 | |
---|
55 | |
---|
56 | info = {} |
---|
57 | info['is_so'] = is_so = context.isSectionOfficer() |
---|
58 | info['is_student'] = is_student = context.isStudent() |
---|
59 | info['is_ca'] = is_ca = context.isCourseAdviser() |
---|
60 | info['student'] = student = context.students_catalog(id=student_id)[0] |
---|
61 | info['review_state'] = review_state = context.getStudentReviewState() |
---|
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) |
---|
66 | info['choosen_ids'] = request.get('ids',[]) |
---|
67 | info['status_info'] = "" |
---|
68 | if is_student: |
---|
69 | if review_state == 'courses_registered': |
---|
70 | info['status_info'] = "Request for Course Validation pending" |
---|
71 | elif review_state == 'courses_validated': |
---|
72 | info['status_info'] = "Courses validated" |
---|
73 | elif is_ca: |
---|
74 | if review_state == 'courses_registered': |
---|
75 | info['status_info'] = "Please validate these Courses" |
---|
76 | elif review_state == 'courses_validated': |
---|
77 | info['status_info'] = "Courses validated" |
---|
78 | info['doc'] = context.getContent() |
---|
79 | ##study_course = context.aq_parent.getContent() |
---|
80 | ##cert_id = study_course.study_course |
---|
81 | cert_id = student.course |
---|
82 | info['cert_id'] = cert_id |
---|
83 | normal = [] |
---|
84 | carry_overs = [] |
---|
85 | credits_total = 0 |
---|
86 | for id,obj in context.objectItems(): |
---|
87 | try: |
---|
88 | credit = int(obj.getContent().credits) |
---|
89 | except ValueError: |
---|
90 | credit = 3 |
---|
91 | credits_total += credit |
---|
92 | if id.endswith('_co'): |
---|
93 | d = context.getCourseInfo(id[:-3]) |
---|
94 | d['id'] = id |
---|
95 | d['grade'] = obj.getContent().grade |
---|
96 | carry_overs.append(d) |
---|
97 | else: |
---|
98 | d = context.getCourseInfo(id) |
---|
99 | d['id'] = id |
---|
100 | coe = obj.getContent().core_or_elective |
---|
101 | d['coe'] = 'Core' |
---|
102 | if not coe: |
---|
103 | d['coe'] = 'Elective' |
---|
104 | normal.append(d) |
---|
105 | info['credits_total'] = credits_total |
---|
106 | carry_overs.sort(cmp_semester) |
---|
107 | info['carry_overs'] = carry_overs |
---|
108 | normal.sort(cmp_semester) |
---|
109 | info['normal'] = normal |
---|
110 | return info |
---|