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

Last change on this file since 1511 was 1494, checked in by joachim, 18 years ago

make register courses work

  • Property svn:keywords set to Id
File size: 2.3 KB
RevLine 
[845]1# Script (Python) "getStudyLevelInfo"
[723]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##
[805]10# $Id: getStudyLevelInfo.py 1494 2007-02-26 09:16:06Z joachim $
[723]11"""
12return Info about the Studylevel
13"""
[1494]14try:
15    from Products.zdb import set_trace
16except:
17    def set_trace():
18        pass
[1380]19from Products.AdvancedQuery import Eq, Between, Le,In
[1494]20aq_portal = context.portal_catalog.evalAdvancedQuery
[1380]21request = context.REQUEST
22session = request.SESSION
23response = request.RESPONSE
24
[723]25def 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
[1380]42def 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
[723]48
[1380]49
[723]50wf = context.portal_workflow
51mtool = context.portal_membership
[1380]52student_id = context.getStudentId()
53
[723]54info = {}
[1380]55info['student'] = student = context.students_catalog(id=student_id)[0]
[723]56info['choosen_ids'] = request.get('ids',[])
57info['doc'] = context.getContent()
[1380]58##study_course = context.aq_parent.getContent()
59##cert_id = study_course.study_course
60cert_id = student.course
[723]61info['cert_id'] = cert_id
[1380]62normal = []
63carry_overs = []
[1482]64credits_total = 0
[1380]65for id,obj in context.objectItems():
[1482]66    try:
67        credit = int(obj.getContent().credits)
68    except ValueError:
69        credit = 3
70    credits_total += credit
[1380]71    if id.endswith('_co'):
72        d = context.getCourseInfo(id[:-3])
[1494]73        d['id'] = id
[1380]74        d['grade'] = obj.getContent().grade
75        carry_overs.append(d)
76    else:
77        d = context.getCourseInfo(id)
[1494]78        d['id'] = id
[1380]79        coe = obj.getContent().core_or_elective
80        d['coe'] = 'Core'
81        if not coe:
82            d['coe'] = 'Elective'
83        normal.append(d)
[1482]84info['credits_total'] = credits_total
[1380]85carry_overs.sort(cmp_semester)
86info['carry_overs'] = carry_overs
87normal.sort(cmp_semester)
88info['normal'] = normal
[723]89return info
Note: See TracBrowser for help on using the repository browser.