diff options
-rw-r--r-- | .travis.yml | 8 | ||||
-rw-r--r-- | CHANGELOG.md | 7 | ||||
-rw-r--r-- | README.rst | 13 | ||||
-rw-r--r-- | docs/index.rst | 6 | ||||
-rw-r--r-- | wkhtmltopdf/__init__.py | 2 | ||||
-rw-r--r-- | wkhtmltopdf/tests/run.py | 12 | ||||
-rw-r--r-- | wkhtmltopdf/utils.py | 13 |
7 files changed, 46 insertions, 15 deletions
diff --git a/.travis.yml b/.travis.yml index 698a5ed..8dae083 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,11 +18,11 @@ 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.1'" - - "wget http://freefr.dl.sourceforge.net/project/wkhtmltopdf/0.12.1/wkhtmltox-0.12.1_linux-precise-amd64.deb" + - "sudo apt-get install -y openssl build-essential xorg libssl-dev xfonts-75dpi" + - "echo '## Downloading wkhtmltopdf'" + - "wget http://download.gna.org/wkhtmltopdf/0.12/0.12.2.1/wkhtmltox-0.12.2.1_linux-wheezy-amd64.deb" - "echo '## Installing wkhtmltox'" - - "sudo dpkg -i wkhtmltox-0.12.1_linux-precise-amd64.deb" + - "sudo dpkg -i wkhtmltox-0.12.2.1_linux-wheezy-amd64.deb" - WHICH_WK=`which wkhtmltopdf` - "export WKHTMLTOPDF_CMD=$WHICH_WK" install: diff --git a/CHANGELOG.md b/CHANGELOG.md index 1cd0f24..538a4c5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ Changelog for django-wkhtmltopdf ================================ +2.0.3 +-------- + +* Use shlex for argument splitting (thanks DeadWisdom) +* Skip absolute path substitution where STATIC or MEDIA URL are empty or None + (thanks powderflask) + 2.0.2 ----- @@ -14,10 +14,10 @@ django-wkhtmltopdf :alt: Number of PyPI downloads -Converts html to PDF +Converts HTML to PDF -------------------- -Provides a thin Django wrapper for the `wkhtmltopdf <http://wkhtmltopdf.org>`_ binary. +Provides Django views to wrap the HTML to PDF conversion of the `wkhtmltopdf <http://wkhtmltopdf.org>`_ binary. Requirements ------------ @@ -26,7 +26,7 @@ Install the `wkhtmltopdf static binary <http://wkhtmltopdf.org/downloads.html>`_ This requires libfontconfig (on Ubuntu: ``sudo aptitude install libfontconfig``). -Python 2.6+ and 3.3+ is supported. +Python 2.6+ and 3.3+ are supported. Installation @@ -39,7 +39,7 @@ Add ``'wkhtmltopdf'`` to ``INSTALLED_APPS`` in your ``settings.py``. By default it will execute the first ``wkhtmltopdf`` command found on your ``PATH``. If you can't add wkhtmltopdf to your ``PATH``, you can set ``WKHTMLTOPDF_CMD`` to a -specific execuatable: +specific executable: e.g. in ``settings.py``: :: @@ -58,6 +58,11 @@ The default is: :: 'quiet': True, } +Documentation +------------- + +Documentation is available at http://django-wkhtmltopdf.readthedocs.org/en/latest/. + License ------- diff --git a/docs/index.rst b/docs/index.rst index 817db3f..67442a8 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -6,7 +6,7 @@ django-wkhtmltopdf the wkhtmltopdf_ library, allowing you to write using the technologies you know - HTML and CSS - and output a PDF file. -.. _wkhtmltopdf: http://code.google.com/p/wkhtmltopdf/ +.. _wkhtmltopdf: http://wkhtmltopdf.org/ Quickstart ========== @@ -17,7 +17,7 @@ Quickstart Grab the wkhtmltopdf binary_ for your platform. -.. _binary: http://code.google.com/p/wkhtmltopdf/downloads/list +.. _binary: http://wkhtmltopdf.org/downloads.html ``settings.py`` @@ -46,7 +46,7 @@ Contribute You can fork the project on Github_. -.. _Github: http://github.com/incuna/django-wkhtmltopdf +.. _Github: https://github.com/incuna/django-wkhtmltopdf Contents ======== diff --git a/wkhtmltopdf/__init__.py b/wkhtmltopdf/__init__.py index 873fb03..a9fe3b7 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__ = '2.0.2' +__version__ = '2.0.3' diff --git a/wkhtmltopdf/tests/run.py b/wkhtmltopdf/tests/run.py index a840e68..5004ee1 100644 --- a/wkhtmltopdf/tests/run.py +++ b/wkhtmltopdf/tests/run.py @@ -2,10 +2,12 @@ import os import sys +import django from django.conf import settings DIRNAME = os.path.abspath(os.path.dirname(__file__)) +sys.path.insert(0, os.getcwd()) settings.configure( DEBUG=True, @@ -19,6 +21,10 @@ settings.configure( 'wkhtmltopdf.tests', 'wkhtmltopdf', ), + MIDDLEWARE_CLASSES=( + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + ), MEDIA_ROOT=os.path.join(DIRNAME, 'media'), MEDIA_URL='/media/', STATIC_ROOT=os.path.join(DIRNAME, 'static'), @@ -27,6 +33,12 @@ settings.configure( ) try: + django.setup() +except AttributeError: + pass # Django < 1.7; okay to ignore + + +try: from django.test.runner import DiscoverRunner except ImportError: from discover_runner.runner import DiscoverRunner diff --git a/wkhtmltopdf/utils.py b/wkhtmltopdf/utils.py index 3c9b4a7..053a2e7 100644 --- a/wkhtmltopdf/utils.py +++ b/wkhtmltopdf/utils.py @@ -5,6 +5,7 @@ from itertools import chain import os import re import sys +import shlex try: from urllib.request import pathname2url @@ -88,13 +89,19 @@ def wkhtmltopdf(pages, output=None, **kwargs): cmd = 'WKHTMLTOPDF_CMD' cmd = getattr(settings, cmd, os.environ.get(cmd, 'wkhtmltopdf')) - ck_args = list(chain(cmd.split(), + ck_args = list(chain(shlex.split(cmd), _options_to_args(**options), list(pages), [output])) ck_kwargs = {'env': env} - if hasattr(sys.stderr, 'fileno'): + # Handling of fileno() attr. based on https://github.com/GrahamDumpleton/mod_wsgi/issues/85 + try: + i = sys.stderr.fileno() ck_kwargs['stderr'] = sys.stderr + except (AttributeError, IOError): + # can't call fileno() on mod_wsgi stderr object + pass + return check_output(ck_args, **ck_kwargs) @@ -152,7 +159,7 @@ def make_absolute_paths(content): has_scheme = re.compile(r'^[^:/]+://') for x in overrides: - if has_scheme.match(x['url']): + if not x['url'] or has_scheme.match(x['url']): continue if not x['root'].endswith('/'): |