From 1e3dfedfc4778879917970bf125c51947c367f94 Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 11:14:24 +0100 Subject: Add support for Python3 --- wkhtmltopdf/tests/tests.py | 35 ++++++++++++++++++----------------- wkhtmltopdf/utils.py | 21 ++++++++++++++------- wkhtmltopdf/views.py | 17 +++++++++++------ 3 files changed, 43 insertions(+), 30 deletions(-) diff --git a/wkhtmltopdf/tests/tests.py b/wkhtmltopdf/tests/tests.py index b007687..f2d92aa 100644 --- a/wkhtmltopdf/tests/tests.py +++ b/wkhtmltopdf/tests/tests.py @@ -8,6 +8,7 @@ import sys from django.conf import settings from django.test import TestCase from django.test.client import RequestFactory +from django.utils.encoding import smart_str from wkhtmltopdf.subprocess import CalledProcessError from wkhtmltopdf.utils import (_options_to_args, make_absolute_paths, @@ -41,15 +42,15 @@ class TestUtils(TestCase): try: # Standard call pdf_output = wkhtmltopdf(pages=[temp_file.name]) - self.assertTrue(pdf_output.startswith('%PDF'), pdf_output) + self.assertTrue(pdf_output.startswith(b'%PDF'), pdf_output) # Single page pdf_output = wkhtmltopdf(pages=temp_file.name) - self.assertTrue(pdf_output.startswith('%PDF'), pdf_output) + self.assertTrue(pdf_output.startswith(b'%PDF'), pdf_output) # Unicode pdf_output = wkhtmltopdf(pages=[temp_file.name], title=u'♥') - self.assertTrue(pdf_output.startswith('%PDF'), pdf_output) + self.assertTrue(pdf_output.startswith(b'%PDF'), pdf_output) # Invalid arguments self.assertRaises(CalledProcessError, @@ -63,7 +64,7 @@ class TestUtils(TestCase): response = PDFTemplateResponse(self.factory.get('/'), None, context={'title': title}) temp_file = response.render_to_temporary_file('sample.html') temp_file.seek(0) - saved_content = temp_file.read() + saved_content = smart_str(temp_file.read()) self.assertTrue(title in saved_content) temp_file.close() @@ -80,11 +81,11 @@ class TestViews(TestCase): # 404 response = PDFResponse(content='', status=404) self.assertEqual(response.status_code, 404) - self.assertEqual(response.content, '') + self.assertEqual(response.content, b'') self.assertEqual(response['Content-Type'], 'application/pdf') self.assertFalse(response.has_header('Content-Disposition')) - content = '%PDF-1.4\n%%EOF' + content = b'%PDF-1.4\n%%EOF' # Without filename response = PDFResponse(content=content) self.assertEqual(response.status_code, 200) @@ -153,14 +154,14 @@ class TestViews(TestCase): # Render to temporary file tempfile = response.render_to_temporary_file(self.template) tempfile.seek(0) - html_content = tempfile.read() + html_content = smart_str(tempfile.read()) self.assertTrue(html_content.startswith('')) self.assertTrue('

{title}

'.format(**context) in html_content) pdf_content = response.rendered_content - self.assertTrue(pdf_content.startswith('%PDF-')) - self.assertTrue(pdf_content.endswith('%%EOF\n')) + self.assertTrue(pdf_content.startswith(b'%PDF-')) + self.assertTrue(pdf_content.endswith(b'%%EOF\n')) # Footer cmd_options = {'title': 'Test PDF'} @@ -179,7 +180,7 @@ class TestViews(TestCase): tempfile = response.render_to_temporary_file(self.footer_template) tempfile.seek(0) - footer_content = tempfile.read() + footer_content = smart_str(tempfile.read()) footer_content = make_absolute_paths(footer_content) media_url = 'file://{0}/'.format(settings.MEDIA_ROOT) @@ -189,8 +190,8 @@ class TestViews(TestCase): self.assertTrue(static_url in footer_content, True) pdf_content = response.rendered_content - self.assertTrue('\0'.join('{title}'.format(**cmd_options)) - in pdf_content) + self.assertTrue(pdf_content.startswith(b'%PDF-')) + self.assertTrue(pdf_content.endswith(b'%%EOF\n')) def test_pdf_template_response_to_browser(self): self.test_pdf_template_response(show_content=True) @@ -214,8 +215,8 @@ class TestViews(TestCase): fileheader = self.inline_fileheader self.assertEqual(response['Content-Disposition'], fileheader.format(self.pdf_filename)) - self.assertTrue(response.content.startswith('%PDF-')) - self.assertTrue(response.content.endswith('%%EOF\n')) + self.assertTrue(response.content.startswith(b'%PDF-')) + self.assertTrue(response.content.endswith(b'%%EOF\n')) # As HTML request = RequestFactory().get('/?as=html') @@ -223,7 +224,7 @@ class TestViews(TestCase): self.assertEqual(response.status_code, 200) response.render() self.assertFalse(response.has_header('Content-Disposition')) - self.assertTrue(response.content.startswith('')) + self.assertTrue(response.content.startswith(b'')) # POST request = RequestFactory().post('/') @@ -254,8 +255,8 @@ class TestViews(TestCase): # not sure how we can test this as the contents is all encoded... # best we can do for the moment is check it's a pdf and it worked. # self.assertTrue('☃' in response.content) - self.assertTrue(response.content.startswith('%PDF-')) - self.assertTrue(response.content.endswith('%%EOF\n')) + self.assertTrue(response.content.startswith(b'%PDF-')) + self.assertTrue(response.content.endswith(b'%%EOF\n')) def test_pdf_template_view_unicode_to_browser(self): self.test_pdf_template_view_unicode(show_content=True) diff --git a/wkhtmltopdf/utils.py b/wkhtmltopdf/utils.py index 1b74a97..9be8f86 100644 --- a/wkhtmltopdf/utils.py +++ b/wkhtmltopdf/utils.py @@ -5,10 +5,16 @@ from itertools import chain import os import re import sys -import urllib -from urlparse import urljoin + +try: + from urllib import pathname2url + from urlparse import urljoin +except ImportError: # py3k + from urllib.request import pathname2url + from urllib.parse import urljoin from django.conf import settings +from django.utils import six from .subprocess import check_output @@ -22,7 +28,7 @@ def _options_to_args(**options): continue flags.append('--' + name.replace('_', '-')) if value is not True: - flags.append(unicode(value)) + flags.append(six.text_type(value)) return flags @@ -56,7 +62,7 @@ def wkhtmltopdf(pages, output=None, **kwargs): orientation='Landscape', disable_javascript=True) """ - if isinstance(pages, basestring): + if isinstance(pages, six.string_types): # Support a single page. pages = [pages] @@ -113,19 +119,20 @@ def http_quote(string): valid ascii charset string you can use in, say, http headers and the like. """ - if isinstance(string, unicode): + if isinstance(string, six.text_type): try: import unidecode string = unidecode.unidecode(string) except ImportError: string = string.encode('ascii', 'replace') # Wrap in double-quotes for ; , and the like - return '"{0!s}"'.format(string.replace('\\', '\\\\').replace('"', '\\"')) + string = string.replace(b'\\', b'\\\\').replace(b'"', b'\\"') + return '"{0!s}"'.format(string.decode()) def pathname2fileurl(pathname): """Returns a file:// URL for pathname. Handles OS-specific conversions.""" - return urljoin('file:', urllib.pathname2url(pathname)) + return urljoin('file:', pathname2url(pathname)) def make_absolute_paths(content): diff --git a/wkhtmltopdf/views.py b/wkhtmltopdf/views.py index 5a46490..92e2d0f 100644 --- a/wkhtmltopdf/views.py +++ b/wkhtmltopdf/views.py @@ -5,7 +5,6 @@ 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 .utils import (content_disposition_filename, make_absolute_paths, @@ -74,15 +73,21 @@ class PDFTemplateResponse(TemplateResponse, PDFResponse): context = self.resolve_context(self.context_data) - content = smart_str(template.render(context)) + content = template.render(context) content = make_absolute_paths(content) - tempfile = NamedTemporaryFile(mode=mode, bufsize=bufsize, - suffix=suffix, prefix=prefix, - dir=dir, delete=delete) + try: + tempfile = NamedTemporaryFile(mode=mode, bufsize=bufsize, + suffix=suffix, prefix=prefix, + dir=dir, delete=delete) + except TypeError: + # Python 3 has 'buffering' arg for 'NamedTemporaryFile' class + tempfile = NamedTemporaryFile(mode=mode, buffering=bufsize, + suffix=suffix, prefix=prefix, + dir=dir, delete=delete) try: - tempfile.write(content) + tempfile.write(content.encode('utf-8')) tempfile.flush() return tempfile except: -- cgit v1.2.3 From d843e33d973b550bb7b019c80f94034e0080b02a Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 11:14:37 +0100 Subject: Update .travis for Python3 --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index cb3ffca..7ff9d4e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,8 @@ language: python python: - "2.6" - "2.7" + - "3.3" + - "3.4" before_script: - "./before_script.sh" install: -- cgit v1.2.3 From 25cf30db173bdd708f07c33aca33f2f64087f4d5 Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 11:22:39 +0100 Subject: [ci skip] Update README --- README.rst | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 553a5da..b7050ec 100644 --- a/README.rst +++ b/README.rst @@ -8,19 +8,20 @@ django-wkhtmltopdf Converts html to PDF -------------------- -Provides a thin wrapper to the wkhtmltopdf binary from https://github.com/wkhtmltopdf/wkhtmltopdf -Get the wkhtmltopdf binaries from http://wkhtmltopdf.org/ +Provides a thin Django wrapper for the `wkhtmltopdf`_ binary. +.. _wkhtmltopdf: http://wkhtmltopdf.org/ Requirements ------------ Install the `wkhtmltopdf`_ binary. + This requires libfontconfig (on Ubuntu: ``sudo aptitude install libfontconfig``). -.. _wkhtmltopdf: http://wkhtmltopdf.org/ +.. _wkhtmltopdf: http://wkhtmltopdf.org/downloads.html -Python 2.6 +Python 2.6+ through 3.4 is supported. Installation -- cgit v1.2.3 From cc6e1753a4d388e294e14c4c0805052ccd1be381 Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 11:23:57 +0100 Subject: Update test reqs for Django with py3k support In near future we should support moar Djangos (and using Travis for this). --- wkhtmltopdf/tests/test_requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wkhtmltopdf/tests/test_requirements.txt b/wkhtmltopdf/tests/test_requirements.txt index 3999bef..7eedf6c 100644 --- a/wkhtmltopdf/tests/test_requirements.txt +++ b/wkhtmltopdf/tests/test_requirements.txt @@ -1 +1 @@ -Django==1.4.2 +Django==1.4.13 -- cgit v1.2.3 From 39b76d8b55506bcddf40d6e76508dd7de272c988 Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 11:35:49 +0100 Subject: Update setup.py --- LICENSE | 2 +- setup.py | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/LICENSE b/LICENSE index fe36c19..a7d567e 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2012, Incuna Ltd +Copyright (c) 2014, Incuna Ltd All rights reserved. Redistribution and use in source and binary forms, with or without modification, diff --git a/setup.py b/setup.py index abc3591..611ebb9 100644 --- a/setup.py +++ b/setup.py @@ -8,12 +8,26 @@ setup( packages=find_packages(), include_package_data=True, version=wkhtmltopdf.__version__, - description='Converts html to PDF using http://code.google.com/p/wkhtmltopdf/.', + description='Converts HTML to PDF using wkhtmltopdf.', long_description=open('README.rst').read(), + license='MIT', author=wkhtmltopdf.__author__, author_email='admin@incuna.com', url='https://github.com/incuna/django-wkhtmltopdf', - install_requires=['Django>=1.3'], + install_requires=['Django>=1.4'], zip_safe=False, + classifiers=[ + 'Development Status :: 5 - Production/Stable', + 'Intended Audience :: Developers', + 'Topic :: Software Development', + 'Topic :: Utilities', + 'License :: OSI Approved :: MIT License', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.6', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.3', + 'Programming Language :: Python :: 3.4', + ], + keywords='django wkhtmltopdf pdf', ) - -- cgit v1.2.3 From 4e69c491558000282a928fc62fc376ae4e6ae70c Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 11:43:03 +0100 Subject: Tweak classifiers --- setup.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index 611ebb9..876e9ef 100644 --- a/setup.py +++ b/setup.py @@ -14,13 +14,12 @@ setup( author=wkhtmltopdf.__author__, author_email='admin@incuna.com', url='https://github.com/incuna/django-wkhtmltopdf', - install_requires=['Django>=1.4'], zip_safe=False, classifiers=[ 'Development Status :: 5 - Production/Stable', + 'Environment :: Web Environment', 'Intended Audience :: Developers', - 'Topic :: Software Development', - 'Topic :: Utilities', + 'Operating System :: OS Independent', 'License :: OSI Approved :: MIT License', 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 2.6', @@ -28,6 +27,7 @@ setup( 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.3', 'Programming Language :: Python :: 3.4', + 'Framework :: Django', ], keywords='django wkhtmltopdf pdf', ) -- cgit v1.2.3 From 61f7af8399c1ab51a0b2dff06414170947eaa228 Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 11:43:43 +0100 Subject: Support moar Django The future is now ;] --- .travis.yml | 12 +++++++++++- wkhtmltopdf/tests/test_requirements.txt | 1 - 2 files changed, 11 insertions(+), 2 deletions(-) delete mode 100644 wkhtmltopdf/tests/test_requirements.txt diff --git a/.travis.yml b/.travis.yml index 7ff9d4e..d6bb5c4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,10 +4,20 @@ python: - "2.7" - "3.3" - "3.4" +env: + - DJANGO==1.4.13 + - DJANGO==1.5.8 + - DJANGO==1.6.5 +matrix: + exclude: + - python: 3.3 + env: DJANGO==1.4.13 + - python: 3.4 + env: DJANGO==1.4.13 before_script: - "./before_script.sh" install: - - pip install -r wkhtmltopdf/tests/test_requirements.txt + - pip install $DJANGO - pip install . script: - make test diff --git a/wkhtmltopdf/tests/test_requirements.txt b/wkhtmltopdf/tests/test_requirements.txt deleted file mode 100644 index 7eedf6c..0000000 --- a/wkhtmltopdf/tests/test_requirements.txt +++ /dev/null @@ -1 +0,0 @@ -Django==1.4.13 -- cgit v1.2.3 From fae7dc96b6bd9d174d38505b8870e38311198c12 Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 11:46:22 +0100 Subject: Fix env for travis --- .travis.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index d6bb5c4..8c1a717 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,15 +5,15 @@ python: - "3.3" - "3.4" env: - - DJANGO==1.4.13 - - DJANGO==1.5.8 - - DJANGO==1.6.5 + - DJANGO=Django==1.4.13 + - DJANGO=Django==1.5.8 + - DJANGO=Django==1.6.5 matrix: exclude: - python: 3.3 - env: DJANGO==1.4.13 + env: DJANGO=Django==1.4.13 - python: 3.4 - env: DJANGO==1.4.13 + env: DJANGO=Django==1.4.13 before_script: - "./before_script.sh" install: -- cgit v1.2.3 From c5c66b156da1b29faaba5388785f6b2eac4f3030 Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 11:52:02 +0100 Subject: yml is hard --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8c1a717..0cbb0de 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,9 +10,9 @@ env: - DJANGO=Django==1.6.5 matrix: exclude: - - python: 3.3 + - python: "3.3" env: DJANGO=Django==1.4.13 - - python: 3.4 + - python: "3.4" env: DJANGO=Django==1.4.13 before_script: - "./before_script.sh" -- cgit v1.2.3 From 6819627b1748a1cf367238015a0aec1df2a1bed3 Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 12:26:59 +0100 Subject: Add notes for 0.2.0 release --- CHANGELOG.md | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24f7223..ddeb096 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,14 +1,22 @@ Changelog for django-wkhtmltopdf ================================ +0.2.0 +----- + +* Support for Python 3 +* Support other Django versions +* Use TestRunner for tests (and remove run_tests.sh) +* Add support for Wheel packaging + 1.2.3 ----- -* update wkhtmltopdf binary to 0.12.0 version on before_script.sh -* update docs to reference a wkhtmltopdf on github ( https://github.com/wkhtmltopdf/wkhtmltopdf ) -* add link to official site http://wkhtmltopdf.org/ -* move tests from Makefile to run_tests.sh +* Update wkhtmltopdf binary to 0.12.0 version on before_script.sh +* Update docs to reference a wkhtmltopdf on github +* Add link to official site http://wkhtmltopdf.org/ +* Move tests from Makefile to run_tests.sh 1.2.2 -- cgit v1.2.3 From 3898e56c1f8a4cceea21e2628fdb7d93f97ca615 Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 12:27:54 +0100 Subject: Make teh tests run right Because Django 1.6 and other fireworks. --- .travis.yml | 1 + Makefile | 9 +++++++-- run_tests.sh | 6 ------ test_requirements.txt | 2 ++ wkhtmltopdf/test_settings.py | 30 ------------------------------ wkhtmltopdf/tests/run.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 53 insertions(+), 38 deletions(-) delete mode 100755 run_tests.sh create mode 100644 test_requirements.txt delete mode 100644 wkhtmltopdf/test_settings.py create mode 100644 wkhtmltopdf/tests/run.py diff --git a/.travis.yml b/.travis.yml index 0cbb0de..a7f43c2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,6 +18,7 @@ before_script: - "./before_script.sh" install: - pip install $DJANGO + - pip install -r test_requirements.txt - pip install . script: - make test diff --git a/Makefile b/Makefile index 059771c..eb99a79 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,12 @@ SHELL := /bin/bash +help: + @echo "Usage:" + @echo " make release | Release to pypi." + @echo " make test | Run the tests." + release: - python setup.py register sdist upload + python setup.py register sdist bdist_wheel upload test: - ./run_tests.sh + python ./wkhtmltopdf/tests/run.py diff --git a/run_tests.sh b/run_tests.sh deleted file mode 100755 index 1cb1dd5..0000000 --- a/run_tests.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env bash - -export WKHTMLTOPDF_CMD=`pwd`/wkhtmltox_folder/wkhtmltox/bin/wkhtmltopdf; -export PYTHONPATH=.:$$PYTHONPATH; - -django-admin.py test tests --settings=wkhtmltopdf.test_settings diff --git a/test_requirements.txt b/test_requirements.txt new file mode 100644 index 0000000..ba357b3 --- /dev/null +++ b/test_requirements.txt @@ -0,0 +1,2 @@ +colour-runner==0.0.4 +django-discover-runner==1.0 diff --git a/wkhtmltopdf/test_settings.py b/wkhtmltopdf/test_settings.py deleted file mode 100644 index 16fb734..0000000 --- a/wkhtmltopdf/test_settings.py +++ /dev/null @@ -1,30 +0,0 @@ -import os - -DEBUG = True - -DIRNAME = os.path.abspath(os.path.dirname(__file__)) - -SECRET_KEY = 'fooooooo' - -DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': ':memory:', - } -} - -MEDIA_ROOT = os.path.join(DIRNAME, 'media') -MEDIA_URL = '/media/' -STATIC_ROOT = os.path.join(DIRNAME, 'static') -STATIC_URL = '/static/' - -INSTALLED_APPS = ( - 'wkhtmltopdf.tests', - 'wkhtmltopdf', -) - -TEMPLATE_DIRS = [ - os.path.join(DIRNAME, 'testproject', 'tests', 'templates'), -] - -WKHTMLTOPDF_DEBUG = DEBUG diff --git a/wkhtmltopdf/tests/run.py b/wkhtmltopdf/tests/run.py new file mode 100644 index 0000000..239f5dc --- /dev/null +++ b/wkhtmltopdf/tests/run.py @@ -0,0 +1,43 @@ +#! /usr/bin/env python +import os +import sys + +from colour_runner.django_runner import ColourRunnerMixin +from django.conf import settings + +DIRNAME = os.path.abspath(os.path.dirname(__file__)) + + +settings.configure( + DEBUG=True, + DATABASES={ + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + 'NAME': ':memory:', + } + }, + INSTALLED_APPS=( + 'wkhtmltopdf.tests', + 'wkhtmltopdf', + ), + MEDIA_ROOT=os.path.join(DIRNAME, 'media'), + MEDIA_URL='/media/', + STATIC_ROOT=os.path.join(DIRNAME, 'static'), + STATIC_URL='/static/', + WKHTMLTOPDF_DEBUG=True, +) + +try: + from django.test.runner import DiscoverRunner +except ImportError: + from discover_runner.runner import DiscoverRunner + + +class TestRunner(ColourRunnerMixin, DiscoverRunner): + pass + + +test_runner = TestRunner(verbosity=1) +failures = test_runner.run_tests(['wkhtmltopdf']) +if failures: + sys.exit(1) -- cgit v1.2.3 From 58d345459fab83081800cf751fef0abc5372b38c Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 12:29:08 +0100 Subject: [ci skip] Bump to 2.0.0 --- CHANGELOG.md | 2 +- wkhtmltopdf/__init__.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ddeb096..daa7be1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ Changelog for django-wkhtmltopdf ================================ -0.2.0 +2.0.0 ----- * Support for Python 3 diff --git a/wkhtmltopdf/__init__.py b/wkhtmltopdf/__init__.py index a1663c7..537dafc 100644 --- a/wkhtmltopdf/__init__.py +++ b/wkhtmltopdf/__init__.py @@ -3,4 +3,4 @@ if 'DJANGO_SETTINGS_MODULE' in os.environ: from .utils import * __author__ = 'Incuna Ltd' -__version__ = '1.2.3' +__version__ = '2.0.0' -- cgit v1.2.3 From 8ff65e95d59ea46d05b8b44d2551f1085a4834f7 Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 12:33:06 +0100 Subject: colour-runner dependency doesn't work on py2.6 DAMN IT --- test_requirements.txt | 1 - wkhtmltopdf/tests/run.py | 7 +------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/test_requirements.txt b/test_requirements.txt index ba357b3..0d4fee0 100644 --- a/test_requirements.txt +++ b/test_requirements.txt @@ -1,2 +1 @@ -colour-runner==0.0.4 django-discover-runner==1.0 diff --git a/wkhtmltopdf/tests/run.py b/wkhtmltopdf/tests/run.py index 239f5dc..a840e68 100644 --- a/wkhtmltopdf/tests/run.py +++ b/wkhtmltopdf/tests/run.py @@ -2,7 +2,6 @@ import os import sys -from colour_runner.django_runner import ColourRunnerMixin from django.conf import settings DIRNAME = os.path.abspath(os.path.dirname(__file__)) @@ -33,11 +32,7 @@ except ImportError: from discover_runner.runner import DiscoverRunner -class TestRunner(ColourRunnerMixin, DiscoverRunner): - pass - - -test_runner = TestRunner(verbosity=1) +test_runner = DiscoverRunner(verbosity=1) failures = test_runner.run_tests(['wkhtmltopdf']) if failures: sys.exit(1) -- cgit v1.2.3 From db3f0591e01189e70ca177e3750bd43a171a6ac3 Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 12:44:07 +0100 Subject: Debug --- before_script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/before_script.sh b/before_script.sh index 5c2cce8..9ab45e4 100755 --- a/before_script.sh +++ b/before_script.sh @@ -9,4 +9,4 @@ mkdir -p $WKHTMLTOX_FOLDER echo "## Extracting wkhtmltox into $WKHTMLTOX_FOLDER" tar xvJf wkhtmltox-linux-amd64_0.12.0-03c001d.tar.xz -C $WKHTMLTOX_FOLDER export WKHTMLTOPDF_CMD=$WKHTMLTOX_FOLDER/wkhtmltox/bin/wkhtmltopdf - +echo $WKHTMLTOPDF_CMD --version -- cgit v1.2.3 From 6cacfe5e012a3e9b95b53dede0ba997f5ed74880 Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 12:46:54 +0100 Subject: Debug part II --- before_script.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/before_script.sh b/before_script.sh index 9ab45e4..e5956b0 100755 --- a/before_script.sh +++ b/before_script.sh @@ -9,4 +9,4 @@ mkdir -p $WKHTMLTOX_FOLDER echo "## Extracting wkhtmltox into $WKHTMLTOX_FOLDER" tar xvJf wkhtmltox-linux-amd64_0.12.0-03c001d.tar.xz -C $WKHTMLTOX_FOLDER export WKHTMLTOPDF_CMD=$WKHTMLTOX_FOLDER/wkhtmltox/bin/wkhtmltopdf -echo $WKHTMLTOPDF_CMD --version +$WKHTMLTOPDF_CMD --version -- cgit v1.2.3 From 35f093603ecf6aa48b29d91ba4a6da1cb7109817 Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 15:45:15 +0100 Subject: Move the wkhtmltopdf install process to .travis --- .travis.yml | 13 +++++++++++-- before_script.sh | 12 ------------ 2 files changed, 11 insertions(+), 14 deletions(-) delete mode 100755 before_script.sh diff --git a/.travis.yml b/.travis.yml index a7f43c2..dab05fc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,8 @@ python: - "3.3" - "3.4" env: + global: + - WKHTML_HOME=`pwd`/"_wkhtmltopdf" - DJANGO=Django==1.4.13 - DJANGO=Django==1.5.8 - DJANGO=Django==1.6.5 @@ -14,8 +16,15 @@ matrix: env: DJANGO=Django==1.4.13 - python: "3.4" env: DJANGO=Django==1.4.13 -before_script: - - "./before_script.sh" +before_install: + - echo '## Installing dependencies' + - 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 $WKHTML_HOME + - echo "## Extracting wkhtmltox into $WKHTML_HOME" + - tar xvJf wkhtmltox-linux-amd64_0.12.0-03c001d.tar.xz -C $WKHTML_HOME + - export WKHTMLTOPDF_CMD=$WKHTML_HOME/wkhtmltox/bin/wkhtmltopdf install: - pip install $DJANGO - pip install -r test_requirements.txt diff --git a/before_script.sh b/before_script.sh deleted file mode 100755 index e5956b0..0000000 --- a/before_script.sh +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/env bash -WKHTMLTOX_FOLDER="`pwd`/wkhtmltox_folder" - -echo '## Installing dependencies' -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 $WKHTMLTOX_FOLDER -echo "## Extracting wkhtmltox into $WKHTMLTOX_FOLDER" -tar xvJf wkhtmltox-linux-amd64_0.12.0-03c001d.tar.xz -C $WKHTMLTOX_FOLDER -export WKHTMLTOPDF_CMD=$WKHTMLTOX_FOLDER/wkhtmltox/bin/wkhtmltopdf -$WKHTMLTOPDF_CMD --version -- cgit v1.2.3 From a57a5e87f501009cfc0c80af8a100f8ad18d9819 Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 15:46:40 +0100 Subject: [ci skip] Update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index daa7be1..780fd46 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ Changelog for django-wkhtmltopdf * Support other Django versions * Use TestRunner for tests (and remove run_tests.sh) * Add support for Wheel packaging - +* Build the wkhtmltopdf binary in .travis.yml (and remove before_script.sh) 1.2.3 ----- -- cgit v1.2.3 From 0caa3f75d50607c9e37b7f7249b99ab9897cd023 Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 15:55:11 +0100 Subject: Travis does not like before_install? --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index dab05fc..3816ee5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ matrix: env: DJANGO=Django==1.4.13 - python: "3.4" env: DJANGO=Django==1.4.13 -before_install: +install: - echo '## Installing dependencies' - sudo apt-get install -y openssl build-essential xorg libssl-dev - echo '## Downloading wkhtmltopdf 0.12.0' @@ -25,7 +25,7 @@ before_install: - echo "## Extracting wkhtmltox into $WKHTML_HOME" - tar xvJf wkhtmltox-linux-amd64_0.12.0-03c001d.tar.xz -C $WKHTML_HOME - export WKHTMLTOPDF_CMD=$WKHTML_HOME/wkhtmltox/bin/wkhtmltopdf -install: + - pip install $DJANGO - pip install -r test_requirements.txt - pip install . -- cgit v1.2.3 From d7c17ca2f766a214dae867a1dfe0a7ac0d64837c Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 15:57:58 +0100 Subject: Double quotes for install cmds --- .travis.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3816ee5..e4f8d64 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,16 +16,16 @@ matrix: env: DJANGO=Django==1.4.13 - python: "3.4" env: DJANGO=Django==1.4.13 +before_install: + - "echo '## Installing dependencies'" + - "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 $WKHTML_HOME" + - "echo '## Extracting wkhtmltox into $WKHTML_HOME'" + - "tar xvJf wkhtmltox-linux-amd64_0.12.0-03c001d.tar.xz -C $WKHTML_HOME" + - "export WKHTMLTOPDF_CMD=$WKHTML_HOME/wkhtmltox/bin/wkhtmltopdf" install: - - echo '## Installing dependencies' - - 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 $WKHTML_HOME - - echo "## Extracting wkhtmltox into $WKHTML_HOME" - - tar xvJf wkhtmltox-linux-amd64_0.12.0-03c001d.tar.xz -C $WKHTML_HOME - - export WKHTMLTOPDF_CMD=$WKHTML_HOME/wkhtmltox/bin/wkhtmltopdf - - pip install $DJANGO - pip install -r test_requirements.txt - pip install . -- cgit v1.2.3 From 2f999b9bde4b64271fb42e9caa30474451c4098d Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 16:00:30 +0100 Subject: Move pwd to before_install section C'mon Travis! --- .travis.yml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index e4f8d64..352b7c6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,8 +5,6 @@ python: - "3.3" - "3.4" env: - global: - - WKHTML_HOME=`pwd`/"_wkhtmltopdf" - DJANGO=Django==1.4.13 - DJANGO=Django==1.5.8 - DJANGO=Django==1.6.5 @@ -17,14 +15,15 @@ matrix: - python: "3.4" env: DJANGO=Django==1.4.13 before_install: + - PWD=`pwd` - "echo '## Installing dependencies'" - "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 $WKHTML_HOME" - - "echo '## Extracting wkhtmltox into $WKHTML_HOME'" - - "tar xvJf wkhtmltox-linux-amd64_0.12.0-03c001d.tar.xz -C $WKHTML_HOME" - - "export WKHTMLTOPDF_CMD=$WKHTML_HOME/wkhtmltox/bin/wkhtmltopdf" + - "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" install: - pip install $DJANGO - pip install -r test_requirements.txt -- cgit v1.2.3 From 865889afb07866b6a41e93be3600c40acdacacc9 Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 16:16:38 +0100 Subject: Add apt-get update for Travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 352b7c6..a2b7cf8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,6 +17,7 @@ matrix: before_install: - PWD=`pwd` - "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" -- cgit v1.2.3 From f595fe1391028316541aa4cd9df2910ed05f6d76 Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 16:54:34 +0100 Subject: Law is tricky, kids --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index a7d567e..aecebff 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2014, Incuna Ltd +Copyright (c) 2012-2014, Incuna Ltd All rights reserved. Redistribution and use in source and binary forms, with or without modification, -- cgit v1.2.3 From e1daede87708f070a26b86e0aa533be276a1c9a7 Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 17:03:01 +0100 Subject: Correct Python versions in Readme --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index b7050ec..a61a069 100644 --- a/README.rst +++ b/README.rst @@ -21,7 +21,7 @@ This requires libfontconfig (on Ubuntu: ``sudo aptitude install libfontconfig``) .. _wkhtmltopdf: http://wkhtmltopdf.org/downloads.html -Python 2.6+ through 3.4 is supported. +Python 2.6+ and 3.3+ is supported. Installation -- cgit v1.2.3 From b615855f8ca277437dad9c332398e3803c2af41c Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 17:03:42 +0100 Subject: Add universal wheel distribution file --- setup.cfg | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 setup.cfg diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000..2a9acf1 --- /dev/null +++ b/setup.cfg @@ -0,0 +1,2 @@ +[bdist_wheel] +universal = 1 -- cgit v1.2.3 From c66222e8d649ef3d10ca679921c4c6ce8793cddd Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 17:11:38 +0100 Subject: First try py3k then fall back to python2 --- wkhtmltopdf/utils.py | 6 +++--- wkhtmltopdf/views.py | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/wkhtmltopdf/utils.py b/wkhtmltopdf/utils.py index 9be8f86..e34085d 100644 --- a/wkhtmltopdf/utils.py +++ b/wkhtmltopdf/utils.py @@ -7,11 +7,11 @@ import re import sys try: - from urllib import pathname2url - from urlparse import urljoin -except ImportError: # py3k from urllib.request import pathname2url from urllib.parse import urljoin +except ImportError: # Python2 + from urllib import pathname2url + from urlparse import urljoin from django.conf import settings from django.utils import six diff --git a/wkhtmltopdf/views.py b/wkhtmltopdf/views.py index 92e2d0f..1c57869 100644 --- a/wkhtmltopdf/views.py +++ b/wkhtmltopdf/views.py @@ -77,12 +77,12 @@ class PDFTemplateResponse(TemplateResponse, PDFResponse): content = make_absolute_paths(content) try: - tempfile = NamedTemporaryFile(mode=mode, bufsize=bufsize, + # Python3 has 'buffering' arg instead of 'bufsize' + tempfile = NamedTemporaryFile(mode=mode, buffering=bufsize, suffix=suffix, prefix=prefix, dir=dir, delete=delete) except TypeError: - # Python 3 has 'buffering' arg for 'NamedTemporaryFile' class - tempfile = NamedTemporaryFile(mode=mode, buffering=bufsize, + tempfile = NamedTemporaryFile(mode=mode, bufsize=bufsize, suffix=suffix, prefix=prefix, dir=dir, delete=delete) -- cgit v1.2.3 From 47dc520837b5d099fecc0db27f38ee6ebf898a80 Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Wed, 18 Jun 2014 17:39:22 +0100 Subject: Range Django versions --- .travis.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index a2b7cf8..3f3dacc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,15 +5,15 @@ python: - "3.3" - "3.4" env: - - DJANGO=Django==1.4.13 - - DJANGO=Django==1.5.8 - - DJANGO=Django==1.6.5 + - DJANGO="Django>=1.4,<1.5" + - DJANGO="Django>=1.5,<1.6" + - DJANGO="Django>=1.6,<1.7" matrix: exclude: - python: "3.3" - env: DJANGO=Django==1.4.13 + env: DJANGO="Django>=1.4,<1.5" - python: "3.4" - env: DJANGO=Django==1.4.13 + env: DJANGO="Django>=1.4,<1.5" before_install: - PWD=`pwd` - "echo '## Installing dependencies'" -- cgit v1.2.3 From 301bef0d6931582583a156b3195b8b13f54d2875 Mon Sep 17 00:00:00 2001 From: Matt Lenc Date: Thu, 19 Jun 2014 11:26:05 +0100 Subject: Bring back the test assert for title in content --- wkhtmltopdf/tests/tests.py | 5 +++-- wkhtmltopdf/views.py | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/wkhtmltopdf/tests/tests.py b/wkhtmltopdf/tests/tests.py index f2d92aa..7365d05 100644 --- a/wkhtmltopdf/tests/tests.py +++ b/wkhtmltopdf/tests/tests.py @@ -8,6 +8,7 @@ import sys from django.conf import settings from django.test import TestCase from django.test.client import RequestFactory +from django.utils import six from django.utils.encoding import smart_str from wkhtmltopdf.subprocess import CalledProcessError @@ -190,8 +191,8 @@ class TestViews(TestCase): self.assertTrue(static_url in footer_content, True) pdf_content = response.rendered_content - self.assertTrue(pdf_content.startswith(b'%PDF-')) - self.assertTrue(pdf_content.endswith(b'%%EOF\n')) + title = '\0'.join(cmd_options['title']) + self.assertIn(six.b(title), pdf_content) def test_pdf_template_response_to_browser(self): self.test_pdf_template_response(show_content=True) diff --git a/wkhtmltopdf/views.py b/wkhtmltopdf/views.py index 1c57869..2f1945d 100644 --- a/wkhtmltopdf/views.py +++ b/wkhtmltopdf/views.py @@ -5,6 +5,7 @@ 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 .utils import (content_disposition_filename, make_absolute_paths, @@ -73,7 +74,7 @@ class PDFTemplateResponse(TemplateResponse, PDFResponse): context = self.resolve_context(self.context_data) - content = template.render(context) + content = smart_str(template.render(context)) content = make_absolute_paths(content) try: -- cgit v1.2.3