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 | """
|
---|
12 | return Info about the Studylevel
|
---|
13 | try:
|
---|
14 | from Products.zdb import set_trace
|
---|
15 | except:
|
---|
16 | def set_trace():
|
---|
17 | pass
|
---|
18 | """
|
---|
19 |
|
---|
20 | request = context.REQUEST
|
---|
21 | response = request.RESPONSE
|
---|
22 | import logging
|
---|
23 | logger = logging.getLogger('Skins.getTranscriptInfo')
|
---|
24 | info = context.waeup_tool.getAccessInfo(context)
|
---|
25 | student_id = info['student_id']
|
---|
26 | if student_id is None:
|
---|
27 | return None
|
---|
28 |
|
---|
29 | mtool = context.portal_membership
|
---|
30 | if mtool.isAnonymousUser(): # or not context.isSectionOfficer():
|
---|
31 | return None
|
---|
32 |
|
---|
33 | mtool = context.portal_membership
|
---|
34 | member = mtool.getAuthenticatedMember()
|
---|
35 | member_id = str(member)
|
---|
36 |
|
---|
37 | course_results = context.course_results
|
---|
38 |
|
---|
39 |
|
---|
40 | student_record = context.students_catalog.getRecordByKey(student_id)
|
---|
41 | info['student_record'] = context.getFormattedStudentEntry(student_record)
|
---|
42 |
|
---|
43 |
|
---|
44 | year_courses = [[],[],[],[],[],[],[],[],[]]
|
---|
45 | year_details = [{'year':0},{'year':1},{'year':2},{'year':3},{'year':4},{'year':5},{'year':6},{'year':7},{'year':8}]
|
---|
46 |
|
---|
47 | courses = course_results.getAllCourses(student_id)
|
---|
48 |
|
---|
49 | for 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 |
|
---|
55 | year_counter = 0
|
---|
56 | for year in year_courses:
|
---|
57 | gpa = 0
|
---|
58 | total_credits = 0
|
---|
59 | for course in year:
|
---|
60 | if course['weight'] and course['credits']:
|
---|
61 | gpa += int(course['weight']) * int(course['credits'])
|
---|
62 | total_credits += int(course['credits'])
|
---|
63 | if gpa and total_credits:
|
---|
64 | year_details[year_counter]['total_credits'] = total_credits
|
---|
65 | year_details[year_counter]['gpa'] = "%4.2f" % (float(gpa)/int(total_credits))
|
---|
66 | else:
|
---|
67 | year_details[year_counter]['total_credits'] = 0
|
---|
68 | year_details[year_counter]['gpa'] = 0
|
---|
69 | year.sort(cmp=lambda x,y: cmp("%(semester)s%(code)s" % x,
|
---|
70 | "%(semester)s%(code)s" % y))
|
---|
71 | year_counter += 1
|
---|
72 |
|
---|
73 | info['year_details'] = year_details
|
---|
74 | info['year_courses'] = year_courses
|
---|
75 |
|
---|
76 | return info |
---|