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

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

corrections (all in custom)

File size: 2.6 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
21
22mtool = context.portal_membership
23member = mtool.getAuthenticatedMember()
24member_id = str(member)
25
26if mtool.isAnonymousUser():
27    return None
28info = {}
29#from Products.zdb import set_trace
30#set_trace()
31requested_id = context.getStudentId()
32if requested_id and not context.isStaff() and member_id != requested_id:
33    import logging
34    logger = logging.getLogger('Student.SessionResults.Info')
35    logger.info('"%s", "tried to access", "%s"' % (member_id,requested_id))
36    return None
37elif context.isStaff():
38    student_id = requested_id
39else:
40    student_id = member_id
41
42students_object = context.portal_url.getPortalObject().campus.students
43student = getattr(students_object, student_id)
44
45
46clear = getattr(student,'clearance',None)
47if clear:
48    value = clear.getContent().matric_no
49else:
50    return None
51
52res = returning(matric_no = value)
53student = res[0]
54res = results(matric_no = value)
55results = res
56
57
58sem1 = []
59sem2 = []
60with_courses_cat = hasattr(context,'courses_catalog')
61fields = context.results_import.schema()
62gpa = 0
63course_count = 0
64verdict = None
65session = None
66for r in results:
67    if verdict is None:
68        verdict = r.Verdict
69        session = r.Session
70    result = {}
71    for field in fields:
72        result[field] = getattr(r,field)
73    if with_courses_cat:
74        res = context.courses_catalog(code = r.CosCode)
75    if with_courses_cat and res:
76        result['title'] = res[0].title
77        result['credits'] = res[0].credits
78        try:
79            weight = int(result['WEIGHT'])
80            credits = int(res[0].credits)
81            gpa_course =  int(res[0].credits) * weight
82            gpa += gpa_course
83            course_count += credits
84            result['gpa'] = 'ok'
85        except:
86            result['gpa'] = 'na'
87    else:
88        result['title'] = "na"
89        result['credits'] = "na"
90        result['gpa'] = 'na'
91    if r.Semester == '2':
92        sem2.append(result)
93    else:
94        sem1.append(result)
95if course_count:
96    gpa = float(gpa) / course_count
97    gpa = "%4.2f" % gpa
98info['verdict'] = verdict
99info['session'] = session
100info['gpa'] = gpa
101info['results'] = (sem1, sem2)
102info['student'] = student
103info['s_id'] = student_id
104return info
105
Note: See TracBrowser for help on using the repository browser.