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 | |
---|
17 | mtool = context.portal_membership |
---|
18 | if mtool.isAnonymousUser(): |
---|
19 | return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url()) |
---|
20 | member = mtool.getAuthenticatedMember() |
---|
21 | member_id = str(member) |
---|
22 | students_folder = context.portal_url.getPortalObject().campus.students |
---|
23 | |
---|
24 | if not students_folder.isSectionOfficer(): |
---|
25 | logger.info('%s tried to access %s' % (member_id,requested_id)) |
---|
26 | return 'Not allowed' |
---|
27 | |
---|
28 | |
---|
29 | |
---|
30 | cr = context.course_results |
---|
31 | scat = context.students_catalog |
---|
32 | st_schema = context.students_catalog.schema() |
---|
33 | fields = ("id", |
---|
34 | "name", |
---|
35 | "matric_no", |
---|
36 | "jamb_reg_no", |
---|
37 | "sex", |
---|
38 | "email", |
---|
39 | "phone", |
---|
40 | "faculty", |
---|
41 | "department", |
---|
42 | "course", |
---|
43 | "session", |
---|
44 | "level", |
---|
45 | "review_state", |
---|
46 | "course_id", |
---|
47 | "session_id", |
---|
48 | "level_id", |
---|
49 | "credits", |
---|
50 | "score", |
---|
51 | "carry_over", |
---|
52 | ) |
---|
53 | res_list = [] |
---|
54 | lines = [] |
---|
55 | lines.append(','.join(fields)) |
---|
56 | format = '"%(' + ')s","%('.join(fields) + ')s"' |
---|
57 | |
---|
58 | res = context.course_results(code=course_id) |
---|
59 | items = [ brain for brain in res] |
---|
60 | |
---|
61 | |
---|
62 | |
---|
63 | for r in items: |
---|
64 | student_record = context.students_catalog.getRecordByKey(r.student_id) |
---|
65 | line = context.getFormattedStudentEntry(student_record) |
---|
66 | if r['carry_over']: |
---|
67 | line['carry_over'] = 'CO' |
---|
68 | else: |
---|
69 | line['carry_over'] = '' |
---|
70 | line['credits'] = r['credits'] |
---|
71 | line['session_id'] = r['session_id'] |
---|
72 | line['level_id'] = level_id = r['level_id'] |
---|
73 | line['score'] = r['score'] |
---|
74 | line['course_id'] = r['code'] |
---|
75 | lines.append(format % line) |
---|
76 | |
---|
77 | |
---|
78 | #setheader('Content-type', 'text/x-cvs') |
---|
79 | #setheader('Content-type','application/vnd.ms-excel') |
---|
80 | setheader('Content-type','text/semicolon-seperated-values') |
---|
81 | setheader('Content-Disposition:', 'attachment; filename="%s.csv"' % course_id) |
---|
82 | setheader('Expires', 'Mon, 26 Jul 1997 05:00:00GMT') # Date in the past |
---|
83 | setheader('Cache-Control', 'no-store, no-cache,must-revalidate') # HTTP/1.1 |
---|
84 | setheader('Cache-Control', 'post-check=0,pre-check=0') |
---|
85 | #setheader('Pragma', 'no-cache') # HTTP/1.0 |
---|
86 | return '\n'.join(lines) |
---|