|
@ -1,8 +1,9 @@ |
|
|
from django.shortcuts import get_object_or_404 |
|
|
from django.shortcuts import get_object_or_404, render |
|
|
from django.http import HttpResponse |
|
|
from django.http import HttpResponse |
|
|
from django.views import generic |
|
|
from django.views import generic |
|
|
from django.conf import settings |
|
|
from django.conf import settings |
|
|
from seminar.models import Soustredeni, Resitel, Soustredeni_Ucastnici # Tohle je stare a chceme se toho zbavit. Pouzivejte s.ToCoChci |
|
|
from django.contrib.staticfiles.finders import find |
|
|
|
|
|
from seminar.models import Soustredeni, Resitel, Soustredeni_Ucastnici, Nastaveni # Tohle je stare a chceme se toho zbavit. Pouzivejte s.ToCoChci |
|
|
import csv |
|
|
import csv |
|
|
import tempfile |
|
|
import tempfile |
|
|
import shutil |
|
|
import shutil |
|
@ -62,20 +63,17 @@ 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) |
|
|
|
|
|
castka = Nastaveni.get_solo().cena_sous |
|
|
|
|
|
tex = render(request, 'soustredeni/stvrzenky.tex', {'ucastnici': ucastnici, 'soustredeni': soustredeni, 'castka': castka}).content |
|
|
|
|
|
|
|
|
static = Path(settings.STATIC_ROOT) |
|
|
|
|
|
tempdir = Path(tempfile.mkdtemp()) |
|
|
tempdir = Path(tempfile.mkdtemp()) |
|
|
shutil.copy(static / 'images/logomm.pdf', tempdir) |
|
|
with open(tempdir / "stvrzenky.tex", "w") as texfile: |
|
|
shutil.copy(static / 'seminar/stvrzenky.tex', tempdir) |
|
|
texfile.write(tex.decode()) |
|
|
subprocess.run( |
|
|
|
|
|
['pdfcsplain', 'stvrzenky.tex'], |
|
|
shutil.copy(find('images/logomm.pdf'), tempdir) |
|
|
cwd=tempdir, |
|
|
subprocess.call(["pdflatex", "stvrzenky.tex"], cwd = tempdir, stdout=subprocess.DEVNULL) |
|
|
encoding='utf-8', |
|
|
|
|
|
input=f'{soustredeni.datum_zacatku.strftime("%-d.~%-m.~%Y")} -- {soustredeni.datum_konce.strftime("%-d.~%-m.~%Y")}\n{soustredeni.misto}\n' |
|
|
with open(tempdir / "stvrzenky.pdf", "rb") as pdffile: |
|
|
+ '\n'.join([f'{u.osoba.jmeno} {u.osoba.prijmeni}' for u in ucastnici]) |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
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) |
|
|
shutil.rmtree(tempdir) |
|
|
return response |
|
|
return response |
|
|