## Script (Python) "paid_transfer_list"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=student=None
##title=
##
# $Id: hall_allocation_list.py 1273 2007-01-11 18:28:49Z joachim $
"""
export students who paid for the transfer form
"""
request = context.REQUEST
setheader = request.RESPONSE.setHeader
scat = context.students_catalog
fields = ("id",
          "name",
          "matric_no",
          "jamb_reg_no",
          "sex",
          "email",
          "phone",
          "faculty",
          "department",
          "course",
          "level",
          )
res_list = []
lines = []
lines.append(','.join(fields))
format = '"%(' + ')s","%('.join(fields) + ')s"'

payments = context.portal_catalog(portal_type='Payment')

for payment in payments:
    if not payment.id.startswith('transfer'):
        continue
    sid = payment.getPath().split('/')[-3]
    erg = scat(id=sid)
    if not erg:
        continue
    d = context.getFormattedStudentEntry(erg[0])
    lines.append(format % d)

#setheader('Content-type', 'text/x-cvs')
#setheader('Content-type','application/vnd.ms-excel')
setheader('Content-type','text/semicolon-seperated-values')
setheader('Content-Disposition:', 'attachment; filename="transfer_list.csv"')
setheader('Expires',  'Mon, 26 Jul 1997 05:00:00GMT') # Date in the past
setheader('Cache-Control', 'no-store, no-cache,must-revalidate') # HTTP/1.1
setheader('Cache-Control', 'post-check=0,pre-check=0')
setheader('Pragma', 'no-cache') # HTTP/1.0
return '\n'.join(lines)

