Commit d6c43522 authored by Gladys Forte's avatar Gladys Forte

notification v2

parent fe520cc9
from django.conf import settings
from websocket import create_connection
import json
from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response
REALTIMESERVER_IP = settings.REALTIMESERVER_IP
......@@ -14,3 +16,23 @@ def send_broadcast_message(room_name, sender, message):
}
ws.send(json.dumps(data))
ws.close()
class CustomPagination(PageNumberPagination):
page_size = 10
max_page_size = 50
page_query_param = 'page'
page_size_query_param = 'page_size'
def get_paginated_response(self, data):
return Response({
'page_number': self.page.number,
'size_per_page': self.page.paginator.per_page,
'total_pages': self.page.paginator.num_pages,
'total': self.page.paginator.count,
'totalunseen': data['unseen'],
'code': data['code'],
'status': data['status'],
'message': data['message'],
'results': data['results']
})
\ No newline at end of file
......@@ -14,9 +14,9 @@ from rest_framework import status
from django.conf import settings
from app.applicationlayer.management.notification.utils_notif import (
send_broadcast_message)
from app.applicationlayer.utils import (status_message_response,
send_broadcast_message,
CustomPagination)
from app.applicationlayer.utils import (status_message_response)
from rest_framework.exceptions import ValidationError
from django.shortcuts import render, redirect, get_object_or_404
from rest_framework.decorators import action
......@@ -32,10 +32,10 @@ class NotificationsViewset(meviewsets.ModelViewSet):
pagination_class = CustomPagination
def list(self, request, *args, **kwargs):
# try:
try:
req = self.request
account_no = req.query_params.get('account_no')
app = req.query_params.get('app_code')
app = req.query_params.get('app')
if account_no:
......@@ -76,15 +76,15 @@ class NotificationsViewset(meviewsets.ModelViewSet):
'message': 'List of Notifications found',
'results': serializer.data
}
return self.get_paginated_response(message)
# return Response(serializer.data)
# except Exception as e:
# message = status_message_response(
# 500, 'failed',
# 'Request was not able to process' + str(e), [])
# return Response(message,
# status=status.HTTP_500_INTERNAL_SERVER_ERROR)
except Exception as e:
message = status_message_response(
500, 'failed',
'Request was not able to process' + str(e), [])
return Response(message,
status=status.HTTP_500_INTERNAL_SERVER_ERROR)
@action(methods=["PATCH"], detail=True)
......@@ -96,8 +96,7 @@ class NotificationsViewset(meviewsets.ModelViewSet):
models.Notification.objects.filter(account_no=account_no,
id__in=request.data['ids']).update(
is_read=True,
modified=datetime.now(),
modifiedby=account_no)
modified=datetime.now())
message = status_message_response(
200, 'success',
......@@ -124,8 +123,7 @@ class NotificationsViewset(meviewsets.ModelViewSet):
models.Notification.objects.filter(account_no=account_no).update(
is_read=True,
modified=datetime.now(),
modifiedby=account_no)
modified=datetime.now())
message = status_message_response(
200, 'success',
......@@ -147,9 +145,7 @@ class NotificationsViewset(meviewsets.ModelViewSet):
serializer = serializers.NotificationSerializer(data=request.data)
try:
if serializer.is_valid():
x = serializer.save()
x.created = datetime.now()
x.save()
serializer.save()
message = {
'code': 201,
......@@ -159,7 +155,6 @@ class NotificationsViewset(meviewsets.ModelViewSet):
}
ROOM = serializer.data['account_no']
SENDER = serializer.data['sender_account_no']
send_broadcast_message(
......
......@@ -27,3 +27,4 @@ SESSION_TIMEOUT = config['DEV']['SESSION_TIMEOUT']
FRONT_END_URL = config['DEV']['FRONT_END_URL']
AUTH_ACCESSS_TOKEN_TIMEOUT = config['DEV']['AUTH_ACCESSS_TOKEN_TIMEOUT']
USER_DEFAULT_PASSWORD = config['DEV']['USER_DEFAULT_PASSWORD']
REALTIMESERVER_IP = config['NOTIFICATION']['REALTIMESERVER_IP']
\ No newline at end of file
......@@ -25,5 +25,4 @@ SESSION_TIMEOUT = config['LOCAL']['SESSION_TIMEOUT']
FRONT_END_URL = config['LOCAL']['FRONT_END_URL']
AUTH_ACCESSS_TOKEN_TIMEOUT = config['LOCAL']['AUTH_ACCESSS_TOKEN_TIMEOUT']
USER_DEFAULT_PASSWORD = config['LOCAL']['USER_DEFAULT_PASSWORD']
REALTIMESERVER_IP = config['NOTIFICATION']['REALTIMESERVER_IP']
\ No newline at end of file
......@@ -27,3 +27,4 @@ SESSION_TIMEOUT = config['PRODUCTION']['SESSION_TIMEOUT']
FRONT_END_URL = config['PRODUCTION']['FRONT_END_URL']
AUTH_ACCESSS_TOKEN_TIMEOUT = config['PRODUCTION']['AUTH_ACCESSS_TOKEN_TIMEOUT']
USER_DEFAULT_PASSWORD = config['PRODUCTION']['USER_DEFAULT_PASSWORD']
REALTIMESERVER_IP = config['NOTIFICATION']['REALTIMESERVER_IP']
\ No newline at end of file
......@@ -27,3 +27,4 @@ SESSION_TIMEOUT = config['UAT']['SESSION_TIMEOUT']
FRONT_END_URL = config['UAT']['FRONT_END_URL']
AUTH_ACCESSS_TOKEN_TIMEOUT = config['UAT']['AUTH_ACCESSS_TOKEN_TIMEOUT']
USER_DEFAULT_PASSWORD = config['UAT']['USER_DEFAULT_PASSWORD']
REALTIMESERVER_IP = config['NOTIFICATION']['REALTIMESERVER_IP']
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment