From 119fbe17cdc5c597a27beb64db622903a2a456f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Mih=C3=A1lik?= Date: Sat, 9 Dec 2023 21:18:48 +0100 Subject: [PATCH] Added user uploaded solution size limit --- competition/views.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/competition/views.py b/competition/views.py index 694cdc80..52c37345 100644 --- a/competition/views.py +++ b/competition/views.py @@ -252,10 +252,17 @@ def upload_solution(self, request, pk=None): detail='Túto úlohu už nie je možné odovzdať.') event_registration = EventRegistration.get_registration_by_profile_and_event( request.user.profile, problem.series.semester) + if 'file' not in request.FILES: raise exceptions.ParseError(detail='Request neobsahoval súbor') file = request.FILES['file'] + + if file.size > 20971520: # 20 MB + raise exceptions.ParseError( + detail='Riešenie prekročilo maximálnu povolenú veľkosť', + ) + if mime_type(file) != 'application/pdf': raise exceptions.ParseError( detail='Riešenie nie je vo formáte pdf')