source: WAeUP_SRP/branches/srpp_on_branch/skins/waeup_student/getStudyLevelInfo.py @ 5505

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

is_* keys removed from get* functions

  • Property svn:keywords set to Id
File size: 2.5 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 913 2006-11-21 10:49:45Z 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['action'] = "%s" % context.absolute_url()
47info['choosen_ids'] = request.get('ids',[])
48info['doc'] = context.getContent()
49study_course = context.aq_parent.getContent()
50cert_id = study_course.study_course
51brain = context.portal_catalog(meta_type="Student",id = student_id)[-1]
52cp = brain.getPath()
53info['container_path'] = cp
54info['cert_id'] = cert_id
55
56res = context.portal_catalog(meta_type="StudentCourseResult",
57                             container_path="%s/study_course/%s" % (cp,level_id))
58first = []
59second = []
60sum = 0
61course_count = 0
62for r in res:
63    row = {}
64    ro = r.getObject()
65    rd = ro.getContent()
66    row['id'] = ro.getId()
67    row['credits'] = rd.credits
68    if row['credits'] and rd.grade:
69        credits = int(rd.credits)
70        sum += credits * ['F','E','D','C','B','A'].index(rd.grade)
71        course_count += credits
72    row['sum'] = sum
73    row['count'] = course_count
74    row['title'] = rd.title
75    #row['core'] = rd.core_or_elective
76    row['semester'] = rd.semester
77    row['score'] = rd.score
78    row['grade'] = rd.grade
79    row['weight'] = rd.weight
80    row['url'] = ro.absolute_url()
81    row['review_state'] = wf.getInfoFor(ro,'review_state','None')
82    row['is_editable'] = mtool.checkPermission('Modify portal content', ro)
83    if rd.semester == 1:
84        first.append(row)
85    else:
86        second.append(row)
87first.sort()
88second.sort()
89gpaf = 0.0
90if course_count:
91    gpaf = (float(sum)/course_count)
92gpa = "%4.2f" % gpaf
93info['doc'].edit(mapping={'gpa': gpaf})
94info['first'] = first
95info['second'] = second
96return info
Note: See TracBrowser for help on using the repository browser.