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

Last change on this file since 1795 was 1783, checked in by Henrik Bettermann, 18 years ago
  • assertViewable removed and page templates adjusted, so that no traceback occurs.
  • 'Previous Session' action added
  • waeup_content_master.pt removed
  • and more
  • Property svn:keywords set to Id
File size: 3.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 1783 2007-05-15 07:49:50Z 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
28aq_portal = context.portal_catalog.evalAdvancedQuery
29request = context.REQUEST
30session = request.SESSION
31response = request.RESPONSE
32
33def calculateGPA():
34    """calculate the gpa"""
35    sum = 0
36    course_count = 0
37    for sc in context.objectValues():
38        result = sc.getContent()
39        if not result.grade:
40            continue
41        res = context.portal_catalog({'meta_type': 'Course',
42                                      'id': sc.aq_parent.id})
43        if len(res) < 1:
44            continue
45        course = res[0].getObject().getContent()
46    if course_count:
47        return sum/course_count
48    return 0.0
49
50def cmp_semester_id(a,b):
51    s1 = "%(semester)s%(id)s" % a
52    s2 = "%(semester)s%(id)s" % b
53    if s1 == s2:
54        return 0
55    if s1 > s2:
56        return 1
57    return -1
58
59student_id = context.getStudentId()
60
61info = {}
62info['is_so'] = is_so = context.isSectionOfficer()
63info['is_student'] = is_student = context.isStudent()
64info['is_ca'] = is_ca = context.isCourseAdviser()
65info['student'] = student = context.students_catalog(id=student_id)[0]
66info['review_state'] = review_state = context.getStudentReviewState()
67info['view_only'] =  review_state != "school_fee_paid"
68info['show_check_boxes'] =  (is_ca and review_state in ('school_fee_paid',)) or\
69                            (is_student and context.getStudentReviewState() == "school_fee_paid") or\
70                            (is_so)
71info['choosen_ids'] = request.get('ids',[])
72info['status_info'] = ""
73if is_student:
74    if review_state == 'courses_registered':
75        info['status_info'] = "Request for Course Validation pending"
76    elif review_state == 'courses_validated':
77        info['status_info'] = "Courses validated"
78elif is_ca:
79    if review_state == 'courses_registered':
80        info['status_info'] = "Please validate these Courses"
81    elif review_state == 'courses_validated':
82        info['status_info'] = "Courses validated"
83info['doc'] = context.getContent()
84##study_course = context.aq_parent.getContent()
85##cert_id = study_course.study_course
86cert_id = student.course
87info['cert_id'] = cert_id
88normal = []
89carry_overs = []
90credits_total = 0
91for id,obj in context.objectItems():
92    try:
93        credit = int(obj.getContent().credits)
94    except ValueError:
95        credit = 3
96    credits_total += credit
97    if id.endswith('_co'):
98        d = context.getCourseInfo(id[:-3])
99        d['id'] = id
100        d['grade'] = obj.getContent().grade
101        carry_overs.append(d)
102    else:
103        d = context.getCourseInfo(id)
104        d['id'] = id
105        coe = obj.getContent().core_or_elective
106        d['coe'] = 'Core'
107        if not coe:
108            d['coe'] = 'Elective'
109        normal.append(d)
110info['credits_total'] = credits_total
111carry_overs.sort(cmp_semester_id)
112info['carry_overs'] = carry_overs
113normal.sort(cmp_semester_id)
114info['normal'] = normal
115
116students_object = context.portal_url.getPortalObject().campus.students
117student = getattr(students_object, student_id)
118info['app'] = student.application
119info['app_doc'] = student.application.getContent()
120
121return info
Note: See TracBrowser for help on using the repository browser.