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

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

more beds for futminna

moree security for course_result_list

File size: 2.4 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
16
17mtool = context.portal_membership
18if mtool.isAnonymousUser():
19    return request.RESPONSE.redirect("%s/srp_anonymous_view" % context.portal_url())
20member = mtool.getAuthenticatedMember()
21member_id = str(member)
22students_folder = context.portal_url.getPortalObject().campus.students
23
24if not students_folder.isSectionOfficer():
25    logger.info('%s tried to access %s' % (member_id,requested_id))
26    return 'Not allowed'
27
28
29
30cr = context.course_results
31scat = context.students_catalog
32st_schema = context.students_catalog.schema()
33fields = ("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          )
53res_list = []
54lines = []
55lines.append(','.join(fields))
56format = '"%(' + ')s","%('.join(fields) + ')s"'
57
58res = context.course_results(code=course_id)
59items = [ brain for brain in res]
60
61
62
63for 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')
80setheader('Content-type','text/semicolon-seperated-values')
81setheader('Content-Disposition:', 'attachment; filename="%s.csv"' % course_id)
82setheader('Expires',  'Mon, 26 Jul 1997 05:00:00GMT') # Date in the past
83setheader('Cache-Control', 'no-store, no-cache,must-revalidate') # HTTP/1.1
84setheader('Cache-Control', 'post-check=0,pre-check=0')
85#setheader('Pragma', 'no-cache') # HTTP/1.0
86return '\n'.join(lines)
Note: See TracBrowser for help on using the repository browser.