## Script (Python) "course_result_list" ##bind container=container ##bind context=context ##bind namespace= ##bind script=script ##bind subpath=traverse_subpath ##parameters=course_id=None ##title= ## # $Id: course_result_list.py 3136 2008-02-09 18:11:00Z henrik $ """ export course_result_list """ request = context.REQUEST setheader = request.RESPONSE.setHeader mtool = context.portal_membership if mtool.isAnonymousUser(): return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) member = mtool.getAuthenticatedMember() member_id = str(member) students_folder = context.portal_url.getPortalObject().campus.students if not students_folder.isSectionOfficer(): logger.info('%s tried to access %s' % (member_id,requested_id)) return 'Not allowed' cr = context.course_results scat = context.students_catalog st_schema = context.students_catalog.schema() fields = ("id", "name", "matric_no", "jamb_reg_no", "sex", "email", "phone", "faculty", "department", "course", "session", "level", "review_state", "course_id", "session_id", "level_id", "credits", "score", "carry_over", ) res_list = [] lines = [] lines.append(','.join(fields)) format = '"%(' + ')s","%('.join(fields) + ')s"' res = context.course_results(code=course_id) items = [ brain for brain in res] for r in items: student_record = context.students_catalog.getRecordByKey(r.student_id) line = context.getFormattedStudentEntry(student_record) if r['carry_over']: line['carry_over'] = 'CO' else: line['carry_over'] = '' line['credits'] = r['credits'] line['session_id'] = r['session_id'] line['level_id'] = level_id = r['level_id'] line['score'] = r['score'] line['course_id'] = r['code'] lines.append(format % line) #setheader('Content-type', 'text/x-cvs') #setheader('Content-type','application/vnd.ms-excel') setheader('Content-type','text/semicolon-seperated-values') setheader('Content-Disposition:', 'attachment; filename="%s.csv"' % course_id) setheader('Expires', 'Mon, 26 Jul 1997 05:00:00GMT') # Date in the past setheader('Cache-Control', 'no-store, no-cache,must-revalidate') # HTTP/1.1 setheader('Cache-Control', 'post-check=0,pre-check=0') #setheader('Pragma', 'no-cache') # HTTP/1.0 return '\n'.join(lines)