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: list_students.py 1673 2007-04-09 16:01:51Z joachim $ |
---|
11 | """ |
---|
12 | export student_list |
---|
13 | """ |
---|
14 | try: |
---|
15 | from Products.zdb import set_trace |
---|
16 | except: |
---|
17 | def set_trace(): |
---|
18 | pass |
---|
19 | from Products.AdvancedQuery import Eq, Between, Le,In,MatchRegexp |
---|
20 | aq_portal = context.portal_catalog.evalAdvancedQuery |
---|
21 | aq_students = context.students_catalog.evalAdvancedQuery |
---|
22 | request = context.REQUEST |
---|
23 | setheader = request.RESPONSE.setHeader |
---|
24 | pa = context.portal_accommodation |
---|
25 | scat = context.students_catalog |
---|
26 | st_schema = context.students_catalog.schema() |
---|
27 | #fields = list(st_schema) + ["bed",] |
---|
28 | fields = ("id", |
---|
29 | "name", |
---|
30 | "matric_no", |
---|
31 | "jamb_reg_no", |
---|
32 | "sex", |
---|
33 | "email", |
---|
34 | "faculty", |
---|
35 | "department", |
---|
36 | "course", |
---|
37 | "level", |
---|
38 | ) |
---|
39 | res_list = [] |
---|
40 | lines = [] |
---|
41 | lines.append(','.join(fields)) |
---|
42 | format = '"%(' + ')s","%('.join(fields) + ')s"' |
---|
43 | #cleared = context.portal_catalog(review_state = "cleared_and_validated") |
---|
44 | query = In('review_state',('cleared_and_validated', |
---|
45 | 'school_fee_paid', |
---|
46 | 'courses_registered', |
---|
47 | 'courses_validated')) |
---|
48 | cleared = aq_portal(query) |
---|
49 | newquery = Eq('portal_type','StudentApplication') & MatchRegexp('SearchableText',r'^6*') |
---|
50 | #newquery = MatchRegexp('SearchableText','^5*') |
---|
51 | new_students = aq_portal(newquery) |
---|
52 | new_sids = [] |
---|
53 | for ns in new_students: |
---|
54 | new_sids.append(ns.getPath().split('/')[-2]) |
---|
55 | for student in cleared: |
---|
56 | if student.getId not in new_sids: |
---|
57 | continue |
---|
58 | erg = scat(id=student.getId) |
---|
59 | if not erg: |
---|
60 | continue |
---|
61 | d = context.getFormattedStudentEntry(erg[0]) |
---|
62 | lines.append(format % d) |
---|
63 | #setheader('Content-type', 'text/x-cvs') |
---|
64 | #setheader('Content-type','application/vnd.ms-excel') |
---|
65 | setheader('Content-type','text/semicolon-seperated-values') |
---|
66 | setheader('Content-Disposition:', 'attachment; filename="cleared_students.csv"') |
---|
67 | setheader('Expires', 'Mon, 26 Jul 1997 05:00:00GMT') # Date in the past |
---|
68 | setheader('Cache-Control', 'no-store, no-cache,must-revalidate') # HTTP/1.1 |
---|
69 | setheader('Cache-Control', 'post-check=0,pre-check=0') |
---|
70 | setheader('Pragma', 'no-cache') # HTTP/1.0 |
---|
71 | return '\n'.join(lines) |
---|