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

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

fixed

  • Property svn:keywords set to Id
File size: 3.4 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 1586 2007-03-19 12:13:05Z henrik $
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
54
55
56info = {}
57info['is_so'] = is_so = context.isSectionOfficer()
58info['is_student'] = is_student = context.isStudent()
59info['is_ca'] = is_ca = context.isCourseAdviser()
60info['student'] = student = context.students_catalog(id=student_id)[0]
61info['review_state'] = review_state = context.getStudentReviewState()
62info['view_only'] =  review_state != "school_fee_paid"
63info['show_check_boxes'] =  (is_ca and review_state in ('school_fee_paid',)) or\
64                            (is_student and context.getStudentReviewState() == "school_fee_paid") or\
65                            (is_so)
66info['choosen_ids'] = request.get('ids',[])
67info['status_info'] = ""
68if is_student:
69    if review_state == 'courses_registered':
70        info['status_info'] = "Request for Course Validation pending"
71    elif review_state == 'courses_validated':
72        info['status_info'] = "Courses validated"
73elif is_ca:
74    if review_state == 'courses_registered':
75        info['status_info'] = "Please validate these Courses"
76    elif review_state == 'courses_validated':
77        info['status_info'] = "Courses validated"
78info['doc'] = context.getContent()
79##study_course = context.aq_parent.getContent()
80##cert_id = study_course.study_course
81cert_id = student.course
82info['cert_id'] = cert_id
83normal = []
84carry_overs = []
85credits_total = 0
86for id,obj in context.objectItems():
87    try:
88        credit = int(obj.getContent().credits)
89    except ValueError:
90        credit = 3
91    credits_total += credit
92    if id.endswith('_co'):
93        d = context.getCourseInfo(id[:-3])
94        d['id'] = id
95        d['grade'] = obj.getContent().grade
96        carry_overs.append(d)
97    else:
98        d = context.getCourseInfo(id)
99        d['id'] = id
100        coe = obj.getContent().core_or_elective
101        d['coe'] = 'Core'
102        if not coe:
103            d['coe'] = 'Elective'
104        normal.append(d)
105info['credits_total'] = credits_total
106carry_overs.sort(cmp_semester)
107info['carry_overs'] = carry_overs
108normal.sort(cmp_semester)
109info['normal'] = normal
110
111students_object = context.portal_url.getPortalObject().campus.students
112student = getattr(students_object, student_id)
113info['app'] = student.application
114info['app_doc'] = student.application.getContent()
115
116return info
Note: See TracBrowser for help on using the repository browser.