Hello,

I strungle with export of csv... I have this function that works great :

def export_csv(tab1_id):
    import gluon.contenttype
    response.headers['Content-Type'] = \
        gluon.contenttype.contenttype('.csv')
    import cStringIO
    stream=cStringIO.StringIO()
    db((db.tab1.id == tab1_id)).select().export_to_csv_file(stream)
    response.headers['Content-disposition'] = 'attachment; filename=%s.csv' 
% 'test12345'
    response.write(stream.getvalue())

def export_default_analysis_request():
    tab1_subset = (db.tab1.bool1 == True)
    form = SQLFORM.factory(
            Field('tab1_id', 
requires=IS_IN_DB(db(tab1_subset),'tab1.id','%(f1)s')),
                submit_button=T('Submit'))
    if form.accepts(request.vars, session):
        response.flash = T('form accepted')
        export_csv(tab1_id = form.vars.tab1_id)
    elif form.errors:
        response.flash = T('form has errors')
    else:
        response.flash = T('please fill out the form')
    return dict(form=form)

The problem is that I am getting the html page below the value I want to 
export...

Do I need to redirect on a blank page? It likes if response contain the 
actual page that get out at the same time as the data...

I just copy stuff from here and there, but I think I will have to better 
understand what is going on...

Thanks

Richard

Reply via email to