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 1641 2007-03-26 17:51:30Z joachim $ |
---|
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_id(a,b): |
---|
43 | s1 = "%(semester)s%(id)s" % a |
---|
44 | s2 = "%(semester)s%(id)s" % b |
---|
45 | if s1 == s2: |
---|
46 | return 0 |
---|
47 | if s1 > s2: |
---|
48 | return 1 |
---|
49 | return -1 |
---|
50 | |
---|
51 | |
---|
52 | wf = context.portal_workflow |
---|
53 | mtool = context.portal_membership |
---|
54 | student_id = context.getStudentId() |
---|
55 | |
---|
56 | |
---|
57 | |
---|
58 | info = {} |
---|
59 | info['is_so'] = is_so = context.isSectionOfficer() |
---|
60 | info['is_student'] = is_student = context.isStudent() |
---|
61 | info['is_ca'] = is_ca = context.isCourseAdviser() |
---|
62 | info['student'] = student = context.students_catalog(id=student_id)[0] |
---|
63 | info['review_state'] = review_state = context.getStudentReviewState() |
---|
64 | info['view_only'] = review_state != "school_fee_paid" |
---|
65 | info['show_check_boxes'] = (is_ca and review_state in ('school_fee_paid',)) or\ |
---|
66 | (is_student and context.getStudentReviewState() == "school_fee_paid") or\ |
---|
67 | (is_so) |
---|
68 | info['choosen_ids'] = request.get('ids',[]) |
---|
69 | info['status_info'] = "" |
---|
70 | if is_student: |
---|
71 | if review_state == 'courses_registered': |
---|
72 | info['status_info'] = "Request for Course Validation pending" |
---|
73 | elif review_state == 'courses_validated': |
---|
74 | info['status_info'] = "Courses validated" |
---|
75 | elif is_ca: |
---|
76 | if review_state == 'courses_registered': |
---|
77 | info['status_info'] = "Please validate these Courses" |
---|
78 | elif review_state == 'courses_validated': |
---|
79 | info['status_info'] = "Courses validated" |
---|
80 | info['doc'] = context.getContent() |
---|
81 | ##study_course = context.aq_parent.getContent() |
---|
82 | ##cert_id = study_course.study_course |
---|
83 | cert_id = student.course |
---|
84 | info['cert_id'] = cert_id |
---|
85 | normal = [] |
---|
86 | carry_overs = [] |
---|
87 | credits_total = 0 |
---|
88 | for id,obj in context.objectItems(): |
---|
89 | try: |
---|
90 | credit = int(obj.getContent().credits) |
---|
91 | except ValueError: |
---|
92 | credit = 3 |
---|
93 | credits_total += credit |
---|
94 | if id.endswith('_co'): |
---|
95 | d = context.getCourseInfo(id[:-3]) |
---|
96 | d['id'] = id |
---|
97 | d['grade'] = obj.getContent().grade |
---|
98 | carry_overs.append(d) |
---|
99 | else: |
---|
100 | d = context.getCourseInfo(id) |
---|
101 | d['id'] = id |
---|
102 | coe = obj.getContent().core_or_elective |
---|
103 | d['coe'] = 'Core' |
---|
104 | if not coe: |
---|
105 | d['coe'] = 'Elective' |
---|
106 | normal.append(d) |
---|
107 | info['credits_total'] = credits_total |
---|
108 | carry_overs.sort(cmp_semester_id) |
---|
109 | info['carry_overs'] = carry_overs |
---|
110 | normal.sort(cmp_semester_id) |
---|
111 | info['normal'] = normal |
---|
112 | |
---|
113 | students_object = context.portal_url.getPortalObject().campus.students |
---|
114 | student = getattr(students_object, student_id) |
---|
115 | info['app'] = student.application |
---|
116 | info['app_doc'] = student.application.getContent() |
---|
117 | |
---|
118 | return info |
---|