Hi all,
I need a function in a web2py-app to define some selection parameters, and
a button to start the download after the selection parameters are verified.
So I started with a controller, defining a form, including a submit button
to launch the download. The way I implemented this is kinda working, but
the form remains in a unusable state: the submit button is in the state
pressed down, with value 'working', while it should return to normal state
(up, unpressed), so the user could make another selection to define a new
download.
There has to be a better pattern to implement this. Any hints?
Controller:
def download():
form = FORM(...,INPUT(_type='submit', _value='Export CSV'))
if form.process().accepted:
details_query = ...
fields = OrderedDict([(db.table1.field1, 'Field 1'),(db.table2.field2,
'Another
Field')])
rows = list([r[f] for f in fields] for r in db(details_query).select(*
fields.keys()))
response.view = 'generic.csv'
filename = 'export.csv'
return dict(filename=filename, csvdata=rows, field_names=[fields[k] for
k in fields])
return dict(form=form)
View (generic.csv):
{{
try:
thefile = filename
except:
thefile = 'export.csv'
pass
import cStringIO
import csv
stream = cStringIO.StringIO()
csv_writer = csv.writer(stream)
csv_writer.writerow(field_names)
for row in csvdata:
csv_writer.writerow(row)
pass
response.headers['Content-Type']='application/vnd.ms-excel'
response.headers['Content-disposition']='attachment; filename=' + thefile
response.write(stream.getvalue(), escape=False)
}}
--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.