mirror of
https://github.com/HamzaSha1/zod-backend.git
synced 2025-07-15 10:05:21 +00:00
changed notification method, added celery task to notify expiring task
This commit is contained in:
@ -4,27 +4,35 @@ notifications views file
|
||||
# django imports
|
||||
from django.db.models import Q
|
||||
from rest_framework.decorators import action
|
||||
from rest_framework.permissions import IsAuthenticated
|
||||
from rest_framework.permissions import IsAuthenticated, AllowAny
|
||||
from rest_framework.response import Response
|
||||
from rest_framework import viewsets, status, views
|
||||
|
||||
# local imports
|
||||
from account.utils import custom_response, custom_error_response
|
||||
from base.constants import JUNIOR, GUARDIAN
|
||||
from base.messages import SUCCESS_CODE, ERROR_CODE
|
||||
from base.tasks import notify_task_expiry
|
||||
from guardian.models import Guardian
|
||||
from notifications.constants import TEST_NOTIFICATION
|
||||
# Import serializer
|
||||
from notifications.serializers import RegisterDevice, NotificationListSerializer, ReadNotificationSerializer
|
||||
from notifications.utils import send_notification, send_notification_to_guardian, send_notification_to_junior
|
||||
# Import model
|
||||
from notifications.utils import send_notification
|
||||
from notifications.models import Notification
|
||||
|
||||
|
||||
class NotificationViewSet(viewsets.GenericViewSet):
|
||||
""" used to do the notification actions """
|
||||
"""
|
||||
used to do the notification actions
|
||||
"""
|
||||
serializer_class = NotificationListSerializer
|
||||
permission_classes = [IsAuthenticated, ]
|
||||
|
||||
def list(self, request, *args, **kwargs) -> Response:
|
||||
""" list the notifications """
|
||||
"""
|
||||
to list user's notifications
|
||||
:param request:
|
||||
:return:
|
||||
"""
|
||||
queryset = Notification.objects.filter(notification_to_id=request.auth.payload['user_id']
|
||||
).select_related('notification_to').order_by('-id')
|
||||
paginator = self.pagination_class()
|
||||
@ -49,10 +57,8 @@ class NotificationViewSet(viewsets.GenericViewSet):
|
||||
to send test notification
|
||||
:return:
|
||||
"""
|
||||
send_notification_to_guardian.delay(TEST_NOTIFICATION, None, request.auth.payload['user_id'],
|
||||
{'task_id': None})
|
||||
send_notification_to_junior.delay(TEST_NOTIFICATION, None, request.auth.payload['user_id'],
|
||||
{'task_id': None})
|
||||
send_notification(TEST_NOTIFICATION, None, None, request.auth.payload['user_id'],
|
||||
{})
|
||||
return custom_response(SUCCESS_CODE["3000"])
|
||||
|
||||
@action(methods=['patch'], url_path='mark-as-read', url_name='mark-as-read', detail=False,
|
||||
@ -63,3 +69,12 @@ class NotificationViewSet(viewsets.GenericViewSet):
|
||||
"""
|
||||
Notification.objects.filter(id__in=request.data.get('id')).update(is_read=True)
|
||||
return custom_response(SUCCESS_CODE['3039'], response_status=status.HTTP_200_OK)
|
||||
|
||||
@action(methods=['get'], url_path='task', url_name='task', detail=False,
|
||||
permission_classes=[AllowAny])
|
||||
def task(self, request, *args, **kwargs):
|
||||
"""
|
||||
notification list
|
||||
"""
|
||||
notify_task_expiry()
|
||||
return custom_response(SUCCESS_CODE['3039'], response_status=status.HTTP_200_OK)
|
||||
|
Reference in New Issue
Block a user