From 313f7292f84040b2b1bad2686cc901c2da84be22 Mon Sep 17 00:00:00 2001 From: Ray Luo Date: Sun, 7 Oct 2018 01:02:50 -0700 Subject: [PATCH] Create generic.csv --- applications/welcome/views/generic.csv | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 applications/welcome/views/generic.csv diff --git a/applications/welcome/views/generic.csv b/applications/welcome/views/generic.csv new file mode 100644 index 00000000..a76bf0be --- /dev/null +++ b/applications/welcome/views/generic.csv @@ -0,0 +1,17 @@ +{{"""Usage: + + def controller(): + return {"": db().select(db.thing.ALL)} + +And then visit that controller with a .csv extention name +""" +}}{{if len(response._vars)==1:}}{{ +# Not yet find a Python 2/3 compatible StringIO pattern, +# we avoid this solution http://web2py.com/books/default/chapter/29/10/services#CSV +# Here we buffer the entire csv file instead (it is your controller's job to limit the volume anyway), +# based on: http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#CSV-one-Table-at-a-time- + +content = response._vars[next(iter(response._vars))] +response.headers['Content-Type'] = 'application/vnd.ms-excel' +response.write(str(content), escape=False) +}}{{pass}}