From c826dd92cb898bb1095ed55bdc34fabbc7239c7d Mon Sep 17 00:00:00 2001 From: karthik murakonda Date: Tue, 17 May 2022 22:10:38 +0530 Subject: [PATCH] added getstudentapplication and editstudentapplication endpoints - for admin views --- CDC_Backend/APIs/adminUrls.py | 2 + CDC_Backend/APIs/adminViews.py | 56 +++++++++++++++++++ .../templates/company_jnf_response.html | 2 +- 3 files changed, 59 insertions(+), 1 deletion(-) diff --git a/CDC_Backend/APIs/adminUrls.py b/CDC_Backend/APIs/adminUrls.py index 71d0073..0bbd5bc 100644 --- a/CDC_Backend/APIs/adminUrls.py +++ b/CDC_Backend/APIs/adminUrls.py @@ -13,4 +13,6 @@ urlpatterns = [ path("submitApplication/", adminViews.submitApplication, name="Submit Application"), path('generateCSV/', adminViews.generateCSV, name="Generate CSV"), path('addPPO/', adminViews.addPPO, name="Add PPO"), + path('getstudentapplication/', adminViews.getstudentapplication, name="Get student application"), + path('editstudentapplication/', adminViews.addstudentapplication, name="Edit student application"), ] diff --git a/CDC_Backend/APIs/adminViews.py b/CDC_Backend/APIs/adminViews.py index e01d26e..0a77b05 100644 --- a/CDC_Backend/APIs/adminViews.py +++ b/CDC_Backend/APIs/adminViews.py @@ -1,4 +1,5 @@ import csv +from email.mime import application from rest_framework.decorators import api_view @@ -334,3 +335,58 @@ def addPPO(request, id, email, user_type): print(sys.exc_info()) return Response({'action': "Add PPO", 'message': "Error Occurred"}, status=status.HTTP_400_BAD_REQUEST) + +@api_view(['POST']) +@isAuthorized(allowed_users=[ADMIN]) +@precheck(required_data=[STUDENT_ID, OPENING_ID]) +def getstudentapplication(request, id, email, user_type): + try: + data = request.data + student = get_object_or_404(Student, id=data[STUDENT_ID]) + # search for the application if there or not + application = PlacementApplication.objects.filter(student=student, placement=get_object_or_404(Placement, id=data[OPENING_ID])) + logger.info("Get Student Application: " + str(application)) + if application: + serializer = PlacementApplicationSerializer(application[0]) + return Response({'action': "Get Student Application", 'found': "true",'application_id': serializer.data["id"] , 'application_additionalInfo': serializer.data[ADDITIONAL_INFO],"available_resumes":student.resumes}, + status=status.HTTP_200_OK) + else: + return Response({'action': "Get Student Application", 'found': "false", "available_resumes": student.resumes}, + status=status.HTTP_200_OK) + except: + logger.warning("Get Student Application: " + str(sys.exc_info())) + print(sys.exc_info()) + return Response({'action': "Get Student Application", 'message': "Student with given roll number not found."}, status.HTTP_400_BAD_REQUEST) + + +@api_view(['POST']) +@isAuthorized(allowed_users=[ADMIN]) +@precheck(required_data=[APPLICATION_ID,STUDENT_ID,OPENING_ID,ADDITIONAL_INFO,RESUME_FILE_NAME]) +def addstudentapplication(request, id, email, user_type): + try: + data = request.data + if data[APPLICATION_ID] == "": + application = PlacementApplication() + application.id = generateRandomString() + application.placement = get_object_or_404(Placement, id=data[OPENING_ID]) + application.student = get_object_or_404(Student, id=data[STUDENT_ID]) + application.resume = data[RESUME_FILE_NAME] + application.additional_info = json.dumps(data[ADDITIONAL_INFO]) + application.save() + return Response({'action': "Add Student Application", 'message': "Application added"}, + status=status.HTTP_200_OK) + else: + application = get_object_or_404(PlacementApplication, id=data[APPLICATION_ID]) + if application: + application.resume = data[RESUME_FILE_NAME] + application.additional_info = json.dumps(data[ADDITIONAL_INFO]) + application.save() + return Response({'action': "Add Student Application", 'message': "Application updated"}, + status=status.HTTP_200_OK) + else: + return Response({'action': "Edit Student Application", 'message': "No Application Found"}, + status=status.HTTP_400_BAD_REQUEST) + + except: + logger.warning("Edit Student Application: " + str(sys.exc_info())) + print(sys.exc_info()) \ No newline at end of file diff --git a/CDC_Backend/templates/company_jnf_response.html b/CDC_Backend/templates/company_jnf_response.html index 93fd488..6e7191c 100644 --- a/CDC_Backend/templates/company_jnf_response.html +++ b/CDC_Backend/templates/company_jnf_response.html @@ -27,7 +27,7 @@ Document - +
cdc logo