From 0be1a6c56ef1b7621b119f98fda2d72e2df1bfe3 Mon Sep 17 00:00:00 2001 From: Eshwar Date: Wed, 19 Jun 2024 22:22:41 +0530 Subject: [PATCH 1/2] Added admin view to zip and download resumes for a particular application --- CDC_Backend/APIs/adminUrls.py | 1 + CDC_Backend/APIs/adminViews.py | 38 ++++++++++++++++++++++++++++++++++ CDC_Backend/APIs/constants.py | 2 ++ 3 files changed, 41 insertions(+) diff --git a/CDC_Backend/APIs/adminUrls.py b/CDC_Backend/APIs/adminUrls.py index 5afb5c7..0ff5f69 100644 --- a/CDC_Backend/APIs/adminUrls.py +++ b/CDC_Backend/APIs/adminUrls.py @@ -13,6 +13,7 @@ urlpatterns = [ path('getApplications/', adminViews.getApplications, name="Get Applications"), path("submitApplication/", adminViews.submitApplication, name="Submit Application"), path('generateCSV/', adminViews.generateCSV, name="Generate CSV"), + path('downloadResume/', adminViews.downloadResume, name="Download Resume"), path('addPPO/', adminViews.addPPO, name="Add PPO"), path('getStudentApplication/', adminViews.getStudentApplication, name="Get student application"), path('getStats/', adminViews.getStats, name="Get Stats"), diff --git a/CDC_Backend/APIs/adminViews.py b/CDC_Backend/APIs/adminViews.py index 7cb4888..dd29042 100644 --- a/CDC_Backend/APIs/adminViews.py +++ b/CDC_Backend/APIs/adminViews.py @@ -1,4 +1,5 @@ import csv +import zipfile from rest_framework.decorators import api_view @@ -458,6 +459,43 @@ def generateCSV(request, id, email, user_type): status=status.HTTP_400_BAD_REQUEST) +@api_view(['POST']) +@isAuthorized(allowed_users=[ADMIN]) +@precheck(required_data=[OPENING_ID]) +def downloadResume(request, id, email, user_type): + try: + data = request.data + if OPENING_TYPE in data: + opening_type= data[OPENING_TYPE] + else: + opening_type= "Placement" + if opening_type == "Internship": + opening = get_object_or_404(Internship, id=data[OPENING_ID]) + applications = InternshipApplication.objects.filter(internship=opening) + else: + opening = get_object_or_404(Placement, id=data[OPENING_ID]) + applications = PlacementApplication.objects.filter(placement=opening) + zip_filename = generateRandomString() + ".zip" + if not os.path.isdir(STORAGE_DESTINATION_RESUME_ZIP): + os.makedirs(STORAGE_DESTINATION_RESUME_ZIP, exist_ok=True) + resumes = {} + for apl in applications: + resumes[apl.student.roll_no] = STORAGE_DESTINATION_RESUMES + apl.student.id + '/' + apl.resume # Check if the folder name is student id or user id + + print("Resumes: ", resumes) + with zipfile.ZipFile(STORAGE_DESTINATION_RESUME_ZIP + zip_filename, 'w', zipfile.ZIP_DEFLATED) as zip_file: + for student_roll_no, resume_path in resumes.items(): + zip_file.write(resume_path, os.path.basename(str(student_roll_no) + ".pdf")) + + file_path = LINK_TO_RESUMES_ZIP + urllib.parse.quote_plus(zip_filename) + return Response({'action': "Download resumes", 'message': "Resumes zip created", 'file': file_path}, + status=status.HTTP_200_OK) + except: + logger.warning("Create csv: " + str(sys.exc_info())) + return Response({'action': "Create csv", 'message': "Something Went Wrong"}, + status=status.HTTP_400_BAD_REQUEST) + + @api_view(['POST']) @isAuthorized(allowed_users=[ADMIN]) @precheck(required_data=[COMPANY_NAME, COMPENSATION_GROSS, OFFER_ACCEPTED, STUDENT_ID, DESIGNATION, TIER]) diff --git a/CDC_Backend/APIs/constants.py b/CDC_Backend/APIs/constants.py index 51864db..19e1f3b 100644 --- a/CDC_Backend/APIs/constants.py +++ b/CDC_Backend/APIs/constants.py @@ -88,6 +88,7 @@ PLACEMENT_OPENING_URL = "https://cdc.iitdh.ac.in/portal/student/dashboard/placem LINK_TO_STORAGE_COMPANY_ATTACHMENT = "https://cdc.iitdh.ac.in/storage/Company_Attachments/" LINK_TO_STORAGE_RESUME = "https://cdc.iitdh.ac.in/storage/Resumes/" LINK_TO_APPLICATIONS_CSV = "https://cdc.iitdh.ac.in/storage/Application_CSV/" +LINK_TO_RESUMES_ZIP = "https://cdc.iitdh.ac.in/storage/Resume_Zips/" LINK_TO_EMAIl_VERIFICATION_API = "https://cdc.iitdh.ac.in/portal/company/verifyEmail?token={token}" PDF_FILES_SERVING_ENDPOINT = 'https://cdc.iitdh.ac.in/storage/Company_Attachments/' # TODO: Change this to actual URL @@ -115,6 +116,7 @@ JNF_SMALLTEXT_MAX_CHARACTER_COUNT = 50 STORAGE_DESTINATION_RESUMES = "./Storage/Resumes/" STORAGE_DESTINATION_COMPANY_ATTACHMENTS = './Storage/Company_Attachments/' STORAGE_DESTINATION_APPLICATION_CSV = './Storage/Application_CSV/' +STORAGE_DESTINATION_RESUME_ZIP = './Storage/Resume_Zips/' TOKEN = 'token' RESUME_FILE_NAME = 'resume_file_name' From dcb85afea4557be2a2f93019c49a516bbdbb6b62 Mon Sep 17 00:00:00 2001 From: Eshwar Date: Wed, 19 Jun 2024 22:34:06 +0530 Subject: [PATCH 2/2] Changed it so that only selected student's resumes get downloaded --- CDC_Backend/APIs/adminViews.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CDC_Backend/APIs/adminViews.py b/CDC_Backend/APIs/adminViews.py index dd29042..5d724f5 100644 --- a/CDC_Backend/APIs/adminViews.py +++ b/CDC_Backend/APIs/adminViews.py @@ -480,9 +480,9 @@ def downloadResume(request, id, email, user_type): os.makedirs(STORAGE_DESTINATION_RESUME_ZIP, exist_ok=True) resumes = {} for apl in applications: - resumes[apl.student.roll_no] = STORAGE_DESTINATION_RESUMES + apl.student.id + '/' + apl.resume # Check if the folder name is student id or user id + if apl.selected: + resumes[apl.student.roll_no] = STORAGE_DESTINATION_RESUMES + apl.student.id + '/' + apl.resume # Check if the folder name is student id or user id - print("Resumes: ", resumes) with zipfile.ZipFile(STORAGE_DESTINATION_RESUME_ZIP + zip_filename, 'w', zipfile.ZIP_DEFLATED) as zip_file: for student_roll_no, resume_path in resumes.items(): zip_file.write(resume_path, os.path.basename(str(student_roll_no) + ".pdf"))