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

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

prepared for import of dummy results

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