Skip to content

Commit

Permalink
add spire csvdownload endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Ralph Smith committed Jun 1, 2015
1 parent eaa43f6 commit 5ecfee0
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions spire/wsgi/csvdownload.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os

from werkzeug.exceptions import MethodNotAllowed
from spire.wsgi.util import Mount

class CsvDownloadEndPoint(Mount):

def _dispatch_request(self, request, response):
if request.method == 'GET':
return
elif request.method != 'POST':
raise MethodNotAllowed()

mimetype = request.form.get('mimetype', 'text/csv')
filename = request.form.get('filename', 'data.csv')
data = request.form.get('data', '')
response.headers = {
'content-type': mimetype + '; charset=utf-8',
'content-disposition': 'attachment;filename='+filename
}
response.data = data

0 comments on commit 5ecfee0

Please sign in to comment.