[3690] | 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 | cgpa = 0
|
---|
| 57 | c_total_credits = 0
|
---|
| 58 | for 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 |
|
---|
| 85 | info['year_details'] = year_details
|
---|
| 86 | info['year_courses'] = year_courses
|
---|
| 87 |
|
---|
| 88 | return info |
---|