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