notification changes

This commit is contained in:
abutalib-kiwi
2023-08-21 20:07:39 +05:30
parent dfff643c71
commit 95dad86b12
4 changed files with 63 additions and 39 deletions

View File

@ -22,7 +22,7 @@ from account.models import UserEmailOtp, UserNotification
from junior.utils import junior_notification_email, junior_approval_mail from junior.utils import junior_notification_email, junior_approval_mail
from guardian.utils import real_time, update_referral_points, convert_timedelta_into_datetime 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.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) TASK_SUBMITTED)
from web_admin.models import ArticleCard from web_admin.models import ArticleCard
@ -451,8 +451,8 @@ class AddGuardianSerializer(serializers.ModelSerializer):
"""Notification email""" """Notification email"""
junior_notification_email(email, full_name, email, password) junior_notification_email(email, full_name, email, password)
junior_approval_mail(email, full_name) junior_approval_mail(email, full_name)
send_notification_to_junior.delay(INVITED_GUARDIAN, guardian_data.user.id, junior_data.auth.id, {}) send_notification_to_junior.delay(INVITATION, 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_guardian.delay(ASSOCIATE_REQUEST, junior_data.auth.id, guardian_data.user.id, {})
return guardian_data return guardian_data
class StartTaskSerializer(serializers.ModelSerializer): class StartTaskSerializer(serializers.ModelSerializer):

View File

@ -10,3 +10,5 @@ from notifications.models import Notification
class NotificationAdmin(admin.ModelAdmin): class NotificationAdmin(admin.ModelAdmin):
"""Notification Admin""" """Notification Admin"""
list_display = ['id', 'notification_type', 'notification_to', 'data', 'is_read'] list_display = ['id', 'notification_type', 'notification_to', 'data', 'is_read']
list_filter = ['notification_type']

View File

@ -1,19 +1,22 @@
""" """
notification constants file notification constants file
""" """
from base.constants import NUMBER REGISTRATION = 1
REGISTRATION = NUMBER['one'] INVITATION = 2
TASK_ASSIGNED = NUMBER['two'] ASSOCIATE_REQUEST = 3
INVITED_GUARDIAN = NUMBER['three'] REFERRAL_POINTS = 4
APPROVED_JUNIOR = NUMBER['four'] SKIPPED_PROFILE_SETUP = 5
REFERRAL_POINTS = NUMBER['five']
TASK_POINTS = NUMBER['six'] TASK_ASSIGNED = 6
TASK_REJECTED = NUMBER['seven'] TASK_SUBMITTED = 7
SKIPPED_PROFILE_SETUP = NUMBER['eight'] TASK_ACTION = 8
TASK_SUBMITTED = NUMBER['nine'] TASK_REJECTED = 9
TASK_ACTION = NUMBER['ten'] TASK_APPROVED = 10
LEADERBOARD_RANKING = NUMBER['eleven'] TASK_POINTS = 11
REMOVE_JUNIOR = NUMBER['twelve']
LEADERBOARD_RANKING = 12
REMOVE_JUNIOR = 13
TEST_NOTIFICATION = 99 TEST_NOTIFICATION = 99
NOTIFICATION_DICT = { NOTIFICATION_DICT = {
@ -21,41 +24,46 @@ NOTIFICATION_DICT = {
"title": "Successfully registered!", "title": "Successfully registered!",
"body": "You have registered successfully. Now login and complete your profile." "body": "You have registered successfully. Now login and complete your profile."
}, },
TASK_ASSIGNED: { INVITATION: {
"title": "New task assigned !!", "title": "Invitation sent!",
"body": "{from_user} has assigned you a new task." "body": "Invitation has been successfully sent."
}, },
INVITED_GUARDIAN: { ASSOCIATE_REQUEST: {
"title": "Invite guardian", "title": "Associate request!",
"body": "Invite guardian successfully"
},
APPROVED_JUNIOR: {
"title": "Approve junior !",
"body": "You have request from {from_user} to associate with you." "body": "You have request from {from_user} to associate with you."
}, },
REFERRAL_POINTS: { REFERRAL_POINTS: {
"title": "Earn Referral points", "title": "Earn Referral points!",
"body": "You earn 5 points for referral." "body": "You earn 5 points for referral."
}, },
TASK_POINTS: { # notification once any custodian adds junior in their account
"title": "Earn Task points!",
"body": "You earn 5 points for task."
},
TASK_REJECTED: {
"title": "Task rejected!",
"body": "Your task has been rejected."
},
SKIPPED_PROFILE_SETUP: { SKIPPED_PROFILE_SETUP: {
"title": "Skipped profile setup!", "title": "Profile already setup!",
"body": "Your guardian {from_user} has setup your profile." "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: { TASK_SUBMITTED: {
"title": "Task submitted!", "title": "Task submitted!",
"body": "Your task has been submitted successfully." "body": "Your task has been submitted for approval."
}, },
TASK_ACTION: { TASK_ACTION: {
"title": "Task completion approval!", "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: { LEADERBOARD_RANKING: {
"title": "Leader board rank!", "title": "Leader board rank!",
@ -63,7 +71,7 @@ NOTIFICATION_DICT = {
}, },
REMOVE_JUNIOR: { REMOVE_JUNIOR: {
"title": "Disassociate by guardian!", "title": "Disassociate by guardian!",
"body": "Your guardian disassociate you ." "body": "Your guardian has disassociated you."
}, },
TEST_NOTIFICATION: { TEST_NOTIFICATION: {
"title": "Test Notification", "title": "Test Notification",

View File

@ -97,6 +97,13 @@ def send_push(user, data):
@shared_task() @shared_task()
def send_notification_to_guardian(notification_type, from_user_id, to_user_id, extra_data): 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 from_user = None
if from_user_id: if from_user_id:
from_user = Junior.objects.filter(auth_id=from_user_id).select_related('auth').first() 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() @shared_task()
def send_notification_to_junior(notification_type, from_user_id, to_user_id, extra_data): 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 from_user = None
if from_user_id: if from_user_id:
from_user = Guardian.objects.filter(user_id=from_user_id).select_related('user').first() from_user = Guardian.objects.filter(user_id=from_user_id).select_related('user').first()