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