Display solutions and syntheses
This commit is contained in:
parent
ead59e28b8
commit
e51674e76c
|
@ -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.
|
||||
|
|
|
@ -21,7 +21,8 @@ from django.contrib import admin
|
|||
from django.urls import include, path
|
||||
from django.views.defaults import bad_request, page_not_found, permission_denied, server_error
|
||||
from django.views.generic import TemplateView
|
||||
from registration.views import HealthSheetView, ParentalAuthorizationView, PhotoAuthorizationView
|
||||
from registration.views import HealthSheetView, ParentalAuthorizationView, PhotoAuthorizationView, \
|
||||
SolutionView, SynthesisView
|
||||
|
||||
from .views import AdminSearchView
|
||||
|
||||
|
@ -45,6 +46,11 @@ urlpatterns = [
|
|||
path('media/authorization/parental/<str:filename>/', ParentalAuthorizationView.as_view(),
|
||||
name='parental_authorization'),
|
||||
|
||||
path('media/solutions/<str:filename>/', SolutionView.as_view(),
|
||||
name='solution'),
|
||||
path('media/syntheses/<str:filename>/', SynthesisView.as_view(),
|
||||
name='synthesis'),
|
||||
|
||||
path('', include('eastereggs.urls')),
|
||||
]
|
||||
|
||||
|
|
Loading…
Reference in New Issue