source: WAeUP_SRP/trunk/skins/waeup_fceoyo/getTranscriptInfo.py @ 11951

Last change on this file since 11951 was 6298, checked in by Henrik Bettermann, 14 years ago

Enable transcripts on the fceoyo site.

  • Property svn:keywords set to Id
File size: 3.2 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: getTranscriptInfo.py 6298 2011-06-08 13:05:37Z 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
39student_record = context.students_catalog.getRecordByKey(student_id)
40info['student_record'] = context.getFormattedStudentEntry(student_record)
41students_object = context.portal_url.getPortalObject().campus.students
42student = getattr(students_object, student_id)
43info['app'] = student.application
44try:
45    info['app_doc'] = student.application.getContent()
46except:
47    return
48ci = {}
49ci['course'] = student_record.course
50ci['faculty'] = student_record.faculty
51ci['department'] = student_record.department
52ci['entry_session'] = context.portal_vocabularies.sessions.get(student_record.entry_session)
53ci['perm_address'] = student_record.perm_address
54
55
56info['more_info'] = ci 
57
58year_courses = [[],[],[],[],[],[],[],[],[]]
59year_details = [{'year':0},{'year':1},{'year':2},{'year':3},{'year':4},{'year':5},{'year':6},{'year':7},{'year':8}]
60
61courses = course_results.getAllCourses(student_id)
62
63for course in courses:
64    year = divmod(int(course['level_id']),100)[0]
65    year_courses[year].append(course)
66    if not getattr(year_details[year],'session',None):
67        year_details[year]['session'] = context.portal_vocabularies.sessions.get(course['session_id'])
68
69year_counter = 0
70cgpa = 0
71c_total_credits = 0
72for year in year_courses:
73    gpa = 0
74    total_credits = 0
75    for course in year:
76        if course['weight'] and course['credits']:
77            gpa += int(course['weight']) * int(course['credits'])
78            total_credits += int(course['credits'])
79    cgpa += gpa
80    c_total_credits += total_credits
81    if gpa and total_credits:
82        year_details[year_counter]['total_credits'] = total_credits
83        year_details[year_counter]['gpa'] = "%4.2f" % (float(gpa)/int(total_credits))
84    else:
85        year_details[year_counter]['total_credits'] = 0
86        year_details[year_counter]['gpa'] = 0
87
88    if cgpa and c_total_credits:
89        year_details[year_counter]['c_total_credits'] = c_total_credits
90        year_details[year_counter]['cgpa'] = "%4.2f" % (float(cgpa)/int(c_total_credits))
91    else:
92        year_details[year_counter]['c_total_credits'] = 0
93        year_details[year_counter]['cgpa'] = 0
94
95    year.sort(cmp=lambda x,y: cmp("%(semester)s%(code)s" % x,
96                                         "%(semester)s%(code)s" % y))
97    year_counter += 1
98
99info['year_details'] = year_details
100info['year_courses'] = year_courses
101
102return info
Note: See TracBrowser for help on using the repository browser.