Created
October 15, 2009 18:08
-
-
Save joshourisman/211149 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
from django.http import HttpResponse | |
from piston.resource import Resource | |
class FileResource(Resource): | |
def __init__(self, handler, authentication=None, filename=None): | |
if filename: | |
self.filename = filename | |
else: | |
self.filename = "export.txt" | |
super(FileResource, self).__init__(handler, authentication=authentication) | |
def __call__(self, request, *args, **kwargs): | |
response = super(FileResource, self).__call__(request, *args, **kwargs) | |
if isinstance(response, HttpResponse): | |
response['Content-Disposition'] = 'attachment; filename=%s' % self.filename | |
return response |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment