changed endpoints to populate notifications
This commit is contained in:
parent
8d97183dd3
commit
e05c4761a4
|
@ -124,7 +124,7 @@ def updateDeadline(request, id, email, user_type):
|
||||||
opening.deadline_datetime = datetime.datetime.strptime(data[DEADLINE_DATETIME], '%Y-%m-%d %H:%M:%S %z')
|
opening.deadline_datetime = datetime.datetime.strptime(data[DEADLINE_DATETIME], '%Y-%m-%d %H:%M:%S %z')
|
||||||
opening.changed_by = get_object_or_404(User, id=id)
|
opening.changed_by = get_object_or_404(User, id=id)
|
||||||
opening.save()
|
opening.save()
|
||||||
send_opening_to_notifications_service(id=opening.id,name=opening.company_name,deadline=data[DEADLINE_DATETIME],role=opening.designation)
|
send_opening_to_notifications_service(id=opening.id,name=opening.company_name,deadline=data[DEADLINE_DATETIME],role=opening.designation,opening_type=opening_type)
|
||||||
return Response({'action': "Update Deadline", 'message': "Deadline Updated"},
|
return Response({'action': "Update Deadline", 'message': "Deadline Updated"},
|
||||||
status=status.HTTP_200_OK)
|
status=status.HTTP_200_OK)
|
||||||
except Http404:
|
except Http404:
|
||||||
|
@ -162,7 +162,7 @@ def updateOfferAccepted(request, id, email, user_type):
|
||||||
opening.save()
|
opening.save()
|
||||||
if opening.offer_accepted:
|
if opening.offer_accepted:
|
||||||
deadline=deadline_datetime.strftime('%Y-%m-%d %H:%M:%S %z')
|
deadline=deadline_datetime.strftime('%Y-%m-%d %H:%M:%S %z')
|
||||||
send_opening_to_notifications_service(id=opening.id,name=opening.company_name,deadline=deadline,role=opening.designation)
|
send_opening_to_notifications_service(id=opening.id,name=opening.company_name,deadline=deadline,role=opening.designation,opening_type=opening_type)
|
||||||
send_opening_notifications(opening.id,opening_type)
|
send_opening_notifications(opening.id,opening_type)
|
||||||
else:
|
else:
|
||||||
raise ValueError("Offer Status already updated")
|
raise ValueError("Offer Status already updated")
|
||||||
|
@ -766,7 +766,11 @@ def get_eligible_students(request):
|
||||||
opening_type= data[OPENING_TYPE]
|
opening_type= data[OPENING_TYPE]
|
||||||
else:
|
else:
|
||||||
opening_type= "Placement"
|
opening_type= "Placement"
|
||||||
eligible_students=get_eligible_emails(opening_id=opening_id, opening_type=opening_type)
|
if "send_all" in data:
|
||||||
|
send_all = "True"==data["send_all"]
|
||||||
|
else:
|
||||||
|
send_all = False
|
||||||
|
eligible_students=get_eligible_emails(opening_id=opening_id, opening_type=opening_type, send_all=send_all)
|
||||||
return Response({'action': "Get Eligible Students", 'message': "Eligible Students Fetched",
|
return Response({'action': "Get Eligible Students", 'message': "Eligible Students Fetched",
|
||||||
'eligible_students': eligible_students},
|
'eligible_students': eligible_students},
|
||||||
status=status.HTTP_200_OK)
|
status=status.HTTP_200_OK)
|
||||||
|
|
|
@ -457,7 +457,7 @@ def send_opening_notifications(opening_id, opening_type=PLACEMENT):
|
||||||
logger.warning('Utils - send_opening_notifications: ' + str(sys.exc_info()))
|
logger.warning('Utils - send_opening_notifications: ' + str(sys.exc_info()))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_eligible_emails(opening_id, opening_type=PLACEMENT):
|
def get_eligible_emails(opening_id, opening_type=PLACEMENT,send_all=False):
|
||||||
try:
|
try:
|
||||||
# print(opening_id, opening_type)
|
# print(opening_id, opening_type)
|
||||||
if opening_type == PLACEMENT:
|
if opening_type == PLACEMENT:
|
||||||
|
@ -473,6 +473,10 @@ def get_eligible_emails(opening_id, opening_type=PLACEMENT):
|
||||||
isinstance(opening,Internship) and InternshipApplicationConditions(student, opening)[0]):
|
isinstance(opening,Internship) and InternshipApplicationConditions(student, opening)[0]):
|
||||||
try:
|
try:
|
||||||
student_user = get_object_or_404(User, id=student.id)
|
student_user = get_object_or_404(User, id=student.id)
|
||||||
|
#if send_all True send all students eligible for the opening
|
||||||
|
if send_all:
|
||||||
|
emails.append(student_user.email)
|
||||||
|
continue
|
||||||
# check if he applied
|
# check if he applied
|
||||||
if opening_type == PLACEMENT:
|
if opening_type == PLACEMENT:
|
||||||
if PlacementApplication.objects.filter(student=student, placement=opening).exists():
|
if PlacementApplication.objects.filter(student=student, placement=opening).exists():
|
||||||
|
@ -565,12 +569,13 @@ def send_email_for_opening(opening):
|
||||||
|
|
||||||
|
|
||||||
@background_task.background(schedule=2)
|
@background_task.background(schedule=2)
|
||||||
def send_opening_to_notifications_service(id,name,deadline,role):
|
def send_opening_to_notifications_service(id,name,deadline,role,opening_type=PLACEMENT):
|
||||||
data={
|
data={
|
||||||
"id":id,
|
"id":id,
|
||||||
"company":name,
|
"company":name,
|
||||||
"deadline":deadline,
|
"deadline":deadline,
|
||||||
"role":role
|
"role":role,
|
||||||
|
"opening_type":opening_type
|
||||||
}
|
}
|
||||||
encoded=jwt.encode(data,os.environ.get("JWT_SECRET_KEY"),algorithm="HS256")
|
encoded=jwt.encode(data,os.environ.get("JWT_SECRET_KEY"),algorithm="HS256")
|
||||||
data_={
|
data_={
|
||||||
|
|
Loading…
Reference in New Issue