2021-10-15 20:47:23 +05:30
|
|
|
from rest_framework.decorators import api_view
|
|
|
|
|
|
|
|
from .serializers import *
|
|
|
|
from .utils import *
|
|
|
|
|
|
|
|
logger = logging.getLogger('db')
|
|
|
|
|
|
|
|
|
|
|
|
@api_view(['POST'])
|
|
|
|
@isAuthorized(allowed_users='*')
|
|
|
|
def login(request, id, email, user_type):
|
|
|
|
try:
|
|
|
|
return Response({'action': "Login", 'message': "Verified", "user_type": user_type},
|
|
|
|
status=status.HTTP_200_OK)
|
|
|
|
except:
|
2021-12-03 01:04:49 +05:30
|
|
|
return Response({'action': "Login", 'message': "Something Went Wrong"},
|
2021-10-15 20:47:23 +05:30
|
|
|
status=status.HTTP_400_BAD_REQUEST)
|
|
|
|
|
|
|
|
|
|
|
|
@api_view(['GET'])
|
|
|
|
@isAuthorized(allowed_users=[STUDENT])
|
|
|
|
def studentProfile(request, id, email, user_type):
|
|
|
|
try:
|
|
|
|
studentDetails = get_object_or_404(Student, id=id)
|
|
|
|
|
|
|
|
data = StudentSerializer(studentDetails).data
|
|
|
|
return Response({'action': "Student Profile", 'message': "Details Found", "details": data},
|
|
|
|
status=status.HTTP_200_OK)
|
|
|
|
except:
|
2021-12-03 01:04:49 +05:30
|
|
|
logger.warning("Student Profile: " + str(sys.exc_info()))
|
|
|
|
return Response({'action': "Student Profile", 'message': "Something Went Wrong"},
|
2021-10-15 20:47:23 +05:30
|
|
|
status=status.HTTP_400_BAD_REQUEST)
|
|
|
|
|
|
|
|
|
|
|
|
@api_view(['POST'])
|
|
|
|
@isAuthorized(allowed_users=[STUDENT])
|
|
|
|
def addResume(request, id, email, user_type):
|
|
|
|
destination_path = ""
|
|
|
|
try:
|
|
|
|
student = get_object_or_404(Student, id=id)
|
|
|
|
files = request.FILES
|
|
|
|
|
|
|
|
file = files['file']
|
2021-12-16 23:05:04 +05:30
|
|
|
destination_path = STORAGE_DESTINATION_RESUMES + str(student.roll_no) + "/"
|
2021-12-03 01:04:49 +05:30
|
|
|
file_name = saveFile(file, destination_path)
|
|
|
|
student.resumes.append(file_name)
|
2021-10-15 20:47:23 +05:30
|
|
|
|
|
|
|
student.save()
|
|
|
|
return Response({'action': "Upload Resume", 'message': "Resume Added"},
|
|
|
|
status=status.HTTP_200_OK)
|
|
|
|
except Http404:
|
|
|
|
return Response({'action': "Upload Resume", 'message': 'Student Not Found'},
|
|
|
|
status=status.HTTP_404_NOT_FOUND)
|
|
|
|
except:
|
|
|
|
if path.exists(destination_path):
|
|
|
|
logger.error("Upload Resume: Error in Saving Resume")
|
|
|
|
remove(destination_path)
|
|
|
|
else:
|
|
|
|
logger.warning("Upload Resume: " + str(sys.exc_info()))
|
2021-12-03 01:04:49 +05:30
|
|
|
return Response({'action': "Upload Resume", 'message': "Something Went Wrong"},
|
2021-10-15 20:47:23 +05:30
|
|
|
status=status.HTTP_400_BAD_REQUEST)
|
|
|
|
|
|
|
|
|
|
|
|
@api_view(['GET'])
|
|
|
|
@isAuthorized(allowed_users=[STUDENT])
|
|
|
|
def getDashboard(request, id, email, user_type):
|
|
|
|
try:
|
|
|
|
studentDetails = get_object_or_404(Student, id=id)
|
|
|
|
|
|
|
|
placements = Placement.objects.filter(allowed_batch__contains=[studentDetails.batch],
|
|
|
|
allowed_branch__contains=[studentDetails.branch],
|
2022-04-30 22:27:49 +05:30
|
|
|
deadline_datetime__gte=datetime.datetime.now(),
|
2022-05-02 17:16:56 +05:30
|
|
|
offer_accepted=True, email_verified=True).order_by('deadline_datetime')
|
2021-12-03 01:04:49 +05:30
|
|
|
placementsdata = PlacementSerializerForStudent(placements, many=True).data
|
2021-10-15 20:47:23 +05:30
|
|
|
placementApplications = PlacementApplication.objects.filter(student_id=id)
|
|
|
|
placementApplications = PlacementApplicationSerializer(placementApplications, many=True).data
|
|
|
|
return Response(
|
2021-12-03 01:04:49 +05:30
|
|
|
{'action': "Get Dashboard - Student", 'message': "Data Found", "placements": placementsdata,
|
2021-10-15 20:47:23 +05:30
|
|
|
'placementApplication': placementApplications},
|
|
|
|
status=status.HTTP_200_OK)
|
|
|
|
except Http404:
|
2021-12-03 01:04:49 +05:30
|
|
|
return Response({'action': "Get Dashboard - Student", 'message': 'Student Not Found'},
|
2021-10-15 20:47:23 +05:30
|
|
|
status=status.HTTP_404_NOT_FOUND)
|
|
|
|
except:
|
2021-12-03 01:04:49 +05:30
|
|
|
logger.warning("Get Dashboard -Student: " + str(sys.exc_info()))
|
2022-04-30 22:27:49 +05:30
|
|
|
print(sys.exc_info())
|
|
|
|
|
2021-12-03 01:04:49 +05:30
|
|
|
return Response({'action': "Get Dashboard - Student", 'message': "Something Went Wrong"},
|
2021-10-15 20:47:23 +05:30
|
|
|
status=status.HTTP_400_BAD_REQUEST)
|
|
|
|
|
|
|
|
|
|
|
|
@api_view(['POST'])
|
|
|
|
@isAuthorized(allowed_users=[STUDENT])
|
|
|
|
@precheck(required_data=[RESUME_FILE_NAME])
|
|
|
|
def deleteResume(request, id, email, user_type):
|
|
|
|
try:
|
|
|
|
student = get_object_or_404(Student, id=id)
|
|
|
|
file_name = request.data[RESUME_FILE_NAME]
|
2021-12-12 20:13:47 +05:30
|
|
|
if file_name not in student.resumes:
|
|
|
|
return Response({'action': "Delete Resume", 'message': "Resume Not Found"},
|
|
|
|
status=status.HTTP_404_NOT_FOUND)
|
|
|
|
|
2021-12-03 01:04:49 +05:30
|
|
|
destination_path = STORAGE_DESTINATION_RESUMES + id + "/" + str(file_name)
|
2021-10-15 20:47:23 +05:30
|
|
|
if path.exists(destination_path):
|
|
|
|
remove(destination_path)
|
|
|
|
student.resumes.remove(file_name)
|
|
|
|
student.save()
|
|
|
|
return Response({'action': "Delete Resume", 'message': "Resume Deleted"},
|
|
|
|
status=status.HTTP_200_OK)
|
|
|
|
else:
|
|
|
|
raise FileNotFoundError("File Not Found")
|
|
|
|
except Http404:
|
|
|
|
return Response({'action': "Delete Resume", 'message': 'Student Not Found'},
|
|
|
|
status=status.HTTP_404_NOT_FOUND)
|
|
|
|
except FileNotFoundError as e:
|
2021-12-12 20:13:47 +05:30
|
|
|
return Response({'action': "Delete Resume", 'message': 'File Not Found'},
|
2021-10-15 20:47:23 +05:30
|
|
|
status=status.HTTP_404_NOT_FOUND)
|
|
|
|
except:
|
|
|
|
logger.warning("Delete Resume: " + str(sys.exc_info()))
|
2021-12-03 01:04:49 +05:30
|
|
|
return Response({'action': "Delete Resume", 'message': "Something Went Wrong"},
|
2021-10-15 20:47:23 +05:30
|
|
|
status=status.HTTP_400_BAD_REQUEST)
|
|
|
|
|
|
|
|
|
|
|
|
@api_view(['POST'])
|
|
|
|
@isAuthorized(allowed_users=[STUDENT])
|
2021-10-22 20:37:15 +05:30
|
|
|
@precheck(required_data=[OPENING_TYPE, OPENING_ID, RESUME_FILE_NAME,
|
2021-12-03 01:04:49 +05:30
|
|
|
])
|
2021-10-15 20:47:23 +05:30
|
|
|
def submitApplication(request, id, email, user_type):
|
|
|
|
try:
|
|
|
|
data = request.data
|
|
|
|
student = get_object_or_404(Student, id=id)
|
2022-05-01 14:56:46 +05:30
|
|
|
if not student.can_apply:
|
|
|
|
return Response({'action': "Submit Application", 'message': "Student Can't Apply"},
|
|
|
|
status=status.HTTP_400_BAD_REQUEST)
|
2021-12-03 01:04:49 +05:30
|
|
|
# Only Allowing Applications for Placements
|
2021-10-22 20:37:15 +05:30
|
|
|
if data[OPENING_TYPE] == PLACEMENT:
|
2021-10-15 20:47:23 +05:30
|
|
|
if not len(PlacementApplication.objects.filter(
|
2021-10-22 20:37:15 +05:30
|
|
|
student_id=id, placement_id=data[OPENING_ID])):
|
2021-10-15 20:47:23 +05:30
|
|
|
application = PlacementApplication()
|
2021-10-22 20:37:15 +05:30
|
|
|
opening = get_object_or_404(Placement, id=data[OPENING_ID],
|
2021-12-03 01:04:49 +05:30
|
|
|
allowed_batch__contains=[student.batch],
|
|
|
|
allowed_branch__contains=[student.branch],
|
2022-04-30 22:27:49 +05:30
|
|
|
deadline_datetime__gte=datetime.datetime.now().date()
|
2021-12-03 01:04:49 +05:30
|
|
|
)
|
|
|
|
if not opening.offer_accepted or not opening.email_verified:
|
|
|
|
raise PermissionError("Placement Not Approved")
|
|
|
|
|
2021-10-15 20:47:23 +05:30
|
|
|
cond_stat, cond_msg = PlacementApplicationConditions(student, opening)
|
|
|
|
if not cond_stat:
|
|
|
|
raise PermissionError(cond_msg)
|
|
|
|
application.placement = opening
|
|
|
|
else:
|
|
|
|
raise PermissionError("Application is already Submitted")
|
|
|
|
else:
|
2021-10-22 20:37:15 +05:30
|
|
|
raise ValueError(OPENING_TYPE + " is Invalid")
|
2021-10-15 20:47:23 +05:30
|
|
|
|
|
|
|
if data[RESUME_FILE_NAME] in student.resumes:
|
|
|
|
application.resume = data[RESUME_FILE_NAME]
|
|
|
|
else:
|
|
|
|
raise FileNotFoundError(RESUME_FILE_NAME + " Not Found")
|
|
|
|
|
|
|
|
application.student = student
|
|
|
|
application.id = generateRandomString()
|
2021-12-03 01:04:49 +05:30
|
|
|
additional_info = {}
|
2021-10-15 20:47:23 +05:30
|
|
|
for i in opening.additional_info:
|
2021-10-22 20:37:15 +05:30
|
|
|
if i not in data[ADDITIONAL_INFO]:
|
2021-10-15 20:47:23 +05:30
|
|
|
raise AttributeError(i + " not found in Additional Info")
|
2021-12-03 01:04:49 +05:30
|
|
|
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": data[OPENING_TYPE],
|
|
|
|
"additional_info": dict(json.loads(application.additional_info)),
|
|
|
|
}
|
|
|
|
subject = STUDENT_APPLICATION_SUBMITTED_TEMPLATE_SUBJECT.format(company_name=opening.company_name)
|
|
|
|
sendEmail(email, subject, data, STUDENT_APPLICATION_SUBMITTED_TEMPLATE)
|
2021-10-15 20:47:23 +05:30
|
|
|
|
|
|
|
application.save()
|
|
|
|
return Response({'action': "Submit Application", 'message': "Application Submitted"},
|
|
|
|
status=status.HTTP_200_OK)
|
2021-12-03 01:04:49 +05:30
|
|
|
except Http404 as e:
|
2021-12-12 19:14:27 +05:30
|
|
|
return Response({'action': "Submit Application", 'message': str(e)},
|
2021-12-03 01:04:49 +05:30
|
|
|
status=status.HTTP_404_NOT_FOUND)
|
2021-10-15 20:47:23 +05:30
|
|
|
except PermissionError as e:
|
|
|
|
return Response({'action': "Submit Application", 'message': str(e)},
|
|
|
|
status=status.HTTP_403_FORBIDDEN)
|
|
|
|
except FileNotFoundError as e:
|
|
|
|
return Response({'action': "Submit Application", 'message': str(e)},
|
|
|
|
status=status.HTTP_404_NOT_FOUND)
|
|
|
|
except:
|
|
|
|
logger.warning("Submit Application: " + str(sys.exc_info()))
|
2022-04-30 22:27:49 +05:30
|
|
|
print(traceback.format_exc())
|
|
|
|
|
|
|
|
print(sys.exc_info())
|
2021-12-03 01:04:49 +05:30
|
|
|
return Response({'action': "Submit Application", 'message': "Something Went Wrong"},
|
2021-10-15 20:47:23 +05:30
|
|
|
status=status.HTTP_400_BAD_REQUEST)
|