source: WAeUP_SRP/trunk/skins/waeup_student/getSessionResults.py @ 1331

Last change on this file since 1331 was 1317, checked in by Henrik Bettermann, 18 years ago

getSessionResults fixed
getTransferInfo fixed
first transfer form added

File size: 2.7 KB
Line 
1## Script (Python) "getSessionResults"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=
8##title=
9##
10# $Id: display_session_results.py 1166 2006-12-31 18:11:47Z henrik $
11"""
12process the Application Form
13return html renderer + psm
14"""
15import DateTime
16current = DateTime.DateTime()
17pr = context.portal_registration
18
19returning = context.returning_import
20results = context.results_import
21scatalog = context.students_catalog
22
23mtool = context.portal_membership
24member = mtool.getAuthenticatedMember()
25member_id = str(member)
26
27if mtool.isAnonymousUser():
28    return None
29info = {}
30#from Products.zdb import set_trace
31#set_trace()
32requested_id = context.getStudentId()
33if requested_id and not context.isStaff() and member_id != requested_id:
34    import logging
35    logger = logging.getLogger('Student.SessionResults.Info')
36    logger.info('"%s", "tried to access", "%s"' % (member_id,requested_id))
37    return None
38elif context.isStaff():
39    student_id = requested_id
40else:
41    student_id = member_id
42
43students_object = context.portal_url.getPortalObject().campus.students
44##student = getattr(students_object, student_id)
45##clear = getattr(student,'clearance',None)
46##if clear:
47##    value = clear.getContent().matric_no
48##else:
49##    return None
50
51res = scatalog(id = student_id)
52matric_no = res[0].matric_no
53
54res = returning(matric_no = matric_no)
55student = res[0]
56res = results(matric_no = matric_no)
57results = res
58
59
60sem1 = []
61sem2 = []
62with_courses_cat = hasattr(context,'courses_catalog')
63fields = context.results_import.schema()
64gpa = 0
65course_count = 0
66verdict = None
67session = None
68for r in results:
69    if verdict is None:
70        verdict = r.Verdict
71        session = r.Session
72    result = {}
73    for field in fields:
74        result[field] = getattr(r,field)
75    if with_courses_cat:
76        res = context.courses_catalog(code = r.CosCode)
77    if with_courses_cat and res:
78        result['title'] = res[0].title
79        result['credits'] = res[0].credits
80        try:
81            weight = int(result['WEIGHT'])
82            credits = int(res[0].credits)
83            gpa_course =  int(res[0].credits) * weight
84            gpa += gpa_course
85            course_count += credits
86            result['gpa'] = 'ok'
87        except:
88            result['gpa'] = 'na'
89    else:
90        result['title'] = "na"
91        result['credits'] = "na"
92        result['gpa'] = 'na'
93    if r.Semester == '2':
94        sem2.append(result)
95    else:
96        sem1.append(result)
97if course_count:
98    gpa = float(gpa) / course_count
99    gpa = "%4.2f" % gpa
100info['verdict'] = verdict
101info['session'] = session
102info['gpa'] = gpa
103info['results'] = (sem1, sem2)
104info['student'] = student
105info['s_id'] = student_id
106return info
107
Note: See TracBrowser for help on using the repository browser.