From 213d3cc7b239ddedd3ff4c91fb20af63b910ca4e Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Sun, 3 Mar 2024 23:07:51 +0100 Subject: [PATCH] =?UTF-8?q?Lep=C5=A1=C3=AD=20vyr=C3=A1b=C4=9Bn=C3=AD=20do?= =?UTF-8?q?=C4=8Dasn=C3=BDch=20adres=C3=A1=C5=99=C5=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Chceme je po sobě nejspíš mazat i když to spadne. Možná to zesložití vývoj, ale je to odolnější proti náhodnému pádu čehokoliv. --- seminar/views/views_all.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/seminar/views/views_all.py b/seminar/views/views_all.py index 1d0d87ba..662c5025 100644 --- a/seminar/views/views_all.py +++ b/seminar/views/views_all.py @@ -575,15 +575,14 @@ def obalkyView(request, resitele): tex = render(request,'seminar/archiv/obalky.tex', {'resitele': resitele}).content - tempdir = tempfile.mkdtemp() - with open(tempdir+"/obalky.tex","w") as texfile: - texfile.write(tex.decode()) - shutil.copy(find('seminar/lisak.pdf'), tempdir) - subprocess.call(["pdflatex","obalky.tex"], cwd = tempdir) - - with open(tempdir+"/obalky.pdf","rb") as pdffile: - response = HttpResponse(pdffile.read(), content_type='application/pdf') - shutil.rmtree(tempdir) + with tempfile.TemporaryDirectory() as tempdir: + with open(tempdir+"/obalky.tex","w") as texfile: + texfile.write(tex.decode()) + shutil.copy(find('seminar/lisak.pdf'), tempdir) + subprocess.call(["pdflatex","obalky.tex"], cwd = tempdir) + + with open(tempdir+"/obalky.pdf","rb") as pdffile: + response = HttpResponse(pdffile.read(), content_type='application/pdf') return response