From d78728ce6c5290be5905066e674679d5997f2dcc Mon Sep 17 00:00:00 2001 From: Zachary Sloan Date: Fri, 12 Oct 2012 17:29:54 -0500 Subject: Changed export code to use csv module --- wqflask/wqflask/views.py | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) (limited to 'wqflask') diff --git a/wqflask/wqflask/views.py b/wqflask/wqflask/views.py index 94768c9f..693b863a 100644 --- a/wqflask/wqflask/views.py +++ b/wqflask/wqflask/views.py @@ -1,5 +1,8 @@ from __future__ import absolute_import, division, print_function +import csv +import StringIO # Todo: Use cStringIO? + import simplejson as json import yaml @@ -97,29 +100,24 @@ def export_trait_csv(): print("sample_data - type: %s -- size: %s" % (type(sample_data), len(sample_data))) - def generate(sample_data): - for row in sample_data: - print(','.join(row) + '\n') - yield ','.join(row) + '\n' - - print("generated data:", pf(generate(sample_data))) - - #print(pf(Response(generate(sample_data), - # mimetype='text/plain', - # headers={"Content-Disposition": - # "attachment;filename=test.csv"}))) + buff = StringIO.StringIO() + writer = csv.writer(buff) + for row in sample_data: + writer.writerow(row) + csv_data = buff.getvalue() + buff.close() - return Response(generate(sample_data), + return Response(csv_data, mimetype='text/csv', headers={"Content-Disposition":"attachment;filename=test.csv"}) -@app.route("/export_trait_data", methods=('POST',)) -def export_sample_table(): - """CSV file consisting of the sample data from the trait data and analysis page""" - print("In export_sample_table") - print("request.form:", request.form) - template_vars = export_trait_data.export_sample_table(request.form) +#@app.route("/export_trait_data", methods=('POST',)) +#def export_sample_table(): +# """CSV file consisting of the sample data from the trait data and analysis page""" +# print("In export_sample_table") +# print("request.form:", request.form) +# template_vars = export_trait_data.export_sample_table(request.form) @app.route("/corr_compute", methods=('POST',)) -- cgit v1.2.3