diff options
author | Simon Law <simon.law@ecometrica.com> | 2012-07-25 12:51:26 -0400 |
---|---|---|
committer | Simon Law <simon.law@ecometrica.com> | 2012-07-25 12:51:26 -0400 |
commit | 5a1847309e7fa431c98565805d88a21a40d01406 (patch) | |
tree | 9aa1b5ac50efd0bd39f1a38130ec9d56e4a59302 /wkhtmltopdf/utils.py | |
parent | a6f0a53702a940bf055dadb3bf558aea49c6d862 (diff) | |
download | django-wkhtmltopdf-5a1847309e7fa431c98565805d88a21a40d01406.tar.gz django-wkhtmltopdf-5a1847309e7fa431c98565805d88a21a40d01406.tar.bz2 django-wkhtmltopdf-5a1847309e7fa431c98565805d88a21a40d01406.zip |
MEDIA_URL and STATIC_URL overrides PDFTemplateResponse.get_override_settings()
MEDIA_URL and STATIC_URL used to be set only in get_context_data(),
but there are apps such as staticfiles and Django Compressor where
this won't work well.
Instead, they need to be overridden at the settings level, not at the
context level. This allows template context processors to populate a
RequestContext with the right values.
In addition, MEDIA_URL and STATIC_URL are now overridden as file://
URLs, based on MEDIA_ROOT and STATIC_ROOT. This allows developers to
access these views in runserver, against their current codebase. It
also means faster access for wkhtmltopdf, since the files are stored
locally.
Diffstat (limited to 'wkhtmltopdf/utils.py')
-rw-r--r-- | wkhtmltopdf/utils.py | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/wkhtmltopdf/utils.py b/wkhtmltopdf/utils.py index 03a5f82..69da74f 100644 --- a/wkhtmltopdf/utils.py +++ b/wkhtmltopdf/utils.py @@ -5,6 +5,7 @@ from itertools import chain from os import fdopen import sys from tempfile import mkstemp +import urllib import warnings from django.conf import settings @@ -124,6 +125,11 @@ def http_quote(string): return '"{!s}"'.format(string.replace('\\', '\\\\').replace('"', '\\"')) +def pathname2fileurl(pathname): + """Returns a file:// URL for pathname. Handles OS-specific conversions.""" + return 'file://' + urllib.pathname2url(pathname) + + try: # From Django 1.4 from django.conf import override_settings |