source: WAeUP_SRP/base/skins/waeup_accommodation/hall_allocation_list.py @ 3136

Last change on this file since 3136 was 3136, checked in by Henrik Bettermann, 17 years ago

resolve #469

  • Property svn:keywords set to Id
File size: 1.8 KB
Line 
1## Script (Python) "hall_allocation_list"
2##bind container=container
3##bind context=context
4##bind namespace=
5##bind script=script
6##bind subpath=traverse_subpath
7##parameters=student=None
8##title=
9##
10# $Id: hall_allocation_list.py 3136 2008-02-09 18:11:00Z henrik $
11"""
12export hall_allocation_list
13"""
14request = context.REQUEST
15setheader = request.RESPONSE.setHeader
16pa = context.portal_accommodation
17scat = context.students_catalog
18st_schema = context.students_catalog.schema()
19#fields = list(st_schema) + ["bed",]
20fields = ("id",
21          "name",
22          "hall",
23          "block",
24          "room",
25          "bed",
26          "matric_no",
27          "jamb_reg_no",
28          "sex",
29          "email",
30          "phone",
31          "faculty",
32          "department",
33          "course",
34          "level",
35          )
36res_list = []
37lines = []
38lines.append(','.join(fields))
39format = '"%(' + ')s","%('.join(fields) + ')s"'
40hallid=context.getId()
41booked = pa(hall=hallid)
42if not booked:
43    hallid = 'all_halls'
44    booked = pa()
45for bed in booked:
46    if bed.student == '':
47        continue
48    erg = scat(id=bed.student)
49    if not erg:
50        continue
51    d = context.getFormattedStudentEntry(erg[0])
52    hall,block,room,bed = bed.bed.split('_')
53    d['hall'] = hall
54    d['block'] = block
55    d['room'] = room
56    d['bed'] = bed
57    lines.append(format % d)
58#setheader('Content-type', 'text/x-cvs')
59#setheader('Content-type','application/vnd.ms-excel')
60setheader('Content-type','text/semicolon-seperated-values')
61setheader('Content-Disposition:', 'attachment; filename="%s.csv"' % hallid)
62setheader('Expires',  'Mon, 26 Jul 1997 05:00:00GMT') # Date in the past
63setheader('Cache-Control', 'no-store, no-cache,must-revalidate') # HTTP/1.1
64setheader('Cache-Control', 'post-check=0,pre-check=0')
65#setheader('Pragma', 'no-cache') # HTTP/1.0
66return '\n'.join(lines)
Note: See TracBrowser for help on using the repository browser.