aboutsummaryrefslogtreecommitdiffstats
path: root/wkhtmltopdf
diff options
context:
space:
mode:
authorCharlie Denton <charlie@meshy.co.uk>2012-02-23 17:48:04 +0000
committerCharlie Denton <charlie@meshy.co.uk>2012-02-23 17:48:04 +0000
commite625b44977915a8bf193f5fc974fba86758b7926 (patch)
treec94f0d002287f118cb59d0f5c417e44d3f49c9dc /wkhtmltopdf
parent3581893df1f945d77c74cfb997a6be3d2d0f0831 (diff)
downloaddjango-wkhtmltopdf-e625b44977915a8bf193f5fc974fba86758b7926.tar.gz
django-wkhtmltopdf-e625b44977915a8bf193f5fc974fba86758b7926.tar.bz2
django-wkhtmltopdf-e625b44977915a8bf193f5fc974fba86758b7926.zip
Made PDFTemplateView a little more extensible, and added orientation.
Diffstat (limited to 'wkhtmltopdf')
-rw-r--r--wkhtmltopdf/views.py30
1 files changed, 18 insertions, 12 deletions
diff --git a/wkhtmltopdf/views.py b/wkhtmltopdf/views.py
index 7d9e844..53f11bd 100644
--- a/wkhtmltopdf/views.py
+++ b/wkhtmltopdf/views.py
@@ -26,6 +26,7 @@ class PDFTemplateView(TemplateView):
filename = 'rendered_pdf.pdf'
footer_template = None
header_template = None
+ orientation = 'portrait'
margin_bottom = 0
margin_left = 0
margin_right = 0
@@ -36,25 +37,30 @@ class PDFTemplateView(TemplateView):
if request.GET.get('as', '') == 'html':
return super(PdfTemplateView, self).get(request, *args, **kwargs)
- page_path = template_to_temp_file(self.template_name, self.get_context_data(), context_instance)
+ self.context_instance = context_instance
+ page_path = template_to_temp_file(self.template_name, self.get_context_data(), self.context_instance)
+
+ pdf_kwargs = self.get_pdf_kwargs()
+ return self.response(wkhtmltopdf(page_path, **pdf_kwargs), self.filename)
+
+ def get_pdf_kwargs(self):
+ kwargs = {
+ 'margin_bottom': self.margin_bottom,
+ 'margin_left': self.margin_left,
+ 'margin_right': self.margin_right,
+ 'margin_top': self.margin_top,
+ 'orientation': self.self.orientation,
+ }
tmp_files = []
if self.header_template:
- kwargs['header_html'] = template_to_temp_file(self.header_template, self.get_context_data(), context_instance)
+ kwargs['header_html'] = template_to_temp_file(self.header_template, self.get_context_data(), self.context_instance)
tmp_files.append(kwargs['header_html'])
if self.footer_template:
- kwargs['footer_html'] = template_to_temp_file(self.footer_template, self.get_context_data(), context_instance)
+ 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)
-
- kwargs.update({
- 'margin_bottom': self.margin_bottom,
- 'margin_left': self.margin_left,
- 'margin_right': self.margin_right,
- 'margin_top': self.margin_top
- })
- return self.response(wkhtmltopdf(page_path, **kwargs), self.filename)
+ return kwargs
def get_context_data(self, **kwargs):
context = super(PdfTemplateView, self).get_context_data(**kwargs)