Skip to content

Commit

Permalink
changed endpoints to populate notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
uttamthummala committed Oct 29, 2023
1 parent 8d97183 commit e05c476
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
10 changes: 7 additions & 3 deletions CDC_Backend/APIs/adminViews.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.changed_by = get_object_or_404(User, id=id)
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"},
status=status.HTTP_200_OK)
except Http404:
Expand Down Expand Up @@ -162,7 +162,7 @@ def updateOfferAccepted(request, id, email, user_type):
opening.save()
if opening.offer_accepted:
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)
else:
raise ValueError("Offer Status already updated")
Expand Down Expand Up @@ -766,7 +766,11 @@ def get_eligible_students(request):
opening_type= data[OPENING_TYPE]
else:
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",
'eligible_students': eligible_students},
status=status.HTTP_200_OK)
Expand Down
11 changes: 8 additions & 3 deletions CDC_Backend/APIs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ 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):
def get_eligible_emails(opening_id, opening_type=PLACEMENT,send_all=False):
try:
# print(opening_id, opening_type)
if opening_type == PLACEMENT:
Expand All @@ -473,6 +473,10 @@ def get_eligible_emails(opening_id, opening_type=PLACEMENT):
isinstance(opening,Internship) and InternshipApplicationConditions(student, opening)[0]):
try:
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
if opening_type == PLACEMENT:
if PlacementApplication.objects.filter(student=student, placement=opening).exists():
Expand Down Expand Up @@ -565,12 +569,13 @@ def send_email_for_opening(opening):


@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={
"id":id,
"company":name,
"deadline":deadline,
"role":role
"role":role,
"opening_type":opening_type
}
encoded=jwt.encode(data,os.environ.get("JWT_SECRET_KEY"),algorithm="HS256")
data_={
Expand Down

0 comments on commit e05c476

Please sign in to comment.