From 5a1847309e7fa431c98565805d88a21a40d01406 Mon Sep 17 00:00:00 2001 From: Simon Law Date: Wed, 25 Jul 2012 12:51:26 -0400 Subject: 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. --- wkhtmltopdf/utils.py | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'wkhtmltopdf/utils.py') 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 -- cgit v1.2.3