Created
June 29, 2015 02:13
-
-
Save EliAndrewC/08236994c712e44c4b95 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Current version: | |
def csv_file(func): | |
@wraps(func) | |
def csvout(self, session): | |
cherrypy.response.headers['Content-Type'] = 'application/csv' | |
cherrypy.response.headers['Content-Disposition'] = 'attachment; filename=' + func.__name__ + '.csv' | |
writer = StringIO() | |
func(self, csv.writer(writer), session) | |
return writer.getvalue().encode('utf-8') | |
return csvout | |
# Version that supports query parameters: | |
def csv_file(func): | |
@wraps(func) | |
def csvout(self, session, **params): # <- note that we added **params | |
cherrypy.response.headers['Content-Type'] = 'application/csv' | |
cherrypy.response.headers['Content-Disposition'] = 'attachment; filename=' + func.__name__ + '.csv' | |
writer = StringIO() | |
func(self, csv.writer(writer), session, **params) # <- and we also added **params here | |
return writer.getvalue().encode('utf-8') | |
return csvout |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment