aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md23
-rw-r--r--Makefile5
-rw-r--r--README.rst2
-rw-r--r--setup.py23
-rw-r--r--wkhtmltopdf/__init__.py6
-rw-r--r--wkhtmltopdf/views.py27
6 files changed, 60 insertions, 26 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 560916b..5c94cb9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,29 @@ Changelog for django-wkhtmltopdf
================================
+0.3
+---
+
+* Fix a bug where temporary files were removed before the PDF was generated
+ when using the header & footer options.
+* Only set the `Content-Disposition` header in the response if `filename` is set.
+* Added a Makefile for deployments.
+* Added 2.6 requirement to the README.
+
+
+0.2.2
+-----
+
+* Create a request context if one hasn't been passed into the view.
+
+
+0.2.1
+-----
+
+* Use `get_template_names()` for extra extensibility.
+* Be clear with `template_to_temp_file`'s arguments.
+
+
0.2
---
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..c5f9321
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,5 @@
+SHELL := /bin/bash
+
+release:
+ python setup.py register sdist upload
+
diff --git a/README.rst b/README.rst
index 8e978fe..b65bb22 100644
--- a/README.rst
+++ b/README.rst
@@ -16,6 +16,8 @@ This requires libfontconfig (on Ububtu: ``sudo aptitude install libfontconfig``)
.. _wkhtmltopdf: http://code.google.com/p/wkhtmltopdf/downloads/list
+Python 2.6
+
Installation
------------
diff --git a/setup.py b/setup.py
index 9da3678..86c0b44 100644
--- a/setup.py
+++ b/setup.py
@@ -1,22 +1,17 @@
-from os.path import dirname, join
from setuptools import setup, find_packages
-from wkhtmltopdf import get_version
+import wkhtmltopdf
-def fread(fn):
- with open(join(dirname(__file__), fn), 'r') as f:
- return f.read()
-
setup(
- name = "django-wkhtmltopdf",
- packages = find_packages(),
+ name='django-wkhtmltopdf',
+ packages=find_packages(),
include_package_data=True,
- version = get_version(),
- description = "Converts html to PDF using http://code.google.com/p/wkhtmltopdf/.",
- long_description = fread('README.rst'),
- author = "Incuna Ltd",
- author_email = "admin@incuna.com",
- url = "http://incuna.com/",
+ version=wkhtmltopdf.__version__,
+ description='Converts html to PDF using http://code.google.com/p/wkhtmltopdf/.',
+ long_description=open('README.rst').read(),
+ author=wkhtmltopdf.__author__,
+ author_email='admin@incuna.com',
+ url='http://incuna.com/',
)
diff --git a/wkhtmltopdf/__init__.py b/wkhtmltopdf/__init__.py
index 6738053..39b1413 100644
--- a/wkhtmltopdf/__init__.py
+++ b/wkhtmltopdf/__init__.py
@@ -2,6 +2,6 @@ import os
if 'DJANGO_SETTINGS_MODULE' in os.environ:
from .utils import *
-__version__ = (0, 2, 2)
-def get_version():
- return '.'.join(map(str, __version__))
+__author__ = 'Incuna Ltd'
+__version__ = '0.3'
+
diff --git a/wkhtmltopdf/views.py b/wkhtmltopdf/views.py
index b15d7be..164f94f 100644
--- a/wkhtmltopdf/views.py
+++ b/wkhtmltopdf/views.py
@@ -1,4 +1,4 @@
-from os import remove
+import os
from re import compile
from django.conf import settings
@@ -11,9 +11,12 @@ from wkhtmltopdf.utils import template_to_temp_file, wkhtmltopdf
class PDFResponse(HttpResponse):
- def __init__(self, content, filename):
- super(PDFResponse, self).__init__(content, 'application/pdf')
- self.__setitem__('Content-Disposition', 'attachment; filename=%s' % filename)
+ def __init__(self, content, *args, **kwargs):
+ filename = kwargs.pop('filename', None)
+ super(PDFResponse, self).__init__(content, 'application/pdf', *args, **kwargs)
+ if filename:
+ header_content = 'attachment; filename={0}'.format(filename)
+ self.__setitem__('Content-Disposition', header_content)
class PdfResponse(PDFResponse):
@@ -33,6 +36,11 @@ class PDFTemplateView(TemplateView):
margin_right = 0
margin_top = 0
response = PDFResponse
+ _tmp_files = None
+
+ def __init__(self, *args, **kwargs):
+ self._tmp_files = []
+ super(PDFTemplateView, self).__init__(*args, **kwargs)
def get(self, request, context_instance=None, *args, **kwargs):
if request.GET.get('as', '') == 'html':
@@ -45,7 +53,10 @@ class PDFTemplateView(TemplateView):
page_path = template_to_temp_file(self.get_template_names(), self.get_context_data(), self.context_instance)
pdf_kwargs = self.get_pdf_kwargs()
- return self.response(wkhtmltopdf(page_path, **pdf_kwargs), self.get_filename())
+ output = wkhtmltopdf(page_path, **pdf_kwargs)
+ if self._tmp_files:
+ map(os.remove, self._tmp_files)
+ return self.response(output, filename=self.get_filename())
def get_filename(self):
return self.filename
@@ -58,14 +69,12 @@ class PDFTemplateView(TemplateView):
'margin_top': self.margin_top,
'orientation': self.orientation,
}
- tmp_files = []
if self.header_template:
kwargs['header_html'] = template_to_temp_file(self.header_template, self.get_context_data(), self.context_instance)
- tmp_files.append(kwargs['header_html'])
+ self._tmp_files.append(kwargs['header_html'])
if self.footer_template:
kwargs['footer_html'] = template_to_temp_file(self.footer_template, self.get_context_data(), self.context_instance)
- tmp_files.append(kwargs['footer_html'])
- map(remove, tmp_files)
+ self._tmp_files.append(kwargs['footer_html'])
return kwargs
def get_context_data(self, **kwargs):