1
0
mirror of https://gitlab.com/animath/si/plateforme.git synced 2025-06-21 11:18:27 +02:00

Display scholarship attestation

This commit is contained in:
Yohann D'ANELLO
2021-01-18 23:39:02 +01:00
parent 40fd5a56c1
commit 96adb01edb
4 changed files with 56 additions and 16 deletions

View File

@ -130,6 +130,13 @@
<i class="fas fa-money-bill-wave"></i> {% trans "Update payment" %}
</button>
{% endif %}
{% if user_object.registration.payment.type == "scholarship" %}
{% if user.registration.is_admin or user == user_object %}
<a href="{{ user_object.registration.payment.scholarship_file.url }}" class="btn btn-info" data-turbolinks="false">
<i class="fas fa-file-pdf"></i> {% trans "Download scholarship attestation" %}
</a>
{% endif %}
{% endif %}
{% endwith %}
</dd>
</dl>

View File

@ -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.