Skip to content
This repository has been archived by the owner on Jun 29, 2020. It is now read-only.

Backport fix from django-wkhtmltopdf that includes request in context #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions puppeteer_pdf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,17 +263,19 @@ def make_absolute_paths(content):
def render_to_temporary_file(template, context, request=None, mode='w+b',
bufsize=-1, suffix='.html', prefix='tmp',
dir=None, delete=True):
if django.VERSION < (1, 8):
# If using a version of Django prior to 1.8, ensure ``context`` is an
# instance of ``Context``
if not isinstance(context, Context):
if request:
context = RequestContext(request, context)
else:
context = Context(context)
# Handle error when ``request`` is None
try:
content = template.render(context)
if django.VERSION < (1, 8):
# If using a version of Django prior to 1.8, ensure ``context`` is an
# instance of ``Context``
if not isinstance(context, Context):
if request:
context = RequestContext(request, context)
else:
context = Context(context)
# Handle error when ``request`` is None
content = template.render(context)
else:
content = template.render(context, request)
except AttributeError:
content = loader.render_to_string(template, context)

Expand Down