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

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

register courses

  • Property svn:keywords set to Id
File size: 3.1 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 1513 2007-03-02 22:59:45Z joachim $
11"""
12return Info about the Studylevel
13"""
14try:
15    from Products.zdb import set_trace
16except:
17    def set_trace():
18        pass
19from Products.AdvancedQuery import Eq, Between, Le,In
20aq_portal = context.portal_catalog.evalAdvancedQuery
21request = context.REQUEST
22session = request.SESSION
23response = request.RESPONSE
24
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
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
48
49
50wf = context.portal_workflow
51mtool = context.portal_membership
52student_id = context.getStudentId()
53
54info = {}
55info['is_student'] = is_student = context.isStudent()
56info['is_ca'] = is_ca = context.isCourseAdviser()
57info['student'] = student = context.students_catalog(id=student_id)[0]
58info['review_state'] = review_state = context.getStudentReviewState()
59info['view_only'] =  review_state != "school_fee_paid"
60info['show_check_boxes'] =  (is_ca and review_state == 'courses_registered') or (is_student and context.getStudentReviewState() == "school_fee_paid")
61info['choosen_ids'] = request.get('ids',[])
62info['status_info'] = ""
63if is_student:
64    if review_state == 'courses_registered':
65        info['status_info'] = "Request for Course Validation pending"
66    elif review_state == 'courses_validated':
67        info['status_info'] = "Courses validated"
68elif is_ca:
69    if review_state == 'courses_registered':
70        info['status_info'] = "Please validate these Courses"
71    elif review_state == 'courses_validated':
72        info['status_info'] = "Courses validated"
73info['doc'] = context.getContent()
74##study_course = context.aq_parent.getContent()
75##cert_id = study_course.study_course
76cert_id = student.course
77info['cert_id'] = cert_id
78normal = []
79carry_overs = []
80credits_total = 0
81for id,obj in context.objectItems():
82    try:
83        credit = int(obj.getContent().credits)
84    except ValueError:
85        credit = 3
86    credits_total += credit
87    if id.endswith('_co'):
88        d = context.getCourseInfo(id[:-3])
89        d['id'] = id
90        d['grade'] = obj.getContent().grade
91        carry_overs.append(d)
92    else:
93        d = context.getCourseInfo(id)
94        d['id'] = id
95        coe = obj.getContent().core_or_elective
96        d['coe'] = 'Core'
97        if not coe:
98            d['coe'] = 'Elective'
99        normal.append(d)
100info['credits_total'] = credits_total
101carry_overs.sort(cmp_semester)
102info['carry_overs'] = carry_overs
103normal.sort(cmp_semester)
104info['normal'] = normal
105return info
Note: See TracBrowser for help on using the repository browser.