source: WAeUP_SRP/trunk/skins/waeup_student/course_result_list.py @ 3781

Last change on this file since 3781 was 3781, checked in by Henrik Bettermann, 16 years ago

course_result_list.py : csv download of course results lists
ti_507_2_resolve.py : new script to reindex the mode index in students_catalog
WAeUPTables.py: enable caching for reindexing the students_catalog, but it's still very slow (therefore ti_507_2_resolve.py)

File size: 2.0 KB
Line 
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"""
12export course_result_list
13"""
14request = context.REQUEST
15setheader = request.RESPONSE.setHeader
16cr = context.course_results
17scat = context.students_catalog
18st_schema = context.students_catalog.schema()
19fields = ("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          )
39res_list = []
40lines = []
41lines.append(','.join(fields))
42format = '"%(' + ')s","%('.join(fields) + ')s"'
43
44res = context.course_results(code=course_id)
45items = [ brain for brain in res]
46
47
48
49for 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')
66setheader('Content-type','text/semicolon-seperated-values')
67setheader('Content-Disposition:', 'attachment; filename="%s.csv"' % course_id)
68setheader('Expires',  'Mon, 26 Jul 1997 05:00:00GMT') # Date in the past
69setheader('Cache-Control', 'no-store, no-cache,must-revalidate') # HTTP/1.1
70setheader('Cache-Control', 'post-check=0,pre-check=0')
71#setheader('Pragma', 'no-cache') # HTTP/1.0
72return '\n'.join(lines)
Note: See TracBrowser for help on using the repository browser.