|
|
|
|
@ -1,6 +1,7 @@ |
|
|
|
|
# -*- coding: utf-8 -*- |
|
|
|
|
import urllib |
|
|
|
|
import urllib.parse |
|
|
|
|
from io import BytesIO |
|
|
|
|
from trans import trans |
|
|
|
|
from xhtml2pdf import pisa |
|
|
|
|
from django.template.loader import get_template |
|
|
|
|
from django.template import Context |
|
|
|
|
@ -14,10 +15,9 @@ def pdf_to_response(content, filename=None): |
|
|
|
|
""" |
|
|
|
|
response = HttpResponse(content, content_type='application/pdf') |
|
|
|
|
if filename: |
|
|
|
|
filename = filename.replace('"', "''") |
|
|
|
|
filename = filename.replace('№', 'N') |
|
|
|
|
filename = trans(filename) |
|
|
|
|
response['Content-Disposition'] = ('attachment; filename="{}"'.format(filename)) |
|
|
|
|
filename = filename.encode('utf-8') |
|
|
|
|
filename_part = "filename*=UTF-8''%s" % urllib.parse.quote(filename) |
|
|
|
|
response['Content-Disposition'] = 'attachment; ' + filename_part |
|
|
|
|
return response |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|