Merge pull request #180 from CDC-IITDH/service-api
create new endpoint to expose eligible students for an opeining id
This commit is contained in:
commit
4734834ad5
|
@ -16,4 +16,5 @@ urlpatterns = [
|
|||
path('addPPO/', adminViews.addPPO, name="Add PPO"),
|
||||
path('getStudentApplication/', adminViews.getStudentApplication, name="Get student application"),
|
||||
path('getStats/', adminViews.getStats, name="Get Stats"),
|
||||
path('getEligibleStudents/', adminViews.get_eligible_students, name="Get Eligible Students"),
|
||||
]
|
||||
|
|
|
@ -754,3 +754,28 @@ def getStats(request, id, email, user_type):
|
|||
print(sys.exc_info())
|
||||
return Response({'action': "Get Stats", 'message': "Something Went Wrong"},
|
||||
status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
|
||||
@api_view(['GET'])
|
||||
@isAuthorizedService()
|
||||
@precheck(required_data=[OPENING_ID])
|
||||
def get_eligible_students(request):
|
||||
try:
|
||||
data = request.GET
|
||||
opening_id = data[OPENING_ID]
|
||||
if OPENING_TYPE in data:
|
||||
opening_type= data[OPENING_TYPE]
|
||||
else:
|
||||
opening_type= "Placement"
|
||||
eligible_students=get_eligible_emails(opening_id=opening_id, opening_type=opening_type)
|
||||
return Response({'action': "Get Eligible Students", 'message': "Eligible Students Fetched",
|
||||
'eligible_students': eligible_students},
|
||||
status=status.HTTP_200_OK)
|
||||
except Http404:
|
||||
return Response({'action': "Get Eligible Students", 'message': "Opening Not Found"},
|
||||
status=status.HTTP_404_NOT_FOUND)
|
||||
except:
|
||||
logger.warning("Get Eligible Students: " + str(sys.exc_info()))
|
||||
return Response({'action': "Get Eligible Students", 'message': "Something Went Wrong"},
|
||||
status=status.HTTP_400_BAD_REQUEST)
|
||||
|
|
@ -100,6 +100,7 @@ EMAIL = "email"
|
|||
STUDENT = 'student'
|
||||
ADMIN = 'admin'
|
||||
SUPER_ADMIN = 's_admin'
|
||||
SERVICE= 'service'
|
||||
COMPANY = 'company'
|
||||
TIER = 'tier'
|
||||
# To be Configured Properly
|
||||
|
|
|
@ -151,6 +151,26 @@ def isAuthorized(allowed_users=None):
|
|||
|
||||
return decorator
|
||||
|
||||
def isAuthorizedService():
|
||||
def decorator(view_func):
|
||||
def wrapper_func(request, *args, **kwargs):
|
||||
try:
|
||||
headers = request.META
|
||||
if 'HTTP_AUTHORIZATION' in headers:
|
||||
token_id = headers['HTTP_AUTHORIZATION'][7:]
|
||||
jwt.decode(token_id, os.environ.get("JWT_SECRET_KEY"), algorithms="HS256")
|
||||
return view_func(request, *args, **kwargs)
|
||||
else:
|
||||
raise PermissionError("Authorization Header Not Found")
|
||||
except:
|
||||
logger.warning("Is Authorized? " + str(sys.exc_info()))
|
||||
return Response(
|
||||
{'action': "Is Authorized?", 'message': "Something went wrong. Contact CDC for more details"},
|
||||
status=status.HTTP_400_BAD_REQUEST)
|
||||
return wrapper_func
|
||||
|
||||
return decorator
|
||||
|
||||
|
||||
def generateRandomString():
|
||||
try:
|
||||
|
@ -435,6 +455,37 @@ def send_opening_notifications(opening_id, opening_type=PLACEMENT):
|
|||
logger.warning('Utils - send_opening_notifications: ' + str(sys.exc_info()))
|
||||
return False
|
||||
|
||||
def get_eligible_emails(opening_id, opening_type=PLACEMENT):
|
||||
try:
|
||||
# print(opening_id, opening_type)
|
||||
if opening_type == PLACEMENT:
|
||||
opening = get_object_or_404(Placement, id=opening_id)
|
||||
else:
|
||||
opening = get_object_or_404(Internship, id=opening_id)
|
||||
emails=[]
|
||||
students = Student.objects.all()
|
||||
for student in students.iterator():
|
||||
if student.branch in opening.allowed_branch:
|
||||
if student.degree == 'bTech' or opening.rs_eligible is True:
|
||||
if (isinstance(opening,Placement) and PlacementApplicationConditions(student, opening)[0]) or (
|
||||
isinstance(opening,Internship) and InternshipApplicationConditions(student, opening)[0]):
|
||||
try:
|
||||
student_user = get_object_or_404(User, id=student.id)
|
||||
# check if he applied
|
||||
if opening_type == PLACEMENT:
|
||||
if PlacementApplication.objects.filter(student=student, placement=opening).exists():
|
||||
continue
|
||||
else:
|
||||
if InternshipApplication.objects.filter(student=student, internship=opening).exists():
|
||||
continue
|
||||
emails.append(student_user.email)
|
||||
except Exception as e:
|
||||
logger.warning('Utils - send_opening_notifications: For Loop' + str(e))
|
||||
return False
|
||||
return True, emails
|
||||
except:
|
||||
logger.warning('Utils - send_opening_notifications: ' + str(sys.exc_info()))
|
||||
return False
|
||||
|
||||
def exception_email(opening):
|
||||
opening = opening.dict()
|
||||
|
|
Loading…
Reference in New Issue