From 02b6c10cc324d5ffa173a02054fab41f5567f9c3 Mon Sep 17 00:00:00 2001 From: Gowtham Sai <66207607+gowtham3105@users.noreply.github.com> Date: Thu, 4 Aug 2022 00:54:27 +0530 Subject: [PATCH] Limit Resumes per student --- CDC_Backend/APIs/constants.py | 1 + CDC_Backend/APIs/studentViews.py | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/CDC_Backend/APIs/constants.py b/CDC_Backend/APIs/constants.py index aeb26b1..faa35d1 100644 --- a/CDC_Backend/APIs/constants.py +++ b/CDC_Backend/APIs/constants.py @@ -54,6 +54,7 @@ TIER = 'tier' # To be Configured Properly FOURTH_YEAR = '2019' MAX_OFFERS_PER_STUDENT = 2 +MAX_RESUMES_PER_STUDENT =3 EMAIL_VERIFICATION_TOKEN_TTL = 48 # in hours JNF_TEXT_MAX_CHARACTER_COUNT = 100 JNF_TEXTMEDIUM_MAX_CHARACTER_COUNT = 200 diff --git a/CDC_Backend/APIs/studentViews.py b/CDC_Backend/APIs/studentViews.py index ccb25bf..0fbadd0 100644 --- a/CDC_Backend/APIs/studentViews.py +++ b/CDC_Backend/APIs/studentViews.py @@ -40,6 +40,9 @@ def addResume(request, id, email, user_type): student = get_object_or_404(Student, id=id) files = request.FILES + if len(student.resumes) >= MAX_RESUMES_PER_STUDENT: + raise PermissionError('Max Number of Resumes limit reached') + file = files['file'] destination_path = STORAGE_DESTINATION_RESUMES + str(student.roll_no) + "/" file_name = saveFile(file, destination_path) @@ -51,6 +54,9 @@ def addResume(request, id, email, user_type): except Http404: return Response({'action': "Upload Resume", 'message': 'Student Not Found'}, status=status.HTTP_404_NOT_FOUND) + except PermissionError: + return Response({'action': "Upload Resume", 'message': 'Max Number of Resumes limit reached'}, + status=status.HTTP_400_BAD_REQUEST) except: if path.exists(destination_path): logger.error("Upload Resume: Error in Saving Resume")