diff options
author | Filipp Lepalaan <filipp@mac.com> | 2015-11-25 23:02:15 +0200 |
---|---|---|
committer | Filipp Lepalaan <filipp@mac.com> | 2015-11-25 23:02:15 +0200 |
commit | 33eeb885ffd45e9c83ab1b003d6300623832371d (patch) | |
tree | 37a335da92120a88861e000dbe057ee01ff5aeb7 /servo/lib | |
parent | 69c5f610ad1a9379e7d1237ee95e17a1da02f35d (diff) | |
download | Servo-33eeb885ffd45e9c83ab1b003d6300623832371d.tar.gz Servo-33eeb885ffd45e9c83ab1b003d6300623832371d.tar.bz2 Servo-33eeb885ffd45e9c83ab1b003d6300623832371d.zip |
Added some CSV shortcuts
Diffstat (limited to 'servo/lib')
-rw-r--r-- | servo/lib/utils.py | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/servo/lib/utils.py b/servo/lib/utils.py index 77c39a3..fa7c37c 100644 --- a/servo/lib/utils.py +++ b/servo/lib/utils.py @@ -23,12 +23,23 @@ def paginate(queryset, page, count=10): return results +def text_response(data): + return HttpResponse(data, content_type="text/plain; charset=utf-8") + def csv_response(data): """ Shortcut for sending a CSV response """ return HttpResponse(data, content_type='text/csv') +def send_csv(data, filename): + """ + Shortcut for sending CSV data as a file + """ + response = text_response(data) + response['Content-Disposition'] = 'attachment; filename="%s.txt"' % filename + return response + def json_response(data): """ Shortcut for sending a JSON response |