This commit is contained in:
Jonas Havelka 2025-09-29 14:24:57 +02:00
parent 9a50805a69
commit 62f12d8bda
7 changed files with 131 additions and 0 deletions

Binary file not shown.

Binary file not shown.

View file

@ -125,5 +125,6 @@
<h2>Výsledková listina včetně neveřejných bodů</h2>
{% include "vysledkovky/vysledkovka_rocnik.html" with vysledkovka=vysledkovka_neverejna %}
</div>
<p><a href='certifikaty.tar.gz' download>Certifikáty úspěšných řešitelů</a></p>
{% endif %}
{% endblock content %}

View file

@ -0,0 +1,9 @@
{% autoescape off %}
{% load static %}
{% load tex %}
\def\ucastnik{{resitel|sloz}}
\def\narozeni{ {% firstof ofresitel.osoba.datum_narozeni "\\TODO{datum narození, 1. 1. 2001}" %} }
\def\mistonar{\TODO{místo narození}}}
\def\body{{{body}} bodu}
\input{certifikat.tex}

View file

@ -0,0 +1,66 @@
{% autoescape off %}
{% load static %}
{% load tex %}
\def\rocnik{{rocnik.rocnik|sloz}}
\def\rok{ {{rocnik.prvni_rok}}/{{rocnik.prvni_rok|add:"1"}} }
\def\levypodpis{Mgr. Vladan Majerech, Dr.\\vedoucí KS M\&M}
\def\pravypodpis{doc. RNDr. Mirko Rokyta, CSc.\\děkan MFF UK}
\documentclass[landscape, 12pt]{article}
\usepackage{geometry}\geometry{a4paper,left=2cm,right=2cm,top=2cm,bottom=2cm}
\setlength\parskip{2em}
\pagestyle{empty}
\usepackage{graphicx}
\usepackage[czech]{babel}
\begin{document}
\centering
\Large
{\Huge
\includegraphics[width=0.45\textwidth]{mff-uk-logo.pdf}\\[1em]
uděluje osvědčení úspěšného řešitele\\
Korespondenčního semináře M\&M
\par}
{\normalsize jméno účastníka:} {\Huge \ucastnik}\\
{\normalsize datum narození:} \narozeni{\normalsize, místo narození:} \mistonar
Účastník v \rocnik. ročníku semináře (školní rok \rok) získal \body,\\
čímž se stal úspěšným řešitelem korespondenčního semináře.
\begin{minipage}[t]{0.25\textwidth}
{
\centering
\hrule
\vspace{4pt}
\normalsize\levypodpis
\par
}
\end{minipage}
\begin{minipage}[b]{0.3\textwidth}
\centering
\includegraphics[width=0.8\textwidth]{logomm-new.pdf}
\par
\end{minipage}
\begin{minipage}[t]{0.25\textwidth}
{
\centering
\hrule
\vspace{4pt}
\normalsize\pravypodpis
\par
}
\end{minipage}
\vspace{1em}
%{\vbox to 0pt{\hbox to \textwidth{\hfill\includegraphics[height=2.5em]{jcmf.pdf}}\vskip 0pt minus 1fill}\setlength\parskip{0pt}\noindent}
{\normalsize
Korespondenční seminář M\&M organizují převážně studenti Matematicko-fyzikální fakulty Univerzity Karlovy.\\
% Organizaci semináře a vydávání časopisu podporuje Jednota českých matematiků a fyziků.
\par}
\end{document}

View file

@ -36,6 +36,11 @@ urlpatterns = [
org_required(views.resiteleRocnikuCsvExportView),
name='tvorba_rocnik_resitele_csv'
),
path(
'rocnik/<int:rocnik>/certifikaty.tar.gz',
org_required(views.certifikatyExportView),
name='tvorba_rocnik_certifikaty'
),
path(
'rocnik/<int:rocnik>/tituly.tex',
org_required(views.TitulyViewRocnik),

View file

@ -13,6 +13,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
from personalni.models import Resitel
from soustredeni.models import Konfera
@ -34,6 +35,10 @@ from django.conf import settings
import unicodedata
import logging
import time
import http
import tempfile
import shutil
import subprocess
import personalni.views
@ -281,6 +286,51 @@ def resiteleRocnikuCsvExportView(request, rocnik):
)
)
def certifikatyExportView(request, rocnik):
rocnik = get_object_or_404(Rocnik, rocnik=rocnik)
id_a_body_resitelu: dict[int, int] = body_resitelu(
rocnik,
jen_verejne = False,
)
resitele_a_body = [(Resitel.objects.get(id=id), body) for id, body in id_a_body_resitelu.items() if body > 100]
if len(resitele_a_body) == 0:
return HttpResponse(
render(request, 'universal.html', {
'title': 'Není pro koho vyrobit certifikáty.',
'text': 'Právě ses pokusil/a vygenerovat certifikáty úspěšných řešitelů pro prázdnou množinu lidí. Můžeš počkat až se vše oboduje, případně se zeptej webařů :-)',
}),
status=http.HTTPStatus.NOT_FOUND,
)
with tempfile.TemporaryDirectory() as tempdir:
shutil.copy(find("tvorba/logomm-new.pdf"), tempdir)
shutil.copy(find("tvorba/mff-uk-logo.pdf"), tempdir)
tex = render(request, "tvorba/archiv/rocnik_certifikat_part.tex", {
"rocnik": rocnik,
}).content
with open(tempdir+"/certifikat.tex", "w") as texfile:
texfile.write(tex.decode())
files = ["tvorba/logomm-new.pdf", "tvorba/mff-uk-logo.pdf", "certifikat.tex"]
for r, b in resitele_a_body:
tex = render(request, "tvorba/archiv/rocnik_certifikat.tex", {
"resitel": r,
"body": b,
}).content
with open(tempdir+"/certifikat.tex", "w") as texfile:
texfile.write(tex.decode())
subprocess.call(["pdflatex", "certifikat.tex"], cwd=tempdir)
shutil.move(tempdir+"/certifikat.pdf", f"{tempdir}/{r}.pdf")
files.append(f"{r}.pdf")
subprocess.call(["tar", "-czf", "certifikaty.tar.gz", *files], cwd=tempdir)
with open(tempdir+"/certifikaty.tar.gz", "rb") as pdffile:
response = HttpResponse(pdffile.read(), content_type='application/gzip')
return response
# FIXME: Pozor, výš je ještě jeden ProblemView!
#class ProblemView(generic.DetailView):