From 88ae103ec11c5cfa874bd9bc915e44ba7946aae0 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Sun, 3 Mar 2024 23:09:18 +0100 Subject: [PATCH] =?UTF-8?q?Lep=C5=A1=C3=AD=20slo=C5=BEky=20i=20pro=20stvrz?= =?UTF-8?q?enky?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- soustredeni/views.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/soustredeni/views.py b/soustredeni/views.py index f2aafdf7..899ee7f9 100644 --- a/soustredeni/views.py +++ b/soustredeni/views.py @@ -79,14 +79,14 @@ def soustredeniStvrzenkyView(request, soustredeni): castka = Nastaveni.get_solo().cena_sous tex = render(request, 'soustredeni/stvrzenky.tex', {'ucastnici': ucastnici, 'soustredeni': soustredeni, 'castka': castka}).content - tempdir = Path(tempfile.mkdtemp()) - with open(tempdir / "stvrzenky.tex", "w") as texfile: - texfile.write(tex.decode()) + with tempfile.TemporaryDirectory() as tempdirfn: + tempdir = Path(tempdirfn) + with open(tempdir / "stvrzenky.tex", "w") as texfile: + texfile.write(tex.decode()) - shutil.copy(find('images/logomm.pdf'), tempdir) - subprocess.call(["pdflatex", "stvrzenky.tex"], cwd = tempdir, stdout=subprocess.DEVNULL) + shutil.copy(find('images/logomm.pdf'), tempdir) + subprocess.call(["pdflatex", "stvrzenky.tex"], cwd = tempdir, stdout=subprocess.DEVNULL) - with open(tempdir / "stvrzenky.pdf", "rb") as pdffile: - response = HttpResponse(pdffile.read(), content_type='application/pdf') - shutil.rmtree(tempdir) + with open(tempdir / "stvrzenky.pdf", "rb") as pdffile: + response = HttpResponse(pdffile.read(), content_type='application/pdf') return response