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

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

names from students_catalog

File size: 2.9 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
53student_from_cat = res[0]
54
55res = returning(matric_no = matric_no)
56student_from_returning = res[0]
57res = results(matric_no = matric_no)
58results = res
59
60
61sem1 = []
62sem2 = []
63with_courses_cat = hasattr(context,'courses_catalog')
64fields = context.results_import.schema()
65gpa = 0
66course_count = 0
67verdict = None
68session = None
69for r in results:
70    if verdict is None:
71        verdict = r.Verdict
72        session = r.Session
73    result = {}
74    for field in fields:
75        result[field] = getattr(r,field)
76    if with_courses_cat:
77        res = context.courses_catalog(code = r.CosCode)
78    if with_courses_cat and res:
79        result['title'] = res[0].title
80        result['credits'] = res[0].credits
81        try:
82            weight = int(result['WEIGHT'])
83            credits = int(res[0].credits)
84            gpa_course =  int(res[0].credits) * weight
85            gpa += gpa_course
86            course_count += credits
87            result['gpa'] = 'ok'
88        except:
89            result['gpa'] = 'na'
90    else:
91        result['title'] = "na"
92        result['credits'] = "na"
93        result['gpa'] = 'na'
94    if r.Semester == '2':
95        sem2.append(result)
96    else:
97        sem1.append(result)
98if course_count:
99    gpa = float(gpa) / course_count
100    gpa = "%4.2f" % gpa
101if student_from_cat.sex:
102    info['sex'] = 'F'
103else:
104    info['sex'] = 'M'
105info['level'] = int(student_from_cat.level)-100
106info['verdict'] = verdict
107info['session'] = session
108info['gpa'] = gpa
109info['results'] = (sem1, sem2)
110info['student_from_returning'] = student_from_returning
111info['student'] = student_from_cat
112info['s_id'] = student_id
113return info
114
Note: See TracBrowser for help on using the repository browser.