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

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

sex and level from returning_import not from students_catalog

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