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

Last change on this file since 1541 was 1524, checked in by joachim, 18 years ago

don't decrease level if not successfull

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('Student.SessionResults.Info')
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
49res = returning(matric_no = matric_no)
50if res:
51    student_from_returning = res[0]
52else:
53    return None
54
55res = results(matric_no = matric_no)
56results = res
57
58
59sem1 = []
60sem2 = []
61with_courses_cat = hasattr(context,'courses_catalog')
62fields = context.results_import.schema()
63gpa = 0
64course_count = 0
65session = None
66
67for r in results:
68    if session is None:
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'] = 'N/A'
87    else:
88        result['title'] = ""
89        result['credits'] = "N/A"
90        result['gpa'] = 'N/A'
91        result['WEIGHT'] = 'N/A'
92        result['GRADE'] = 'N/A'
93    if r.Semester == '2':
94        sem2.append(result)
95    else:
96        sem1.append(result)
97if course_count:
98    gpa = float(gpa) / course_count
99    gpa = "%4.2f" % gpa
100
101
102verdict_voc = context.portal_vocabularies.verdicts
103if verdict_voc.has_key(student_from_cat.verdict):
104    info['verdict'] = verdict = verdict_voc.get(student_from_cat.verdict).upper()
105else:
106    info['verdict'] = 'N/A'
107
108if student_from_cat.level:
109    if student_from_cat.sex:
110        info['sex'] = 'F'
111    else:
112        info['sex'] = 'M'
113    if verdict in ('A','B'):
114        info['level'] = int(student_from_cat.level)-100
115    else:
116        info['level'] = int(student_from_cat.level)
117else:
118    info['sex'] = 'N/A'
119    info['level'] = 'N/A'
120
121info['session'] = session
122info['gpa'] = gpa
123info['results'] = (sem1, sem2)
124info['student_from_returning'] = student_from_returning
125info['student'] = student_from_cat
126info['s_id'] = student_id
127return info
128
Note: See TracBrowser for help on using the repository browser.