source: WAeUP_SRP/branches/joachim-azax-branch/skins/waeup_student/getSessionResults.py @ 17388

Last change on this file since 17388 was 1900, checked in by Henrik Bettermann, 17 years ago

getSessionResults: avoid memory overflow
WAeUPTool: make addStudent work

File size: 3.3 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()
8try:
9    from Products.zdb import set_trace
10except:
11    def set_trace():
12        pass
13pr = context.portal_registration
14request = context.REQUEST
15returning = context.returning_import
16results = context.results_import
17scatalog = context.students_catalog
18
19mtool = context.portal_membership
20member = mtool.getAuthenticatedMember()
21member_id = str(member)
22
23if mtool.isAnonymousUser():
24    return None
25info = {}
26requested_id = context.getStudentId()
27if requested_id and not context.isStaff() and member_id != requested_id:
28    import logging
29    logger = logging.getLogger('Skins.getSessionResults')
30    logger.info('%s tried to access %s' % (member_id,requested_id))
31    return None
32elif context.isStaff():
33    student_id = requested_id
34else:
35    student_id = member_id
36
37students_object = context.portal_url.getPortalObject().campus.students
38##student = getattr(students_object, student_id)
39##clear = getattr(student,'clearance',None)
40##if clear:
41##    value = clear.getContent().matric_no
42##else:
43##    return None
44
45res = scatalog(id = student_id)
46matric_no = res[0].matric_no
47student_from_cat = res[0]
48
49#res = returning(matric_no = matric_no)
50#if res:
51#    student_from_returning = res[0]
52#else:
53#    return None
54
55if matric_no:
56    res = results(matric_no = matric_no)
57    results = res
58else:
59    results = []
60
61
62sem1 = []
63sem2 = []
64with_courses_cat = hasattr(context,'courses_catalog')
65fields = context.results_import.schema()
66gpa = 0
67course_count = 0
68session = None
69
70for r in results:
71    if session is None:
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'] = 'N/A'
90    else:
91        result['title'] = ""
92        result['credits'] = "N/A"
93        result['gpa'] = 'N/A'
94        #result['WEIGHT'] = 'N/A'
95        #result['GRADE'] = 'N/A'
96    if r.Semester == '2':
97        sem2.append(result)
98    else:
99        sem1.append(result)
100if course_count:
101    gpa = float(gpa) / course_count
102    gpa = "%4.2f" % gpa
103
104#set_trace()
105verdict_voc = context.portal_vocabularies.verdicts
106verdict_code = student_from_cat.verdict
107if verdict_code:
108    info['verdict'] = verdict = verdict_voc.get(verdict_code,'N/A').upper()
109else:
110    info['verdict'] = verdict = 'N/A'
111
112if student_from_cat.level:
113    if student_from_cat.sex:
114        info['sex'] = 'F'
115    else:
116        info['sex'] = 'M'
117    if verdict in ('A','B'):
118        info['level'] = int(student_from_cat.level)-100
119    else:
120        info['level'] = int(student_from_cat.level)
121else:
122    info['sex'] = 'N/A'
123    info['level'] = 'N/A'
124
125info['session'] = session
126info['gpa'] = gpa
127info['results'] = (sem1, sem2)
128#info['student_from_returning'] = student_from_returning
129info['student'] = student_from_cat
130info['s_id'] = student_id
131return info
132
Note: See TracBrowser for help on using the repository browser.