[5458] | 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 5459 2010-08-20 09:53:03Z 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 | student_record = context.students_catalog.getRecordByKey(student_id)
|
---|
| 40 | info['student_record'] = context.getFormattedStudentEntry(student_record)
|
---|
| 41 | students_object = context.portal_url.getPortalObject().campus.students
|
---|
| 42 | student = getattr(students_object, student_id)
|
---|
| 43 | info['app'] = student.application
|
---|
| 44 | try:
|
---|
| 45 | info['app_doc'] = student.application.getContent()
|
---|
| 46 | except:
|
---|
| 47 | return
|
---|
[5459] | 48 | ci = {}
|
---|
| 49 | ci['course'] = student_record.course
|
---|
| 50 | ci['faculty'] = student_record.faculty
|
---|
| 51 | ci['department'] = student_record.department
|
---|
| 52 | ci['entry_session'] = context.portal_vocabularies.sessions.get(student_record.entry_session)
|
---|
| 53 | ci['perm_address'] = student_record.perm_address
|
---|
[5458] | 54 |
|
---|
[5459] | 55 |
|
---|
| 56 | info['more_info'] = ci
|
---|
| 57 |
|
---|
[5458] | 58 | year_courses = [[],[],[],[],[],[],[],[],[]]
|
---|
| 59 | year_details = [{'year':0},{'year':1},{'year':2},{'year':3},{'year':4},{'year':5},{'year':6},{'year':7},{'year':8}]
|
---|
| 60 |
|
---|
| 61 | courses = course_results.getAllCourses(student_id)
|
---|
| 62 |
|
---|
| 63 | for 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 |
|
---|
| 69 | year_counter = 0
|
---|
| 70 | cgpa = 0
|
---|
| 71 | c_total_credits = 0
|
---|
| 72 | for 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 |
|
---|
| 99 | info['year_details'] = year_details
|
---|
| 100 | info['year_courses'] = year_courses
|
---|
| 101 |
|
---|
| 102 | return info |
---|