1 | ## Script (Python) "course_result_list" |
---|
2 | ##bind container=container |
---|
3 | ##bind context=context |
---|
4 | ##bind namespace= |
---|
5 | ##bind script=script |
---|
6 | ##bind subpath=traverse_subpath |
---|
7 | ##parameters=course_id=None |
---|
8 | ##title= |
---|
9 | ## |
---|
10 | # $Id: course_result_list.py 3136 2008-02-09 18:11:00Z henrik $ |
---|
11 | """ |
---|
12 | export course_result_list |
---|
13 | """ |
---|
14 | request = context.REQUEST |
---|
15 | setheader = request.RESPONSE.setHeader |
---|
16 | cr = context.course_results |
---|
17 | scat = context.students_catalog |
---|
18 | st_schema = context.students_catalog.schema() |
---|
19 | fields = ("id", |
---|
20 | "name", |
---|
21 | "matric_no", |
---|
22 | "jamb_reg_no", |
---|
23 | "sex", |
---|
24 | "email", |
---|
25 | "phone", |
---|
26 | "faculty", |
---|
27 | "department", |
---|
28 | "course", |
---|
29 | "session", |
---|
30 | "level", |
---|
31 | "review_state", |
---|
32 | "course_id", |
---|
33 | "session_id", |
---|
34 | "level_id", |
---|
35 | "credits", |
---|
36 | "score", |
---|
37 | "carry_over", |
---|
38 | ) |
---|
39 | res_list = [] |
---|
40 | lines = [] |
---|
41 | lines.append(','.join(fields)) |
---|
42 | format = '"%(' + ')s","%('.join(fields) + ')s"' |
---|
43 | |
---|
44 | res = context.course_results(code=course_id) |
---|
45 | items = [ brain for brain in res] |
---|
46 | |
---|
47 | |
---|
48 | |
---|
49 | for r in items: |
---|
50 | student_record = context.students_catalog.getRecordByKey(r.student_id) |
---|
51 | line = context.getFormattedStudentEntry(student_record) |
---|
52 | if r['carry_over']: |
---|
53 | line['carry_over'] = 'CO' |
---|
54 | else: |
---|
55 | line['carry_over'] = '' |
---|
56 | line['credits'] = r['credits'] |
---|
57 | line['session_id'] = r['session_id'] |
---|
58 | line['level_id'] = level_id = r['level_id'] |
---|
59 | line['score'] = r['score'] |
---|
60 | line['course_id'] = r['code'] |
---|
61 | lines.append(format % line) |
---|
62 | |
---|
63 | |
---|
64 | #setheader('Content-type', 'text/x-cvs') |
---|
65 | #setheader('Content-type','application/vnd.ms-excel') |
---|
66 | setheader('Content-type','text/semicolon-seperated-values') |
---|
67 | setheader('Content-Disposition:', 'attachment; filename="%s.csv"' % course_id) |
---|
68 | setheader('Expires', 'Mon, 26 Jul 1997 05:00:00GMT') # Date in the past |
---|
69 | setheader('Cache-Control', 'no-store, no-cache,must-revalidate') # HTTP/1.1 |
---|
70 | setheader('Cache-Control', 'post-check=0,pre-check=0') |
---|
71 | #setheader('Pragma', 'no-cache') # HTTP/1.0 |
---|
72 | return '\n'.join(lines) |
---|