mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-06-21 23:58:24 +02:00
Display solutions and syntheses
This commit is contained in:
@ -16,6 +16,8 @@ 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 Solution, Synthesis
|
||||
from tfjm.tokens import email_validation_token
|
||||
from tfjm.views import AdminMixin, UserMixin
|
||||
|
||||
@ -341,6 +343,52 @@ class ParentalAuthorizationView(LoginRequiredMixin, View):
|
||||
return FileResponse(open(path, "rb"), content_type=mime_type, filename=true_file_name)
|
||||
|
||||
|
||||
class SolutionView(LoginRequiredMixin, View):
|
||||
"""
|
||||
Display the sent solution.
|
||||
"""
|
||||
def get(self, request, *args, **kwargs):
|
||||
filename = kwargs["filename"]
|
||||
path = f"media/solutions/{filename}"
|
||||
if not os.path.exists(path):
|
||||
raise Http404
|
||||
solution = Solution.objects.get(file__endswith=filename)
|
||||
# user = request.user
|
||||
# if False:
|
||||
# FIXME Check ACL
|
||||
# raise PermissionDenied
|
||||
# Guess mime type of the file
|
||||
mime = Magic(mime=True)
|
||||
mime_type = mime.from_file(path)
|
||||
ext = mime_type.split("/")[1].replace("jpeg", "jpg")
|
||||
# Replace file name
|
||||
true_file_name = str(solution) + f".{ext}"
|
||||
return FileResponse(open(path, "rb"), content_type=mime_type, filename=true_file_name)
|
||||
|
||||
|
||||
class SynthesisView(LoginRequiredMixin, View):
|
||||
"""
|
||||
Display the sent synthesis.
|
||||
"""
|
||||
def get(self, request, *args, **kwargs):
|
||||
filename = kwargs["filename"]
|
||||
path = f"media/syhntheses/{filename}"
|
||||
if not os.path.exists(path):
|
||||
raise Http404
|
||||
solution = Synthesis.objects.get(file__endswith=filename)
|
||||
# user = request.user
|
||||
# if False:
|
||||
# FIXME Check ACL
|
||||
# raise PermissionDenied
|
||||
# Guess mime type of the file
|
||||
mime = Magic(mime=True)
|
||||
mime_type = mime.from_file(path)
|
||||
ext = mime_type.split("/")[1].replace("jpeg", "jpg")
|
||||
# Replace file name
|
||||
true_file_name = str(solution) + f".{ext}"
|
||||
return FileResponse(open(path, "rb"), content_type=mime_type, filename=true_file_name)
|
||||
|
||||
|
||||
class UserImpersonateView(LoginRequiredMixin, RedirectView):
|
||||
"""
|
||||
An administrator can log in through this page as someone else, and act as this other person.
|
||||
|
Reference in New Issue
Block a user