aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGeorge Hickman <george@ghickman.co.uk>2012-05-21 15:52:38 +0100
committerGeorge Hickman <george@ghickman.co.uk>2012-05-21 15:52:38 +0100
commita9e1c24ea0f810863c4d611148c41a24afe4ec62 (patch)
treec9acfbd4b8cc6df206226f2c0f2eedb43cf5d11f
parent2ef7f402eea33c79eddb3e5d5a9c0d27e2991f92 (diff)
downloaddjango-wkhtmltopdf-a9e1c24ea0f810863c4d611148c41a24afe4ec62.tar.gz
django-wkhtmltopdf-a9e1c24ea0f810863c4d611148c41a24afe4ec62.tar.bz2
django-wkhtmltopdf-a9e1c24ea0f810863c4d611148c41a24afe4ec62.zip
Only set 'Content-Disposition' header if filename is set
Setting 'Content-Disposition' explicitly sets the PDF as an attachment causing browsers to download the PDF. However newer browsers, like Chrome, will display the PDF without this header. So assume the dev wants this to be force download if they set the filename.
-rw-r--r--wkhtmltopdf/views.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/wkhtmltopdf/views.py b/wkhtmltopdf/views.py
index cf141ee..36efaf5 100644
--- a/wkhtmltopdf/views.py
+++ b/wkhtmltopdf/views.py
@@ -11,9 +11,11 @@ from wkhtmltopdf.utils import template_to_temp_file, wkhtmltopdf
class PDFResponse(HttpResponse):
- def __init__(self, content, filename):
+ def __init__(self, content, **kwargs):
super(PDFResponse, self).__init__(content, 'application/pdf')
- self.__setitem__('Content-Disposition', 'attachment; filename=%s' % filename)
+ if 'filename' in kwargs:
+ header_content = 'attachment; filename={0}'.format(kwargs.get('filename'))
+ self.__setitem__('Content-Disposition', header_content)
class PdfResponse(PDFResponse):