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 | """ |
---|
12 | export hall_allocation_list |
---|
13 | """ |
---|
14 | request = context.REQUEST |
---|
15 | setheader = request.RESPONSE.setHeader |
---|
16 | pa = context.portal_accommodation |
---|
17 | scat = context.students_catalog |
---|
18 | st_schema = context.students_catalog.schema() |
---|
19 | #fields = list(st_schema) + ["bed",] |
---|
20 | fields = ("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 | ) |
---|
36 | res_list = [] |
---|
37 | lines = [] |
---|
38 | lines.append(','.join(fields)) |
---|
39 | format = '"%(' + ')s","%('.join(fields) + ')s"' |
---|
40 | hallid=context.getId() |
---|
41 | booked = pa(hall=hallid) |
---|
42 | if not booked: |
---|
43 | hallid = 'all_halls' |
---|
44 | booked = pa() |
---|
45 | for 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') |
---|
60 | setheader('Content-type','text/semicolon-seperated-values') |
---|
61 | setheader('Content-Disposition:', 'attachment; filename="%s.csv"' % hallid) |
---|
62 | setheader('Expires', 'Mon, 26 Jul 1997 05:00:00GMT') # Date in the past |
---|
63 | setheader('Cache-Control', 'no-store, no-cache,must-revalidate') # HTTP/1.1 |
---|
64 | setheader('Cache-Control', 'post-check=0,pre-check=0') |
---|
65 | #setheader('Pragma', 'no-cache') # HTTP/1.0 |
---|
66 | return '\n'.join(lines) |
---|