mirror of
https://gitlab.com/animath/si/plateforme.git
synced 2025-08-19 16:08:42 +02:00
Display scholarship attestation
This commit is contained in:
@@ -474,6 +474,28 @@ class ParentalAuthorizationView(LoginRequiredMixin, View):
|
||||
return FileResponse(open(path, "rb"), content_type=mime_type, filename=true_file_name)
|
||||
|
||||
|
||||
class ScholarshipView(LoginRequiredMixin, View):
|
||||
"""
|
||||
Display the sent scholarship paper.
|
||||
"""
|
||||
def get(self, request, *args, **kwargs):
|
||||
filename = kwargs["filename"]
|
||||
path = f"media/authorization/scholarship/{filename}"
|
||||
if not os.path.exists(path):
|
||||
raise Http404
|
||||
payment = Payment.objects.get(scholarship_file__endswith=filename)
|
||||
user = request.user
|
||||
if not (payment.registration.user == user or user.registration.is_admin):
|
||||
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 = _("Scholarship attestation of {user}.{ext}").format(user=str(user.registration), ext=ext)
|
||||
return FileResponse(open(path, "rb"), content_type=mime_type, filename=true_file_name)
|
||||
|
||||
|
||||
class SolutionView(LoginRequiredMixin, View):
|
||||
"""
|
||||
Display the sent solution.
|
||||
|
Reference in New Issue
Block a user