source: WAeUP_SRP/trunk/skins/waeup_unilorin/getTranscriptInfo.py @ 5877

Last change on this file since 5877 was 3690, checked in by Henrik Bettermann, 16 years ago

Move all customized skins into trunk. The waeup_custom skin together with the default profile is the BASE configuration which is identical to the Uniben set-up.

File size: 2.7 KB
Line 
1## Script (Python) "getTranscriptInfo"
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 2760 2007-11-26 07:39:15Z henrik $
11"""
12return Info about the Studylevel
13try:
14    from Products.zdb import set_trace
15except:
16    def set_trace():
17        pass
18"""
19
20request = context.REQUEST
21response = request.RESPONSE
22import logging
23logger = logging.getLogger('Skins.getTranscriptInfo')
24info = context.waeup_tool.getAccessInfo(context)
25student_id = info['student_id']
26if student_id is None:
27    return None
28
29mtool = context.portal_membership
30if mtool.isAnonymousUser(): # or not context.isSectionOfficer():
31    return None
32
33mtool = context.portal_membership
34member = mtool.getAuthenticatedMember()
35member_id = str(member)
36
37course_results = context.course_results
38
39
40student_record = context.students_catalog.getRecordByKey(student_id)
41info['student_record'] = context.getFormattedStudentEntry(student_record)
42
43
44year_courses = [[],[],[],[],[],[],[],[],[]]
45year_details = [{'year':0},{'year':1},{'year':2},{'year':3},{'year':4},{'year':5},{'year':6},{'year':7},{'year':8}]
46
47courses = course_results.getAllCourses(student_id)
48
49for course in courses:
50    year = divmod(int(course['level_id']),100)[0]
51    year_courses[year].append(course)
52    if not getattr(year_details[year],'session',None):
53        year_details[year]['session'] = context.portal_vocabularies.sessions.get(course['session_id'])
54
55year_counter = 0
56cgpa = 0
57c_total_credits = 0
58for year in year_courses:
59    gpa = 0
60    total_credits = 0
61    for course in year:
62        if course['weight'] and course['credits']:
63            gpa += int(course['weight']) * int(course['credits'])
64            total_credits += int(course['credits'])
65    cgpa += gpa
66    c_total_credits += total_credits
67    if gpa and total_credits:
68        year_details[year_counter]['total_credits'] = total_credits
69        year_details[year_counter]['gpa'] = "%4.2f" % (float(gpa)/int(total_credits))
70    else:
71        year_details[year_counter]['total_credits'] = 0
72        year_details[year_counter]['gpa'] = 0
73
74    if cgpa and c_total_credits:
75        year_details[year_counter]['c_total_credits'] = c_total_credits
76        year_details[year_counter]['cgpa'] = "%4.2f" % (float(cgpa)/int(c_total_credits))
77    else:
78        year_details[year_counter]['c_total_credits'] = 0
79        year_details[year_counter]['cgpa'] = 0
80
81    year.sort(cmp=lambda x,y: cmp("%(semester)s%(code)s" % x,
82                                         "%(semester)s%(code)s" % y))
83    year_counter += 1
84
85info['year_details'] = year_details
86info['year_courses'] = year_courses
87
88return info
Note: See TracBrowser for help on using the repository browser.