From a59e2f99777c36eb24f8c03909092fec10b17dd0 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Sun, 3 Mar 2024 22:44:59 +0100 Subject: [PATCH 1/6] =?UTF-8?q?U=C5=BEite=C4=8Dn=C3=A1=20chybov=C3=A1=20st?= =?UTF-8?q?r=C3=A1nka=20pro=20ne=C3=BAsp=C4=9B=C5=A1n=C3=A9=20generov?= =?UTF-8?q?=C3=A1n=C3=AD=20ob=C3=A1lek?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/views/views_all.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/seminar/views/views_all.py b/seminar/views/views_all.py index 318eee21..9dc03550 100644 --- a/seminar/views/views_all.py +++ b/seminar/views/views_all.py @@ -562,6 +562,11 @@ def cisloObalkyView(request, rocnik, cislo): def obalkyView(request, resitele): + if len(resitele) == 0: + return render(request, 'universal.html', { + 'title': 'Není pro koho vyrobit obálky.', + 'text': 'Právě ses pokusil/a vygenerovat obálky pro prázdnou množinu lidí. Můžeš to zkusit změnit, případně se zeptej webařů :-)', + }) tex = render(request,'seminar/archiv/obalky.tex', {'resitele': resitele}).content tempdir = tempfile.mkdtemp() From d2926bd1a7b577c5ec7a4afbae67f5ba24784e15 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Sun, 3 Mar 2024 23:05:39 +0100 Subject: [PATCH 2/6] =?UTF-8?q?Spr=C3=A1vn=C3=A9=20hled=C3=A1n=C3=AD=20li?= =?UTF-8?q?=C5=A1=C3=A1ka=20pro=20ob=C3=A1lky?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/views/views_all.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/seminar/views/views_all.py b/seminar/views/views_all.py index 9dc03550..e345e45d 100644 --- a/seminar/views/views_all.py +++ b/seminar/views/views_all.py @@ -8,6 +8,7 @@ from django.http import Http404 from django.db.models import Q, Sum, Count from django.views.generic.base import RedirectView from django.core.exceptions import PermissionDenied +from django.contrib.staticfiles.finders import find import seminar.models as s import seminar.models as m @@ -572,7 +573,7 @@ def obalkyView(request, resitele): tempdir = tempfile.mkdtemp() with open(tempdir+"/obalky.tex","w") as texfile: texfile.write(tex.decode()) - shutil.copy(os.path.join(settings.STATIC_ROOT, 'seminar/lisak.pdf'), tempdir) + shutil.copy(find('seminar/lisak.pdf'), tempdir) subprocess.call(["pdflatex","obalky.tex"], cwd = tempdir) with open(tempdir+"/obalky.pdf","rb") as pdffile: From 4ecd2a7a61509f7a1b7d50ebd1e87ba79ae3e127 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Sun, 3 Mar 2024 23:06:43 +0100 Subject: [PATCH 3/6] =?UTF-8?q?Je=C5=A1t=C4=9B=20status=20k=C3=B3d?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- seminar/views/views_all.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/seminar/views/views_all.py b/seminar/views/views_all.py index e345e45d..1d0d87ba 100644 --- a/seminar/views/views_all.py +++ b/seminar/views/views_all.py @@ -37,6 +37,7 @@ import unicodedata import logging import time from collections.abc import Sequence +import http from seminar.utils import aktivniResitele @@ -564,10 +565,14 @@ def cisloObalkyView(request, rocnik, cislo): def obalkyView(request, resitele): if len(resitele) == 0: - return render(request, 'universal.html', { - 'title': 'Není pro koho vyrobit obálky.', - 'text': 'Právě ses pokusil/a vygenerovat obálky pro prázdnou množinu lidí. Můžeš to zkusit změnit, případně se zeptej webařů :-)', - }) + return HttpResponse( + render(request, 'universal.html', { + 'title': 'Není pro koho vyrobit obálky.', + 'text': 'Právě ses pokusil/a vygenerovat obálky pro prázdnou množinu lidí. Můžeš to zkusit změnit, případně se zeptej webařů :-)', + }), + status=http.HTTPStatus.NOT_FOUND, + ) + tex = render(request,'seminar/archiv/obalky.tex', {'resitele': resitele}).content tempdir = tempfile.mkdtemp() From 213d3cc7b239ddedd3ff4c91fb20af63b910ca4e Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Sun, 3 Mar 2024 23:07:51 +0100 Subject: [PATCH 4/6] =?UTF-8?q?Lep=C5=A1=C3=AD=20vyr=C3=A1b=C4=9Bn=C3=AD?= =?UTF-8?q?=20do=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 From 88ae103ec11c5cfa874bd9bc915e44ba7946aae0 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Sun, 3 Mar 2024 23:09:18 +0100 Subject: [PATCH 5/6] =?UTF-8?q?Lep=C5=A1=C3=AD=20slo=C5=BEky=20i=20pro=20s?= =?UTF-8?q?tvrzenky?= 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 From a1000ad2bfbc5258f513b258d553f10386593a30 Mon Sep 17 00:00:00 2001 From: "Pavel \"LEdoian\" Turinsky" Date: Sun, 3 Mar 2024 23:11:51 +0100 Subject: [PATCH 6/6] =?UTF-8?q?Chybov=C3=A1=20hl=C3=A1=C5=A1ka=20i=20pro?= =?UTF-8?q?=20stvrzenky?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- soustredeni/views.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/soustredeni/views.py b/soustredeni/views.py index 899ee7f9..f150b6b8 100644 --- a/soustredeni/views.py +++ b/soustredeni/views.py @@ -9,6 +9,7 @@ import tempfile import shutil import subprocess from pathlib import Path +import http from seminar.views import obalkyView @@ -76,6 +77,14 @@ def soustredeniUcastniciExportView(request, soustredeni): def soustredeniStvrzenkyView(request, soustredeni): soustredeni = get_object_or_404(Soustredeni, id=soustredeni) ucastnici = Resitel.objects.filter(soustredeni=soustredeni) + if ucastnici.count() == 0: + return HttpResponse( + render(request, 'universal.html', { + 'title': 'Není pro koho vyrobit stvrzenky.', + 'text': 'Právě ses pokusil/a vygenerovat stvrzenky pro prázdnou množinu lidí. Můžeš to zkusit změnit, případně se zeptej webařů :-)', + }), + status=http.HTTPStatus.NOT_FOUND, + ) castka = Nastaveni.get_solo().cena_sous tex = render(request, 'soustredeni/stvrzenky.tex', {'ucastnici': ucastnici, 'soustredeni': soustredeni, 'castka': castka}).content