[5163] | 1 | # $Id: payment_export.py 5163 2010-04-21 04:38:00Z henrik $ |
---|
| 2 | """ |
---|
| 3 | export students who paid for the transfer form |
---|
| 4 | """ |
---|
| 5 | |
---|
| 6 | try: |
---|
| 7 | from Products.zdb import set_trace |
---|
| 8 | except: |
---|
| 9 | def set_trace(): |
---|
| 10 | pass |
---|
| 11 | |
---|
| 12 | from Products.AdvancedQuery import Eq, Between, Le,In |
---|
| 13 | request = context.REQUEST |
---|
| 14 | setheader = request.RESPONSE.setHeader |
---|
| 15 | scat = context.students_catalog |
---|
| 16 | fields = ("id", |
---|
| 17 | "name", |
---|
| 18 | "matric_no", |
---|
| 19 | "jamb_reg_no", |
---|
| 20 | # "sex", |
---|
| 21 | "email", |
---|
| 22 | # "phone", |
---|
| 23 | # "faculty", |
---|
| 24 | # "department", |
---|
| 25 | "course", |
---|
| 26 | "level", |
---|
| 27 | "session", |
---|
| 28 | "review_state", |
---|
| 29 | "entry_session", |
---|
| 30 | "payment_id", |
---|
| 31 | "payment_title", |
---|
| 32 | "indexdata", |
---|
| 33 | ) |
---|
| 34 | res_list = [] |
---|
| 35 | lines = [] |
---|
| 36 | lines.append(','.join(fields)) |
---|
| 37 | format = '"%(' + ')s","%('.join(fields) + ')s"' |
---|
| 38 | |
---|
| 39 | portal = context.portal_catalog_real |
---|
| 40 | aq_portal = context.portal_catalog_real.evalAdvancedQuery |
---|
| 41 | payments = aq_portal(Eq('portal_type','Payment') & Eq("review_state","closed")) |
---|
| 42 | |
---|
| 43 | #payments = context.portal_catalog(portal_type='Payment') |
---|
| 44 | |
---|
| 45 | #return len(payments) |
---|
| 46 | |
---|
| 47 | for payment in payments: |
---|
| 48 | #if not payment.id.startswith('transfer'): |
---|
| 49 | # continue |
---|
| 50 | sid = payment.getPath().split('/')[-3] |
---|
| 51 | if not sid: |
---|
| 52 | continue |
---|
| 53 | erg = scat(id=sid) |
---|
| 54 | if not erg: |
---|
| 55 | continue |
---|
| 56 | d = context.getFormattedStudentEntry(erg[0]) |
---|
| 57 | indexdata = portal.getIndexDataForRID(payment.getRID()) |
---|
| 58 | d['payment_id'] = payment.id |
---|
| 59 | d['payment_title'] = payment.title |
---|
| 60 | d['indexdata'] = indexdata['SearchableText'] |
---|
| 61 | lines.append(format % d) |
---|
| 62 | |
---|
| 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="transfer_list.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) |
---|
| 72 | |
---|