mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-11-26 08:34:55 +00:00
notification create modified to update or create
This commit is contained in:
@ -13,7 +13,7 @@ from django.db.models import F, Window
|
|||||||
from django.db.models.functions.window import Rank
|
from django.db.models.functions.window import Rank
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from base.constants import PENDING, IN_PROGRESS, JUNIOR
|
from base.constants import PENDING, IN_PROGRESS, JUNIOR, GUARDIAN
|
||||||
from guardian.models import JuniorTask
|
from guardian.models import JuniorTask
|
||||||
from junior.models import JuniorPoints
|
from junior.models import JuniorPoints
|
||||||
from notifications.constants import PENDING_TASK_EXPIRING, IN_PROGRESS_TASK_EXPIRING, NOTIFICATION_DICT, TOP_JUNIOR
|
from notifications.constants import PENDING_TASK_EXPIRING, IN_PROGRESS_TASK_EXPIRING, NOTIFICATION_DICT, TOP_JUNIOR
|
||||||
@ -53,7 +53,7 @@ def notify_task_expiry():
|
|||||||
(datetime.datetime.now().date() + datetime.timedelta(days=1))])
|
(datetime.datetime.now().date() + datetime.timedelta(days=1))])
|
||||||
if pending_tasks := all_pending_tasks.filter(task_status=PENDING):
|
if pending_tasks := all_pending_tasks.filter(task_status=PENDING):
|
||||||
for task in pending_tasks:
|
for task in pending_tasks:
|
||||||
send_notification(PENDING_TASK_EXPIRING, None, None, task.junior.auth_id,
|
send_notification(PENDING_TASK_EXPIRING, task.guardian.user_id, GUARDIAN, task.junior.auth_id,
|
||||||
{'task_id': task.id})
|
{'task_id': task.id})
|
||||||
if in_progress_tasks := all_pending_tasks.filter(task_status=IN_PROGRESS):
|
if in_progress_tasks := all_pending_tasks.filter(task_status=IN_PROGRESS):
|
||||||
for task in in_progress_tasks:
|
for task in in_progress_tasks:
|
||||||
|
|||||||
@ -11,3 +11,4 @@ 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']
|
list_filter = ['notification_type']
|
||||||
|
search_fields = ['notification_to']
|
||||||
|
|||||||
@ -88,6 +88,7 @@ def get_notification_data(notification_type, from_user_id, from_user_type, to_us
|
|||||||
push_data['body'] = push_data['body'].format(from_user=from_user_name, task_name=task_name, points=points)
|
push_data['body'] = push_data['body'].format(from_user=from_user_name, task_name=task_name, points=points)
|
||||||
notification_data['body'] = notification_data['body'].format(from_user=from_user_name,
|
notification_data['body'] = notification_data['body'].format(from_user=from_user_name,
|
||||||
task_name=task_name, points=points)
|
task_name=task_name, points=points)
|
||||||
|
|
||||||
notification_data['from_user'] = from_user_name
|
notification_data['from_user'] = from_user_name
|
||||||
notification_data['from_user_image'] = from_user_image
|
notification_data['from_user_image'] = from_user_image
|
||||||
|
|
||||||
@ -104,8 +105,18 @@ def send_notification(notification_type, from_user_id, from_user_type, to_user_i
|
|||||||
notification_data, push_data, from_user, to_user = get_notification_data(notification_type, from_user_id,
|
notification_data, push_data, from_user, to_user = get_notification_data(notification_type, from_user_id,
|
||||||
from_user_type, to_user_id, extra_data)
|
from_user_type, to_user_id, extra_data)
|
||||||
user_notification_type = UserNotification.objects.filter(user=to_user).first()
|
user_notification_type = UserNotification.objects.filter(user=to_user).first()
|
||||||
Notification.objects.create(notification_type=notification_type, notification_from=from_user,
|
|
||||||
notification_to=to_user, data=notification_data)
|
# notification create method changed on 28sep as per changes required
|
||||||
|
task_id = extra_data['task_id'] if 'task_id' in extra_data else None
|
||||||
|
Notification.objects.update_or_create(data__has_key='task_id', data__task_id=task_id,
|
||||||
|
notification_from=from_user, notification_to=to_user,
|
||||||
|
defaults={
|
||||||
|
'notification_type': notification_type,
|
||||||
|
'notification_from': from_user,
|
||||||
|
'notification_to': to_user,
|
||||||
|
'data': notification_data
|
||||||
|
})
|
||||||
|
|
||||||
if user_notification_type and user_notification_type.push_notification:
|
if user_notification_type and user_notification_type.push_notification:
|
||||||
send_push(to_user, push_data)
|
send_push(to_user, push_data)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user