X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/af77776a9ff93ac89cfe941c8a97e3e4cac1bd2e..79c9837d588f3d5a9046d66b74e04ed9886c3408:/apps/reporting/utils.py diff --git a/apps/reporting/utils.py b/apps/reporting/utils.py index 919e2edc1..cc4e97a29 100755 --- a/apps/reporting/utils.py +++ b/apps/reporting/utils.py @@ -2,16 +2,12 @@ # This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later. # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # +from errno import ENOENT import os import os.path -import shutil -import subprocess -from tempfile import mkdtemp -from StringIO import StringIO from django.conf import settings import logging from django.http import HttpResponse -from django.template.loader import render_to_string logger = logging.getLogger(__name__) @@ -25,7 +21,13 @@ def render_to_pdf(output_path, template, context=None, add_files=None): :param dict add_files: a dictionary of additional files XeTeX will need """ + from StringIO import StringIO + import shutil + from tempfile import mkdtemp + import subprocess import Texml.processor + from django.template.loader import render_to_string + rendered = render_to_string(template, context) texml = StringIO(rendered.encode('utf-8')) tempdir = mkdtemp(prefix = "render_to_pdf-") @@ -71,7 +73,11 @@ def generated_file_view(file_name, mime_type, send_name=None, signals=None): send_name = os.path.basename(file_name) def signal_handler(*args, **kwargs): - os.unlink(file_path) + try: + os.unlink(file_path) + except OSError as oe: + if oe.errno != ENOENT: + raise oe if signals: for signal in signals: @@ -79,7 +85,7 @@ def generated_file_view(file_name, mime_type, send_name=None, signals=None): def decorator(func): def view(request, *args, **kwargs): - if not os.path.exists(file_path) or True: + if not os.path.exists(file_path): func(file_path, *args, **kwargs) if hasattr(send_name, "__call__"):