Compare commits

...

7 Commits

Author SHA1 Message Date
Pavel Turinský 81494a7152 Merge pull request 'Fix obálek' (!45) from fix-obalky into master 2 months ago
Pavel "LEdoian" Turinsky a1000ad2bf Chybová hláška i pro stvrzenky 2 months ago
Pavel "LEdoian" Turinsky 88ae103ec1 Lepší složky i pro stvrzenky 2 months ago
Pavel "LEdoian" Turinsky 213d3cc7b2 Lepší vyrábění dočasných adresářů 2 months ago
Pavel "LEdoian" Turinsky 4ecd2a7a61 Ještě status kód 2 months ago
Pavel "LEdoian" Turinsky d2926bd1a7 Správné hledání lišáka pro obálky 2 months ago
Pavel "LEdoian" Turinsky a59e2f9977 Užitečná chybová stránka pro neúspěšné generování obálek 2 months ago
  1. 26
      seminar/views/views_all.py
  2. 25
      soustredeni/views.py

26
seminar/views/views_all.py

@ -8,6 +8,7 @@ from django.http import Http404
from django.db.models import Q, Sum, Count from django.db.models import Q, Sum, Count
from django.views.generic.base import RedirectView from django.views.generic.base import RedirectView
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
from django.contrib.staticfiles.finders import find
import seminar.models as s import seminar.models as s
import seminar.models as m import seminar.models as m
@ -36,6 +37,7 @@ import unicodedata
import logging import logging
import time import time
from collections.abc import Sequence from collections.abc import Sequence
import http
from seminar.utils import aktivniResitele from seminar.utils import aktivniResitele
@ -562,17 +564,25 @@ def cisloObalkyView(request, rocnik, cislo):
def obalkyView(request, resitele): def obalkyView(request, resitele):
if len(resitele) == 0:
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 tex = render(request,'seminar/archiv/obalky.tex', {'resitele': resitele}).content
tempdir = tempfile.mkdtemp() with tempfile.TemporaryDirectory() as tempdir:
with open(tempdir+"/obalky.tex","w") as texfile: with open(tempdir+"/obalky.tex","w") as texfile:
texfile.write(tex.decode()) 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) subprocess.call(["pdflatex","obalky.tex"], cwd = tempdir)
with open(tempdir+"/obalky.pdf","rb") as pdffile: with open(tempdir+"/obalky.pdf","rb") as pdffile:
response = HttpResponse(pdffile.read(), content_type='application/pdf') response = HttpResponse(pdffile.read(), content_type='application/pdf')
shutil.rmtree(tempdir)
return response return response

25
soustredeni/views.py

@ -9,6 +9,7 @@ import tempfile
import shutil import shutil
import subprocess import subprocess
from pathlib import Path from pathlib import Path
import http
from seminar.views import obalkyView from seminar.views import obalkyView
@ -76,17 +77,25 @@ def soustredeniUcastniciExportView(request, soustredeni):
def soustredeniStvrzenkyView(request, soustredeni): def soustredeniStvrzenkyView(request, soustredeni):
soustredeni = get_object_or_404(Soustredeni, id=soustredeni) soustredeni = get_object_or_404(Soustredeni, id=soustredeni)
ucastnici = Resitel.objects.filter(soustredeni=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 castka = Nastaveni.get_solo().cena_sous
tex = render(request, 'soustredeni/stvrzenky.tex', {'ucastnici': ucastnici, 'soustredeni': soustredeni, 'castka': castka}).content tex = render(request, 'soustredeni/stvrzenky.tex', {'ucastnici': ucastnici, 'soustredeni': soustredeni, 'castka': castka}).content
tempdir = Path(tempfile.mkdtemp()) with tempfile.TemporaryDirectory() as tempdirfn:
with open(tempdir / "stvrzenky.tex", "w") as texfile: tempdir = Path(tempdirfn)
texfile.write(tex.decode()) with open(tempdir / "stvrzenky.tex", "w") as texfile:
texfile.write(tex.decode())
shutil.copy(find('images/logomm.pdf'), tempdir) shutil.copy(find('images/logomm.pdf'), tempdir)
subprocess.call(["pdflatex", "stvrzenky.tex"], cwd = tempdir, stdout=subprocess.DEVNULL) subprocess.call(["pdflatex", "stvrzenky.tex"], cwd = tempdir, stdout=subprocess.DEVNULL)
with open(tempdir / "stvrzenky.pdf", "rb") as pdffile: with open(tempdir / "stvrzenky.pdf", "rb") as pdffile:
response = HttpResponse(pdffile.read(), content_type='application/pdf') response = HttpResponse(pdffile.read(), content_type='application/pdf')
shutil.rmtree(tempdir)
return response return response

Loading…
Cancel
Save