I would appreciate help to get csv-download to work please.
The following in my controller:
def search_filled_in_forms():
sp = request.vars.sp
form_id = request.vars.form_id.lower()
title = request.vars.title.lower()
date = request.vars.date
query = (db.evaluation_form.service_provider == sp) &\
(db.evaluation_form.form_id.lower() == form_id) &\
(db.evaluation_form.title_of_training.lower() == title) &\
(db.evaluation_form.date == date)
rows = db(query).select(db.evaluation_form.ALL)
return dict(rows=rows)
def evaluation_data():
title = 'Evaluation data'
form = SQLFORM.factory(
Field('sp', label='Service Provider',
requires = IS_IN_DB(db,db.service_provider.id, '%(name)s')),
Field('form_id', requires = IS_IN_DB(db,db.evaluation_form.form_id)),
Field('title',label='Title of workshop/training',
requires = IS_IN_DB(db,db.evaluation_form.title_of_training)),
Field('date','date',requires = IS_DATE(format=T('%Y-%m-%d'),
error_message=T('must
be YYYY-MM-DD!'))))
if form.accepts(request.vars, session):
redirect(URL(r=request, f='search_filled_in_forms',vars=request.vars))
elif form.errors:
response.flash = 'form has errors'
else:
pass
return dict(form=form,title=title)
and the following views:
evaluation_data.html:
{extend 'layout.html'}}
<h2 align="center">
{{=title}}
</h2>
<div class="ez-box" align="center">
{{=BEAUTIFY(form)}}
</div>f
evaluation_data.csv:
{{
import cStringIO
stream=cStringIO.StringIO()
rows.export_to_csv_file(stream)
response.headers['Content-Type']='application/vnd.ms-excel'
response.write(stream.getvalue(), escape=False)
}}
and lastly
search_filled_in_forms.html:
{{extend 'layout.html'}}
<h1 align='center'>Evaluation forms </h1>
{{=BEAUTIFY(rows)}}
<a href="evaluation_data.csv">Download as csv-file</a>
But in this case evaluation_data.csv does receive "rows". And I am
not sure how to build the url in the line above.
Regards
Johann
--
"Finally, brethren, whatsoever things are true, whatsoever things are
honest, whatsoever things are just, whatsoever things are pure,
whatsoever things are lovely, whatsoever things are of good report; if
there be any virtue, and if there be any praise, think on these
things." Philippians 4:8