| 1 | ##parameters=REQUEST |
|---|
| 2 | # $Id: display_session_results.py 1867 2007-06-08 09:59:59Z joachim $ |
|---|
| 3 | """ |
|---|
| 4 | process the Application Form |
|---|
| 5 | return html renderer + psm |
|---|
| 6 | """ |
|---|
| 7 | import DateTime |
|---|
| 8 | current = DateTime.DateTime() |
|---|
| 9 | pr = context.portal_registration |
|---|
| 10 | |
|---|
| 11 | validate = REQUEST.has_key("cpsdocument_create_button") |
|---|
| 12 | |
|---|
| 13 | lt = context.portal_layouts |
|---|
| 14 | #pr = context.portal_registration |
|---|
| 15 | |
|---|
| 16 | res,psm,ds = lt.renderLayout('student_session_results_search', |
|---|
| 17 | 'student_returning', |
|---|
| 18 | context, |
|---|
| 19 | mapping=validate and REQUEST, |
|---|
| 20 | layout_mode='create', |
|---|
| 21 | ob = {}, |
|---|
| 22 | commit=False, |
|---|
| 23 | formaction = "display_session_results", |
|---|
| 24 | button = "Search", |
|---|
| 25 | ) |
|---|
| 26 | if psm == 'invalid': |
|---|
| 27 | return context.display_session_results_form(rendered = res, |
|---|
| 28 | psm = "Please correct your input!", |
|---|
| 29 | #psm = "%s, %s" % (psm,ds), |
|---|
| 30 | firstlayout = True, |
|---|
| 31 | lastlayout = True, |
|---|
| 32 | ds = ds, |
|---|
| 33 | ) |
|---|
| 34 | elif psm == '': |
|---|
| 35 | return context.display_session_results_form(rendered = res, |
|---|
| 36 | psm = None, |
|---|
| 37 | firstlayout = True, |
|---|
| 38 | lastlayout = True, |
|---|
| 39 | ds = ds, |
|---|
| 40 | ) |
|---|
| 41 | elif psm == 'valid': |
|---|
| 42 | pass |
|---|
| 43 | s_fields = context.returning_import.schema() |
|---|
| 44 | student_rec = ds.get('student') |
|---|
| 45 | student = {} |
|---|
| 46 | for field in s_fields: |
|---|
| 47 | student[field] = getattr(student_rec,field) |
|---|
| 48 | brains = ds.get('results') |
|---|
| 49 | sem1 = [] |
|---|
| 50 | sem2 = [] |
|---|
| 51 | with_courses_cat = hasattr(context,'courses_catalog') |
|---|
| 52 | |
|---|
| 53 | fields = context.results_import.schema() |
|---|
| 54 | verdict = None |
|---|
| 55 | session = None |
|---|
| 56 | for r in brains: |
|---|
| 57 | if verdict is None: |
|---|
| 58 | verdict = r.Verdict |
|---|
| 59 | session = r.Session |
|---|
| 60 | result = {} |
|---|
| 61 | for field in fields: |
|---|
| 62 | result[field] = getattr(r,field) |
|---|
| 63 | if with_courses_cat: |
|---|
| 64 | res = context.courses_catalog(code = r.CosCode) |
|---|
| 65 | if r.CosCode == 'N/A': |
|---|
| 66 | result['title'] = 'N/A' |
|---|
| 67 | elif with_courses_cat and res: |
|---|
| 68 | result['title'] = res[0].title |
|---|
| 69 | else: |
|---|
| 70 | result['title'] = "To Be Determined" |
|---|
| 71 | if r.Semester == '2': |
|---|
| 72 | sem2.append(result) |
|---|
| 73 | else: |
|---|
| 74 | sem1.append(result) |
|---|
| 75 | #from Products.zdb import set_trace;set_trace() |
|---|
| 76 | results = (sem1, sem2) |
|---|
| 77 | student['verdict'] = verdict |
|---|
| 78 | student['session'] = session |
|---|
| 79 | registered = None |
|---|
| 80 | res = context.returning_import(matric_no = student_rec.matric_no) |
|---|
| 81 | if res: |
|---|
| 82 | student_id = res[0].id |
|---|
| 83 | |
|---|
| 84 | #There was one student with empty id in returning_import (BMS0406035) |
|---|
| 85 | student_obj = None |
|---|
| 86 | if student_id: |
|---|
| 87 | student_obj = getattr(context.portal_url.getPortalObject().campus.students,student_id,None) |
|---|
| 88 | else: |
|---|
| 89 | registered = ' ' |
|---|
| 90 | |
|---|
| 91 | if student_obj and hasattr(student_obj,'application'): |
|---|
| 92 | registered = student_id |
|---|
| 93 | else: |
|---|
| 94 | registered = "no_student_object" |
|---|
| 95 | return context.session_results_anon_view(student=student, |
|---|
| 96 | results=results, |
|---|
| 97 | name = "%(Firstname)s %(Middlename)s %(Lastname)s" % student_rec, |
|---|
| 98 | registered = registered) |
|---|
| 99 | |
|---|