Added admin view to zip and download resumes for a particular application

This commit is contained in:
Eshwar 2024-06-19 22:22:41 +05:30
parent c95c3bb631
commit 0be1a6c56e
3 changed files with 41 additions and 0 deletions

View File

@ -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"),

View File

@ -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])

View File

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