1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-06-24 03:08:52 +02:00

Add notation sheets templates that are autocompleted with the data

Signed-off-by: Emmy D'Anello <emmy.danello@animath.fr>
This commit is contained in:
Emmy D'Anello
2023-04-06 23:38:03 +02:00
parent ae62e3daf7
commit 5f09c35dee
6 changed files with 378 additions and 104 deletions

View File

@ -4,6 +4,8 @@
import csv
from io import BytesIO
import os
import subprocess
from tempfile import mkdtemp
from zipfile import ZipFile
from django.conf import settings
@ -818,6 +820,41 @@ class PoolUploadNotesView(VolunteerMixin, FormView, DetailView):
return reverse_lazy('participation:pool_detail', args=(self.kwargs['pk'],))
class NotationSheetTemplateView(VolunteerMixin, DetailView):
"""
Generate a PDF from a LaTeX template for the notation papers.
"""
model = Pool
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context['esp'] = self.object.passages.count() * '&'
context['is_jury'] = self.request.user.registration in self.object.juries.all() \
and 'blank' not in self.request.GET
context['tfjm_number'] = timezone.now().year - 2010
return context
def render_to_response(self, context, **response_kwargs):
tex = render_to_string(self.template_name, context=context, request=self.request)
temp_dir = mkdtemp()
with open(os.path.join(temp_dir, "texput.tex"), "w") as f:
f.write(tex)
process = subprocess.Popen(["pdflatex", "-interaction=nonstopmode", f"-output-directory={temp_dir}",
os.path.join(temp_dir, "texput.tex"), ])
process.wait()
return FileResponse(streaming_content=open(os.path.join(temp_dir, "texput.pdf"), "rb"),
content_type="application/pdf",
filename=self.template_name.split("/")[-1][:-3] + "pdf")
class ScaleNotationSheetTemplateView(NotationSheetTemplateView):
template_name = 'participation/tex/bareme.tex'
class FinalNotationSheetTemplateView(NotationSheetTemplateView):
template_name = 'participation/tex/finale.tex'
class PassageCreateView(VolunteerMixin, CreateView):
model = Passage
form_class = PassageForm