aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Lenc <mattl@incuna.com>2014-09-01 16:45:13 +0100
committerMatt Lenc <mattl@incuna.com>2014-09-01 16:45:13 +0100
commit80dd46d41a389ba4a166d5414034de27ad7e53da (patch)
tree5e4278a60ed30cd779960376de1b6472a4b6035f
parent9cd1fa73837e8c48bc65d24151c3f6bafcd978b4 (diff)
parent843f95258563ac75eabb4a79fef216011f320a0a (diff)
downloaddjango-wkhtmltopdf-80dd46d41a389ba4a166d5414034de27ad7e53da.tar.gz
django-wkhtmltopdf-80dd46d41a389ba4a166d5414034de27ad7e53da.tar.bz2
django-wkhtmltopdf-80dd46d41a389ba4a166d5414034de27ad7e53da.zip
Merge branch 'master' of github.com:incuna/django-wkhtmltopdf
-rw-r--r--.travis.yml12
-rw-r--r--README.rst2
-rw-r--r--wkhtmltopdf/tests/tests.py46
-rw-r--r--wkhtmltopdf/views.py4
4 files changed, 47 insertions, 17 deletions
diff --git a/.travis.yml b/.travis.yml
index 3f3dacc..698a5ed 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -19,12 +19,12 @@ before_install:
- "echo '## Installing dependencies'"
- "sudo apt-get update"
- "sudo apt-get install -y openssl build-essential xorg libssl-dev"
- - "echo '## Downloading wkhtmltopdf 0.12.0'"
- - "wget http://downloads.sourceforge.net/project/wkhtmltopdf/0.12.0/wkhtmltox-linux-amd64_0.12.0-03c001d.tar.xz"
- - "mkdir -p $PWD"
- - "echo '## Extracting wkhtmltox into $PWD'"
- - "tar xvJf wkhtmltox-linux-amd64_0.12.0-03c001d.tar.xz -C $PWD"
- - "export WKHTMLTOPDF_CMD=$PWD/wkhtmltox/bin/wkhtmltopdf"
+ - "echo '## Downloading wkhtmltopdf 0.12.1'"
+ - "wget http://freefr.dl.sourceforge.net/project/wkhtmltopdf/0.12.1/wkhtmltox-0.12.1_linux-precise-amd64.deb"
+ - "echo '## Installing wkhtmltox'"
+ - "sudo dpkg -i wkhtmltox-0.12.1_linux-precise-amd64.deb"
+ - WHICH_WK=`which wkhtmltopdf`
+ - "export WKHTMLTOPDF_CMD=$WHICH_WK"
install:
- pip install $DJANGO
- pip install -r test_requirements.txt
diff --git a/README.rst b/README.rst
index 6585a38..a8b3edb 100644
--- a/README.rst
+++ b/README.rst
@@ -5,7 +5,7 @@ django-wkhtmltopdf
:target: http://badge.fury.io/py/django-wkhtmltopdf
:alt: Latest version
-.. image:: https://travis-ci.org/incuna/django-wkhtmltopdf.png
+.. image:: https://travis-ci.org/incuna/django-wkhtmltopdf.png?branch=master
:target: https://travis-ci.org/incuna/django-wkhtmltopdf
:alt: Travis-CI
diff --git a/wkhtmltopdf/tests/tests.py b/wkhtmltopdf/tests/tests.py
index f296c8e..48a8b19 100644
--- a/wkhtmltopdf/tests/tests.py
+++ b/wkhtmltopdf/tests/tests.py
@@ -17,6 +17,18 @@ from wkhtmltopdf.utils import (_options_to_args, make_absolute_paths,
from wkhtmltopdf.views import PDFResponse, PDFTemplateView, PDFTemplateResponse
+class UnicodeContentPDFTemplateView(PDFTemplateView):
+ """
+ PDFTemplateView with the addition of unicode content in his context.
+
+ Used in unicode content view testing.
+ """
+ def get_context_data(self, **kwargs):
+ Base = super(UnicodeContentPDFTemplateView, self)
+ context = Base.get_context_data(**kwargs)
+ context['title'] = u'♥'
+ return context
+
class TestUtils(TestCase):
def setUp(self):
# Clear standard error
@@ -38,7 +50,9 @@ class TestUtils(TestCase):
def test_wkhtmltopdf(self):
"""Should run wkhtmltopdf to generate a PDF"""
title = 'A test template.'
- response = PDFTemplateResponse(self.factory.get('/'), None, context={'title': title})
+ response = PDFTemplateResponse(self.factory.get('/'),
+ None,
+ context={'title': title})
temp_file = response.render_to_temporary_file('sample.html')
try:
# Standard call
@@ -59,10 +73,25 @@ class TestUtils(TestCase):
finally:
temp_file.close()
+ def test_wkhtmltopdf_with_unicode_content(self):
+ """A wkhtmltopdf call should render unicode content properly"""
+ title = u'♥'
+ response = PDFTemplateResponse(self.factory.get('/'),
+ None,
+ context={'title': title})
+ temp_file = response.render_to_temporary_file('unicode.html')
+ try:
+ pdf_output = wkhtmltopdf(pages=[temp_file.name])
+ self.assertTrue(pdf_output.startswith(b'%PDF'), pdf_output)
+ finally:
+ temp_file.close()
+
def test_PDFTemplateResponse_render_to_temporary_file(self):
"""Should render a template to a temporary file."""
title = 'A test template.'
- response = PDFTemplateResponse(self.factory.get('/'), None, context={'title': title})
+ response = PDFTemplateResponse(self.factory.get('/'),
+ None,
+ context={'title': title})
temp_file = response.render_to_temporary_file('sample.html')
temp_file.seek(0)
saved_content = smart_str(temp_file.read())
@@ -78,7 +107,7 @@ class TestViews(TestCase):
inline_fileheader = 'inline; filename="{0}"'
def test_pdf_response(self):
- """Should generate the correct HttpResponse object and content type."""
+ """Should generate correct HttpResponse object and content type."""
# 404
response = PDFResponse(content='', status=404)
self.assertEqual(response.status_code, 404)
@@ -233,11 +262,12 @@ class TestViews(TestCase):
self.test_pdf_template_view(show_content=True)
def test_pdf_template_view_unicode(self, show_content=False):
- """Test PDFTemplateView."""
-
- view = PDFTemplateView.as_view(filename=self.pdf_filename,
- show_content_in_browser=show_content,
- template_name=self.template)
+ """Test PDFTemplateView with unicode content."""
+ view = UnicodeContentPDFTemplateView.as_view(
+ filename=self.pdf_filename,
+ show_content_in_browser=show_content,
+ template_name=self.template
+ )
# As PDF
request = RequestFactory().get('/')
diff --git a/wkhtmltopdf/views.py b/wkhtmltopdf/views.py
index 2d91224..d5f189a 100644
--- a/wkhtmltopdf/views.py
+++ b/wkhtmltopdf/views.py
@@ -5,8 +5,8 @@ from tempfile import NamedTemporaryFile
from django.conf import settings
from django.http import HttpResponse
from django.template.response import TemplateResponse
-from django.utils.encoding import smart_str
from django.views.generic import TemplateView
+from django.utils.encoding import smart_text
from .utils import (content_disposition_filename, make_absolute_paths,
wkhtmltopdf)
@@ -72,7 +72,7 @@ class PDFTemplateResponse(TemplateResponse, PDFResponse):
context = self.resolve_context(self.context_data)
- content = smart_str(template.render(context))
+ content = smart_text(template.render(context))
content = make_absolute_paths(content)
try: