From e05c4761a406841eedf199f729815c23aaf7d42d Mon Sep 17 00:00:00 2001 From: uttamthummala Date: Sun, 29 Oct 2023 16:51:48 +0530 Subject: [PATCH] changed endpoints to populate notifications --- CDC_Backend/APIs/adminViews.py | 10 +++++++--- CDC_Backend/APIs/utils.py | 11 ++++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/CDC_Backend/APIs/adminViews.py b/CDC_Backend/APIs/adminViews.py index eb76008..794d580 100644 --- a/CDC_Backend/APIs/adminViews.py +++ b/CDC_Backend/APIs/adminViews.py @@ -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: @@ -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") @@ -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) diff --git a/CDC_Backend/APIs/utils.py b/CDC_Backend/APIs/utils.py index 8f92cc1..2db341c 100644 --- a/CDC_Backend/APIs/utils.py +++ b/CDC_Backend/APIs/utils.py @@ -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: @@ -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(): @@ -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_={