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

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

use verdicts vocabulary (in custom)

File size: 3.1 KB
RevLine 
[1174]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
[1417]10request = context.REQUEST
[1174]11returning = context.returning_import
12results = context.results_import
[1317]13scatalog = context.students_catalog
[1174]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:
[1258]26    import logging
27    logger = logging.getLogger('Student.SessionResults.Info')
[1174]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
[1315]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
[1174]42
[1317]43res = scatalog(id = student_id)
44matric_no = res[0].matric_no
[1448]45student_from_cat = res[0]
[1317]46
47res = returning(matric_no = matric_no)
[1417]48if res:
49    student_from_returning = res[0]
50else:
51    return None
52
[1317]53res = results(matric_no = matric_no)
[1174]54results = res
55
56
57sem1 = []
58sem2 = []
59with_courses_cat = hasattr(context,'courses_catalog')
60fields = context.results_import.schema()
[1179]61gpa = 0
62course_count = 0
[1183]63verdict = None
64session = None
[1465]65verdict_voc = context.portal_vocabularies.verdicts
[1174]66for r in results:
[1183]67    if verdict is None:
[1465]68        verdict = verdict_voc.get(r.Verdict)
[1183]69        session = r.Session
[1174]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
[1179]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:
[1448]86            result['gpa'] = 'N/A'
[1174]87    else:
[1448]88        result['title'] = ""
89        result['credits'] = "N/A"
90        result['gpa'] = 'N/A'
91        result['WEIGHT'] = 'N/A'
92        result['GRADE'] = 'N/A'
[1174]93    if r.Semester == '2':
94        sem2.append(result)
95    else:
96        sem1.append(result)
[1179]97if course_count:
98    gpa = float(gpa) / course_count
99    gpa = "%4.2f" % gpa
[1413]100
[1429]101if student_from_cat.level:
102    if student_from_cat.sex:
103        info['sex'] = 'F'
104    else:
105        info['sex'] = 'M'
106    info['level'] = int(student_from_cat.level)-100
[1448]107else:
108    info['sex'] = 'N/A'
109    info['level'] = 'N/A'
[1429]110
[1183]111info['verdict'] = verdict
112info['session'] = session
[1179]113info['gpa'] = gpa
[1174]114info['results'] = (sem1, sem2)
[1411]115info['student_from_returning'] = student_from_returning
116info['student'] = student_from_cat
[1174]117info['s_id'] = student_id
118return info
[1179]119
Note: See TracBrowser for help on using the repository browser.