source: WAeUP_SRP/branches/joachim-azax-branch/skins/waeup_student/getStudyLevelInfo.py @ 17942

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

don't list courses with empty course id

  • Property svn:keywords set to Id
File size: 3.9 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 1974 2007-06-28 07:50:46Z henrik $
11"""
12return Info about the Studylevel
13"""
14
15wf = context.portal_workflow
16mtool = context.portal_membership
17if mtool.isAnonymousUser():
18    return None
19
20try:
21    from Products.zdb import set_trace
22except:
23    def set_trace():
24        pass
25
26
27from Products.AdvancedQuery import Eq, Between, Le,In
28try:
29    aq_portal = context.portal_catalog.evalAdvancedQuery
30except:
31    aq_portal = context.portal_catalog_real.evalAdvancedQuery
32request = context.REQUEST
33#session = request.SESSION
34response = request.RESPONSE
35
36def calculateGPA():
37    """calculate the gpa"""
38    sum = 0
39    course_count = 0
40    for sc in context.objectValues():
41        result = sc.getContent()
42        if not result.grade:
43            continue
44        res = context.portal_catalog({'meta_type': 'Course',
45                                      'id': sc.aq_parent.id})
46        if len(res) < 1:
47            continue
48        course = res[0].getObject().getContent()
49    if course_count:
50        return sum/course_count
51    return 0.0
52
53def cmp_semester_id(a,b):
54    s1 = "%(semester)s%(id)s" % a
55    s2 = "%(semester)s%(id)s" % b
56    if s1 == s2:
57        return 0
58    if s1 > s2:
59        return 1
60    return -1
61
62student_id = context.getStudentId()
63
64info = {}
65info['is_so'] = is_so = context.isSectionOfficer()
66info['is_student'] = is_student = context.isStudent()
67info['is_ca'] = is_ca = context.isCourseAdviser()
68info['student'] = student = context.students_catalog(id=student_id)[0]
69info['review_state'] = review_state = context.getStudentReviewState()
70info['view_only'] =  review_state != "school_fee_paid"
71info['show_check_boxes'] =  (is_ca and review_state in ('school_fee_paid',)) or\
72                            (is_student and context.getStudentReviewState() == "school_fee_paid") or\
73                            (is_so)
74info['choosen_ids'] = request.get('ids',[])
75info['status_info'] = ""
76if is_student:
77    if review_state == 'courses_registered':
78        info['status_info'] = "Request for Course Validation pending"
79    elif review_state == 'courses_validated':
80        info['status_info'] = "Courses validated"
81elif is_ca:
82    if review_state == 'courses_registered':
83        info['status_info'] = "Please validate these Courses"
84    elif review_state == 'courses_validated':
85        info['status_info'] = "Courses validated"
86info['doc'] = context.getContent()
87##study_course = context.aq_parent.getContent()
88##cert_id = study_course.study_course
89cert_id = student.course
90info['cert_id'] = cert_id
91normal = []
92carry_overs = []
93credits_total = 0
94for id,obj in context.objectItems():
95    #try:
96    #    credit = int(obj.getContent().credits)
97    #except ValueError:
98    #    credit = 3
99    #credits_total += credit
100    if not id:
101        continue
102    if id.endswith('_co'):
103        d = context.getCourseInfo(id[:-3])
104        try:
105            credits_total += int(d['credits'])
106        except ValueError:
107            credits_total += 0
108        d['id'] = id
109        d['grade'] = obj.getContent().grade
110        carry_overs.append(d)
111    else:
112        d = context.getCourseInfo(id)
113        d['id'] = id
114        coe = obj.getContent().core_or_elective
115        d['coe'] = 'Core'
116        try:
117            credits_total += int(d['credits'])
118        except ValueError:
119            credits_total += 0
120        if not coe:
121            d['coe'] = 'Elective'
122        normal.append(d)
123info['credits_total'] = credits_total
124info['credits_exceeded'] = credits_total > 50
125carry_overs.sort(cmp_semester_id)
126info['carry_overs'] = carry_overs
127normal.sort(cmp_semester_id)
128info['normal'] = normal
129
130students_object = context.portal_url.getPortalObject().campus.students
131student = getattr(students_object, student_id)
132info['app'] = student.application
133info['app_doc'] = student.application.getContent()
134
135return info
136
Note: See TracBrowser for help on using the repository browser.