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

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

script names corrected

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