source: WAeUP_SRP/trunk/skins/waeup_student/getStudyLevelInfo.py @ 724

Last change on this file since 724 was 724, checked in by Henrik Bettermann, 18 years ago

GPA calculation corrected

File size: 3.0 KB
Line 
1## Script (Python) "cpsdocument_edit"
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: student_edit.py 486 2006-09-06 10:09:39Z joachim $
11"""
12return Info about the Studylevel
13"""
14def findCourse(cid):
15    ''' find the course'''
16    res = context.portal_catalog({'meta_type': 'Course',
17                                  'id': cid})
18    if len(res) < 1:
19        return None
20    course = res[0].getObject().getContent()
21    return course
22
23def calculateGPA():
24    """calculate the gpa"""
25    sum = 0
26    course_count = 0
27    for sc in context.objectValues():
28        result = sc.getContent()
29        if not result.grade:
30            continue
31        res = context.portal_catalog({'meta_type': 'Course',
32                                      'id': sc.aq_parent.id})
33        if len(res) < 1:
34            continue
35        course = res[0].getObject().getContent()
36    if course_count:
37        return sum/course_count
38    return 0.0
39
40request = context.REQUEST
41
42wf = context.portal_workflow
43mtool = context.portal_membership
44path_info = request.get('PATH_INFO').split('/')
45try:
46    i = int(path_info[-1])
47    p = 0
48except:
49    p = 1
50info = {}
51pt = request.get('PATH_TRANSLATED').split('/')
52
53student_id = pt[-(3+p)]
54level_id = pt[-(1+p)]
55info['is_manager'] = context.isManager()
56info['is_student'] = context.isStudent()
57info['action'] = "%s" % context.absolute_url()
58info['choosen_ids'] = request.get('ids',[])
59info['doc'] = context.getContent()
60study_course = context.aq_parent.getContent()
61cert_id = study_course.study_course
62brain = context.portal_catalog(meta_type="Student",id = student_id)[-1]
63cp = brain.getPath()
64info['container_path'] = cp
65info['cert_id'] = cert_id
66
67res = context.portal_catalog(meta_type="StudentCourseResult",
68                             container_path="%s/study_course/%s" % (cp,level_id))
69first = []
70second = []
71sum = 0
72course_count = 0
73for r in res:
74    row = {}
75    ro = r.getObject()
76    rd = ro.getContent()
77    row['id'] = ro.getId()
78    course = findCourse(ro.getId())
79    row['credits'] = 0
80    if course:
81        row['credits'] = course.credits
82    if row['credits'] and rd.grade:
83        credits = int(course.credits)
84        sum += credits * ['F','E','D','C','B','A'].index(rd.grade)
85        course_count += credits
86    row['sum'] = sum
87    row['count'] = course_count
88    row['title'] = rd.Title()
89    #row['core'] = rd.core_or_elective
90    row['semester'] = rd.semester
91    row['score'] = rd.score
92    row['grade'] = rd.grade
93    row['weight'] = rd.weight
94    row['url'] = ro.absolute_url()
95    row['review_state'] = wf.getInfoFor(ro,'review_state','None')
96    row['is_editable'] = mtool.checkPermission('Modify portal content', ro)
97    if rd.semester == 1:
98        first.append(row)
99    else:
100        second.append(row)
101first.sort()
102second.sort()
103gpaf = 0.0
104if course_count:
105    gpaf = (float(sum)/course_count)
106gpa = "%4.2f" % gpaf
107info['doc'].edit(mapping={'gpa': gpa})
108info['first'] = first
109info['second'] = second
110return info
Note: See TracBrowser for help on using the repository browser.