added notification when admin adds a new article

This commit is contained in:
abutalib-kiwi
2023-08-25 16:59:10 +05:30
parent b82902081f
commit 21b92f8c74
8 changed files with 32 additions and 13 deletions

View File

@ -8,6 +8,7 @@ from firebase_admin.messaging import Message, Notification as FirebaseNotificati
# django imports
from django.contrib.auth import get_user_model
from django.db.models import Q
# local imports
from account.models import UserNotification
@ -79,6 +80,7 @@ def get_notification_data(notification_type, from_user_id, from_user_type, to_us
if 'task_id' in extra_data:
task = JuniorTask.objects.filter(id=extra_data.get('task_id')).first()
task_name = task.task_name
extra_data['task_name'] = task_name
extra_data['task_image'] = task.image if task.image else task.default_image
from_user_name, from_user_image, from_user = get_from_user_details(from_user_id, from_user_type)
@ -124,10 +126,13 @@ def send_multiple_push(queryset, data):
@shared_task()
def send_notification_multiple_user(notification_type, from_user_id, from_user_type,
to_user_list: list = [], extra_data: dict = {}):
extra_data: dict = {}):
"""
used to send notification to multiple user for the given notification type
"""
to_user_list = User.objects.filter(junior_profile__is_verified=True, is_superuser=False
).exclude(junior_profile__isnull=True, guardian_profile__isnull=True)
push_data = NOTIFICATION_DICT[notification_type].copy()
notification_data = push_data.copy()
points = extra_data.get('points', None)
@ -144,7 +149,7 @@ def send_notification_multiple_user(notification_type, from_user_id, from_user_t
notification_from=from_user,
data=notification_data))
Notification.objects.bulk_create(notification_list)
to_user_list = to_user_list.filter(user_notification__push_notification=True)
send_multiple_push(to_user_list, push_data)