diff options
author | Zachary Sloan | 2012-10-12 17:29:54 -0500 |
---|---|---|
committer | Zachary Sloan | 2012-10-12 17:29:54 -0500 |
commit | d78728ce6c5290be5905066e674679d5997f2dcc (patch) | |
tree | 04aeab2dcba0384f524c00d097d95794e96649e8 /wqflask | |
parent | 5d8b5c7481429267b418bc27a41dcf58701e1959 (diff) | |
download | genenetwork2-d78728ce6c5290be5905066e674679d5997f2dcc.tar.gz |
Changed export code to use csv module
Diffstat (limited to 'wqflask')
-rw-r--r-- | wqflask/wqflask/views.py | 34 |
1 files changed, 16 insertions, 18 deletions
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',)) |