From 95dad86b12f17182d6210e430139cc8b1216827d Mon Sep 17 00:00:00 2001 From: abutalib-kiwi Date: Mon, 21 Aug 2023 20:07:39 +0530 Subject: [PATCH] notification changes --- junior/serializers.py | 6 +-- notifications/admin.py | 2 + notifications/constants.py | 80 +++++++++++++++++++++----------------- notifications/utils.py | 14 +++++++ 4 files changed, 63 insertions(+), 39 deletions(-) diff --git a/junior/serializers.py b/junior/serializers.py index f79cd46..1ca98e4 100644 --- a/junior/serializers.py +++ b/junior/serializers.py @@ -22,7 +22,7 @@ from account.models import UserEmailOtp, UserNotification from junior.utils import junior_notification_email, junior_approval_mail from guardian.utils import real_time, update_referral_points, convert_timedelta_into_datetime from notifications.utils import send_notification, send_notification_to_junior, send_notification_to_guardian -from notifications.constants import (INVITED_GUARDIAN, APPROVED_JUNIOR, SKIPPED_PROFILE_SETUP, TASK_ACTION, +from notifications.constants import (INVITATION, ASSOCIATE_REQUEST, SKIPPED_PROFILE_SETUP, TASK_ACTION, TASK_SUBMITTED) from web_admin.models import ArticleCard @@ -451,8 +451,8 @@ class AddGuardianSerializer(serializers.ModelSerializer): """Notification email""" junior_notification_email(email, full_name, email, password) junior_approval_mail(email, full_name) - send_notification_to_junior.delay(INVITED_GUARDIAN, guardian_data.user.id, junior_data.auth.id, {}) - send_notification_to_guardian.delay(APPROVED_JUNIOR, junior_data.auth.id, guardian_data.user.id, {}) + send_notification_to_junior.delay(INVITATION, guardian_data.user.id, junior_data.auth.id, {}) + send_notification_to_guardian.delay(ASSOCIATE_REQUEST, junior_data.auth.id, guardian_data.user.id, {}) return guardian_data class StartTaskSerializer(serializers.ModelSerializer): diff --git a/notifications/admin.py b/notifications/admin.py index 382e97b..aa57aac 100644 --- a/notifications/admin.py +++ b/notifications/admin.py @@ -10,3 +10,5 @@ from notifications.models import Notification class NotificationAdmin(admin.ModelAdmin): """Notification Admin""" list_display = ['id', 'notification_type', 'notification_to', 'data', 'is_read'] + list_filter = ['notification_type'] + \ No newline at end of file diff --git a/notifications/constants.py b/notifications/constants.py index 59c2328..f4f8b86 100644 --- a/notifications/constants.py +++ b/notifications/constants.py @@ -1,19 +1,22 @@ """ notification constants file """ -from base.constants import NUMBER -REGISTRATION = NUMBER['one'] -TASK_ASSIGNED = NUMBER['two'] -INVITED_GUARDIAN = NUMBER['three'] -APPROVED_JUNIOR = NUMBER['four'] -REFERRAL_POINTS = NUMBER['five'] -TASK_POINTS = NUMBER['six'] -TASK_REJECTED = NUMBER['seven'] -SKIPPED_PROFILE_SETUP = NUMBER['eight'] -TASK_SUBMITTED = NUMBER['nine'] -TASK_ACTION = NUMBER['ten'] -LEADERBOARD_RANKING = NUMBER['eleven'] -REMOVE_JUNIOR = NUMBER['twelve'] +REGISTRATION = 1 +INVITATION = 2 +ASSOCIATE_REQUEST = 3 +REFERRAL_POINTS = 4 +SKIPPED_PROFILE_SETUP = 5 + +TASK_ASSIGNED = 6 +TASK_SUBMITTED = 7 +TASK_ACTION = 8 +TASK_REJECTED = 9 +TASK_APPROVED = 10 +TASK_POINTS = 11 + +LEADERBOARD_RANKING = 12 +REMOVE_JUNIOR = 13 + TEST_NOTIFICATION = 99 NOTIFICATION_DICT = { @@ -21,41 +24,46 @@ NOTIFICATION_DICT = { "title": "Successfully registered!", "body": "You have registered successfully. Now login and complete your profile." }, - TASK_ASSIGNED: { - "title": "New task assigned !!", - "body": "{from_user} has assigned you a new task." + INVITATION: { + "title": "Invitation sent!", + "body": "Invitation has been successfully sent." }, - INVITED_GUARDIAN: { - "title": "Invite guardian", - "body": "Invite guardian successfully" - }, - APPROVED_JUNIOR: { - "title": "Approve junior !", + ASSOCIATE_REQUEST: { + "title": "Associate request!", "body": "You have request from {from_user} to associate with you." }, REFERRAL_POINTS: { - "title": "Earn Referral points", + "title": "Earn Referral points!", "body": "You earn 5 points for referral." }, - TASK_POINTS: { - "title": "Earn Task points!", - "body": "You earn 5 points for task." - }, - TASK_REJECTED: { - "title": "Task rejected!", - "body": "Your task has been rejected." - }, + # notification once any custodian adds junior in their account SKIPPED_PROFILE_SETUP: { - "title": "Skipped profile setup!", - "body": "Your guardian {from_user} has setup your profile." + "title": "Profile already setup!", + "body": "Your guardian has already setup your profile." + }, + TASK_ASSIGNED: { + "title": "New task assigned!", + "body": "{from_user} has assigned you a new task." }, TASK_SUBMITTED: { "title": "Task submitted!", - "body": "Your task has been submitted successfully." + "body": "Your task has been submitted for approval." }, TASK_ACTION: { "title": "Task completion approval!", - "body": "You have request from {from_user} for task approval." + "body": "You have request from {from_user} for task completion." + }, + TASK_REJECTED: { + "title": "Task completion rejected!", + "body": "Your task completion request has been rejected by {from_user}." + }, + TASK_APPROVED: { + "title": "Task completion approved!", + "body": "Your task completion request has been approved by {from_user}." + }, + TASK_POINTS: { + "title": "Earned Task points!", + "body": "You earn 5 points for task." }, LEADERBOARD_RANKING: { "title": "Leader board rank!", @@ -63,7 +71,7 @@ NOTIFICATION_DICT = { }, REMOVE_JUNIOR: { "title": "Disassociate by guardian!", - "body": "Your guardian disassociate you ." + "body": "Your guardian has disassociated you." }, TEST_NOTIFICATION: { "title": "Test Notification", diff --git a/notifications/utils.py b/notifications/utils.py index 50dee81..0d0b25b 100644 --- a/notifications/utils.py +++ b/notifications/utils.py @@ -97,6 +97,13 @@ def send_push(user, data): @shared_task() def send_notification_to_guardian(notification_type, from_user_id, to_user_id, extra_data): + """ + :param notification_type: + :param from_user_id: + :param to_user_id: + :param extra_data: + :return: + """ from_user = None if from_user_id: from_user = Junior.objects.filter(auth_id=from_user_id).select_related('auth').first() @@ -109,6 +116,13 @@ def send_notification_to_guardian(notification_type, from_user_id, to_user_id, e @shared_task() def send_notification_to_junior(notification_type, from_user_id, to_user_id, extra_data): + """ + :param notification_type: + :param from_user_id: + :param to_user_id: + :param extra_data: + :return: + """ from_user = None if from_user_id: from_user = Guardian.objects.filter(user_id=from_user_id).select_related('user').first()