consolidated code
This commit is contained in:
parent
ed6f313b68
commit
7ccac2a2f2
|
@ -311,13 +311,19 @@ def submitApplication(request, id, email, user_type):
|
||||||
opening_type= data[OPENING_TYPE]
|
opening_type= data[OPENING_TYPE]
|
||||||
else:
|
else:
|
||||||
opening_type= "Placement"
|
opening_type= "Placement"
|
||||||
student = get_object_or_404(Student, pk=data[STUDENT_ID])
|
|
||||||
if opening_type == "Internship":
|
if opening_type == "Internship":
|
||||||
opening = get_object_or_404(Internship, pk=data[OPENING_ID])
|
opening = get_object_or_404(Internship, pk=data[OPENING_ID])
|
||||||
|
else:
|
||||||
|
opening = get_object_or_404(Placement, pk=data[OPENING_ID])
|
||||||
|
student = get_object_or_404(Student, pk=data[STUDENT_ID])
|
||||||
|
# opening = get_object_or_404(Placement, pk=data[OPENING_ID])
|
||||||
student_user = get_object_or_404(User, id=student.id)
|
student_user = get_object_or_404(User, id=student.id)
|
||||||
if data[APPLICATION_ID] == "":
|
if data[APPLICATION_ID] == "":
|
||||||
application = InternshipApplication()
|
application = PlacementApplication() if opening_type == "Placement" else InternshipApplication()
|
||||||
application.id = generateRandomString()
|
application.id = generateRandomString()
|
||||||
|
if(opening_type == "Placement"):
|
||||||
|
application.placement = opening
|
||||||
|
else:
|
||||||
application.internship = opening
|
application.internship = opening
|
||||||
application.student = student
|
application.student = student
|
||||||
if data[RESUME_FILE_NAME] in student.resumes:
|
if data[RESUME_FILE_NAME] in student.resumes:
|
||||||
|
@ -334,70 +340,7 @@ def submitApplication(request, id, email, user_type):
|
||||||
data = {
|
data = {
|
||||||
"name": student.name,
|
"name": student.name,
|
||||||
"company_name": opening.company_name,
|
"company_name": opening.company_name,
|
||||||
"application_type": "Internship",
|
"application_type": "Placement" if opening_type == "Placement" else "Internship",
|
||||||
"additional_info": dict(json.loads(application.additional_info)),
|
|
||||||
}
|
|
||||||
subject = STUDENT_APPLICATION_SUBMITTED_TEMPLATE_SUBJECT.format(company_name=opening.company_name)
|
|
||||||
application.changed_by = get_object_or_404(User, id=id)
|
|
||||||
application.save()
|
|
||||||
sendEmail(student_user.email, subject, data, STUDENT_APPLICATION_SUBMITTED_TEMPLATE)
|
|
||||||
return Response({'action': "Add Student Application", 'message': "Application added For Internship"},
|
|
||||||
status=status.HTTP_200_OK)
|
|
||||||
else:
|
|
||||||
application = get_object_or_404(InternshipApplication, id=data[APPLICATION_ID])
|
|
||||||
if application:
|
|
||||||
if data[RESUME_FILE_NAME] in student.resumes:
|
|
||||||
application.resume = data[RESUME_FILE_NAME]
|
|
||||||
else:
|
|
||||||
raise FileNotFoundError(RESUME_FILE_NAME + " Not Found")
|
|
||||||
application.resume = data[RESUME_FILE_NAME]
|
|
||||||
additional_info = {}
|
|
||||||
for i in opening.additional_info:
|
|
||||||
if i not in data[ADDITIONAL_INFO]:
|
|
||||||
raise AttributeError(i + " not found in Additional Info")
|
|
||||||
else:
|
|
||||||
additional_info[i] = data[ADDITIONAL_INFO][i]
|
|
||||||
|
|
||||||
application.additional_info = json.dumps(additional_info)
|
|
||||||
data = {
|
|
||||||
"name": student.name,
|
|
||||||
"company_name": opening.company_name,
|
|
||||||
"application_type": "Internship",
|
|
||||||
"resume": application.resume[16:],
|
|
||||||
"additional_info_items": dict(json.loads(application.additional_info)),
|
|
||||||
}
|
|
||||||
subject = STUDENT_APPLICATION_UPDATED_TEMPLATE_SUBJECT.format(company_name=opening.company_name)
|
|
||||||
application.changed_by = get_object_or_404(User, id=id)
|
|
||||||
application.save()
|
|
||||||
sendEmail(student_user.email, subject, data, STUDENT_APPLICATION_UPDATED_TEMPLATE)
|
|
||||||
return Response({'action': "Add Student Application", 'message': "Application updated For Internship"},
|
|
||||||
status=status.HTTP_200_OK)
|
|
||||||
else:
|
|
||||||
return Response({'action': "Edit Student Application", 'message': "No Application Found For Internship"},
|
|
||||||
status=status.HTTP_400_BAD_REQUEST)
|
|
||||||
else:
|
|
||||||
opening = get_object_or_404(Placement, pk=data[OPENING_ID])
|
|
||||||
student_user = get_object_or_404(User, id=student.id)
|
|
||||||
if data[APPLICATION_ID] == "":
|
|
||||||
application = PlacementApplication()
|
|
||||||
application.id = generateRandomString()
|
|
||||||
application.placement = opening
|
|
||||||
application.student = student
|
|
||||||
if data[RESUME_FILE_NAME] in student.resumes:
|
|
||||||
application.resume = data[RESUME_FILE_NAME]
|
|
||||||
else:
|
|
||||||
raise FileNotFoundError(RESUME_FILE_NAME + " Not Found")
|
|
||||||
additional_info = {}
|
|
||||||
for i in opening.additional_info:
|
|
||||||
if i not in data[ADDITIONAL_INFO]:
|
|
||||||
raise AttributeError(i + " not found in Additional Info")
|
|
||||||
else:
|
|
||||||
additional_info[i] = data[ADDITIONAL_INFO][i]
|
|
||||||
application.additional_info = json.dumps(additional_info)
|
|
||||||
data = {
|
|
||||||
"name": student.name,
|
|
||||||
"company_name": opening.company_name,
|
|
||||||
"application_type": "Placement",
|
|
||||||
"additional_info": dict(json.loads(application.additional_info)),
|
"additional_info": dict(json.loads(application.additional_info)),
|
||||||
}
|
}
|
||||||
subject = STUDENT_APPLICATION_SUBMITTED_TEMPLATE_SUBJECT.format(company_name=opening.company_name)
|
subject = STUDENT_APPLICATION_SUBMITTED_TEMPLATE_SUBJECT.format(company_name=opening.company_name)
|
||||||
|
@ -406,6 +349,9 @@ def submitApplication(request, id, email, user_type):
|
||||||
sendEmail(student_user.email, subject, data, STUDENT_APPLICATION_SUBMITTED_TEMPLATE)
|
sendEmail(student_user.email, subject, data, STUDENT_APPLICATION_SUBMITTED_TEMPLATE)
|
||||||
return Response({'action': "Add Student Application", 'message': "Application added"},
|
return Response({'action': "Add Student Application", 'message': "Application added"},
|
||||||
status=status.HTTP_200_OK)
|
status=status.HTTP_200_OK)
|
||||||
|
else:
|
||||||
|
if opening_type == "Internship":
|
||||||
|
application = get_object_or_404(InternshipApplication, id=data[APPLICATION_ID])
|
||||||
else:
|
else:
|
||||||
application = get_object_or_404(PlacementApplication, id=data[APPLICATION_ID])
|
application = get_object_or_404(PlacementApplication, id=data[APPLICATION_ID])
|
||||||
if application:
|
if application:
|
||||||
|
@ -425,7 +371,7 @@ def submitApplication(request, id, email, user_type):
|
||||||
data = {
|
data = {
|
||||||
"name": student.name,
|
"name": student.name,
|
||||||
"company_name": opening.company_name,
|
"company_name": opening.company_name,
|
||||||
"application_type": "Placement",
|
"application_type": "Placement" if opening_type == "Placement" else "Internship",
|
||||||
"resume": application.resume[16:],
|
"resume": application.resume[16:],
|
||||||
"additional_info_items": dict(json.loads(application.additional_info)),
|
"additional_info_items": dict(json.loads(application.additional_info)),
|
||||||
}
|
}
|
||||||
|
@ -453,7 +399,6 @@ def submitApplication(request, id, email, user_type):
|
||||||
return Response({'action': "Submit Application", 'message': "Something Went Wrong"},
|
return Response({'action': "Submit Application", 'message': "Something Went Wrong"},
|
||||||
status=status.HTTP_400_BAD_REQUEST)
|
status=status.HTTP_400_BAD_REQUEST)
|
||||||
|
|
||||||
|
|
||||||
@api_view(['POST'])
|
@api_view(['POST'])
|
||||||
@isAuthorized(allowed_users=[ADMIN])
|
@isAuthorized(allowed_users=[ADMIN])
|
||||||
@precheck(required_data=[OPENING_ID])
|
@precheck(required_data=[OPENING_ID])
|
||||||
|
|
Loading…
Reference in New Issue