##parameters=REQUEST # $Id: display_session_results.py 1796 2007-05-18 10:52:31Z henrik $ """ process the Application Form return html renderer + psm """ import DateTime current = DateTime.DateTime() pr = context.portal_registration validate = REQUEST.has_key("cpsdocument_create_button") lt = context.portal_layouts #pr = context.portal_registration res,psm,ds = lt.renderLayout(layout_id= 'student_session_results_search', schema_id= 'student_returning', context=context, mapping=validate and REQUEST, ob={}, layout_mode='create', formaction = "display_session_results", button = "Search", commit=False, ) if psm == 'invalid': return context.display_session_results_form(rendered = res, psm = "Please correct your input!", #psm = "%s, %s" % (psm,ds), firstlayout = True, lastlayout = True, ds = ds, ) elif psm == '': return context.display_session_results_form(rendered = res, psm = None, firstlayout = True, lastlayout = True, ds = ds, ) elif psm == 'valid': pass s_fields = context.returning_import.schema() student_rec = ds.get('student') student = {} for field in s_fields: student[field] = getattr(student_rec,field) brains = ds.get('results') sem1 = [] sem2 = [] with_courses_cat = hasattr(context,'courses_catalog') fields = context.results_import.schema() verdict = None session = None for r in brains: if verdict is None: verdict = r.Verdict session = r.Session result = {} for field in fields: result[field] = getattr(r,field) if with_courses_cat: res = context.courses_catalog(code = r.CosCode) if r.CosCode == 'N/A': result['title'] = 'N/A' elif with_courses_cat and res: result['title'] = res[0].title else: result['title'] = "To Be Determined" if r.Semester == '2': sem2.append(result) else: sem1.append(result) #from Products.zdb import set_trace;set_trace() results = (sem1, sem2) student['verdict'] = verdict student['session'] = session registered = None res = context.returning_import(matric_no = student_rec.matric_no) if res: student_id = res[0].id #There was one student with empty id in returning_import (BMS0406035) student_obj = None if student_id: student_obj = getattr(context.portal_url.getPortalObject().campus.students,student_id,None) else: registered = ' ' if student_obj and hasattr(student_obj,'application'): registered = student_id else: registered = "no_student_object" return context.session_results_anon_view(student=student, results=results, name = "%(Firstname)s %(Middlename)s %(Lastname)s" % student_rec, registered = registered)