From f04c867329700c703167c4408b28f674992e80c0 Mon Sep 17 00:00:00 2001 From: karthik murakonda Date: Tue, 24 May 2022 01:23:29 +0530 Subject: [PATCH] made refractorings --- CDC_Backend/APIs/adminUrls.py | 2 +- CDC_Backend/APIs/adminViews.py | 30 +++++++++++++++++++++--------- CDC_Backend/APIs/models.py | 2 +- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/CDC_Backend/APIs/adminUrls.py b/CDC_Backend/APIs/adminUrls.py index f83850a..90d9c71 100644 --- a/CDC_Backend/APIs/adminUrls.py +++ b/CDC_Backend/APIs/adminUrls.py @@ -13,5 +13,5 @@ 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('getStudentApplication/', adminViews.getStudentApplication, name="Get student application"), ] diff --git a/CDC_Backend/APIs/adminViews.py b/CDC_Backend/APIs/adminViews.py index 4c81893..c1aa325 100644 --- a/CDC_Backend/APIs/adminViews.py +++ b/CDC_Backend/APIs/adminViews.py @@ -338,25 +338,37 @@ def addPPO(request, id, email, user_type): @api_view(['POST']) @isAuthorized(allowed_users=[ADMIN]) @precheck(required_data=[STUDENT_ID, OPENING_ID]) -def getstudentapplication(request, id, email, user_type): +def getStudentApplication(request, id, email, user_type): try: data = request.data student = get_object_or_404(Student, id=data[STUDENT_ID]) student_serializer = StudentSerializer(student) + student_details = { + "name": student_serializer.data['name'], + "batch": student.batch, + "branch": student.branch, + "resume_list": student_serializer.data['resume_list'], + } # 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_serializer.data["resume_list"], - "student_name":student.name, "student_branch":student.branch, "student_batch":student.batch, "resume":serializer.data["resume_link"]}, - status=status.HTTP_200_OK) + application_info = { + "id": serializer.data['id'], + "additional_info": serializer.data['additional_info'], + "resume": serializer.data['resume'], + } + return Response({'action': "Get Student Application", 'application_found': "true", "application_info": application_info, + "student_details":student_details }, status=status.HTTP_200_OK) else: - return Response({'action': "Get Student Application", 'found': "false", "available_resumes": student_serializer.data["resume_list"], - "student_name":student.name, "student_branch":student.branch, "student_batch":student.batch}, - status=status.HTTP_200_OK) - except: + return Response({'action': "Get Student Application", 'application_found': "false", "student_details": student_details}, + status=status.HTTP_404_NOT_FOUND) + except Http404: 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) + except: + logger.warning("Get Student Application: " + str(sys.exc_info())) + print(sys.exc_info()) + return Response({'action': "Get Student Application", 'message': "Some error Occurred"}, status.HTTP_500_INTERNAL_SERVER_ERROR) diff --git a/CDC_Backend/APIs/models.py b/CDC_Backend/APIs/models.py index 4d47bf0..3530aab 100644 --- a/CDC_Backend/APIs/models.py +++ b/CDC_Backend/APIs/models.py @@ -132,7 +132,7 @@ class Placement(models.Model): self.selection_procedure_details = self.selection_procedure_details.strip()[:JNF_TEXTAREA_MAX_CHARACTER_COUNT] self.bond_details = self.bond_details.strip()[:JNF_TEXTAREA_MAX_CHARACTER_COUNT] self.other_requirements = self.other_requirements.strip()[:JNF_TEXTAREA_MAX_CHARACTER_COUNT] - self.additinal_info = [info.strip()[:JNF_TEXTMEDIUM_MAX_CHARACTER_COUNT] for info in self.additional_info] + self.additional_info = [info.strip()[:JNF_TEXTMEDIUM_MAX_CHARACTER_COUNT] for info in self.additional_info] def save(self, *args, **kwargs): ''' On save, add timestamps '''