mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-07-04 04:12:08 +02:00
Generate authorization templates as PDF
This commit is contained in:
@ -2,6 +2,8 @@
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
from tempfile import mkdtemp
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
@ -21,7 +23,7 @@ from django.utils.translation import gettext_lazy as _
|
||||
from django.views.generic import CreateView, DetailView, RedirectView, TemplateView, UpdateView, View
|
||||
from django_tables2 import SingleTableView
|
||||
from magic import Magic
|
||||
from participation.models import Passage, Solution, Synthesis
|
||||
from participation.models import Passage, Solution, Synthesis, Tournament
|
||||
from tfjm.tokens import email_validation_token
|
||||
from tfjm.views import AdminMixin, UserMixin, VolunteerMixin
|
||||
|
||||
@ -381,6 +383,52 @@ class UserUploadParentalAuthorizationView(UserMixin, UpdateView):
|
||||
return reverse_lazy("registration:user_detail", args=(self.object.user.pk,))
|
||||
|
||||
|
||||
class AuthorizationTemplateView(TemplateView):
|
||||
def get_context_data(self, **kwargs):
|
||||
context = super().get_context_data(**kwargs)
|
||||
|
||||
if "registration_id" in self.request.GET:
|
||||
registration = Registration.objects.get(pk=self.request.GET.get("registration_id"))
|
||||
# Don't get unwanted information
|
||||
if registration.user == self.request.user \
|
||||
or self.request.user.is_authenticated and self.request.user.registration.is_admin:
|
||||
context["registration"] = registration
|
||||
if "tournament_id" in self.request.GET:
|
||||
context["tournament"] = Tournament.objects.get(pk=self.request.GET.get("tournament_id"))
|
||||
else:
|
||||
raise ValueError("Merci d'indiquer un tournoi.")
|
||||
|
||||
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(open(os.path.join(temp_dir, "texput.pdf"), "rb"),
|
||||
content_type="application/pdf",
|
||||
filename=self.template_name.split("/")[-1][:-3] + "pdf")
|
||||
|
||||
|
||||
class AdultPhotoAuthorizationTemplateView(AuthorizationTemplateView):
|
||||
template_name = "registration/tex/Autorisation_droit_image_majeur.tex"
|
||||
|
||||
|
||||
class ChildPhotoAuthorizationTemplateView(AuthorizationTemplateView):
|
||||
template_name = "registration/tex/Autorisation_droit_image_mineur.tex"
|
||||
|
||||
|
||||
class ParentalAuthorizationTemplateView(AuthorizationTemplateView):
|
||||
template_name = "registration/tex/Autorisation_parentale.tex"
|
||||
|
||||
|
||||
class InstructionsTemplateView(AuthorizationTemplateView):
|
||||
template_name = "registration/tex/Instructions.tex"
|
||||
|
||||
|
||||
class PaymentUpdateView(LoginRequiredMixin, UpdateView):
|
||||
model = Payment
|
||||
form_class = PaymentForm
|
||||
|
Reference in New Issue
Block a user