mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
add read all endpoint
This commit is contained in:
parent
0fa8af6cd8
commit
a4c9dfdd6f
@ -14,6 +14,7 @@ from django.views.decorators.csrf import csrf_exempt
|
||||
from django.conf.urls import url, include
|
||||
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.exceptions import NotAcceptable, NotFound
|
||||
from django_filters.rest_framework import DjangoFilterBackend
|
||||
from rest_framework import filters, generics, permissions
|
||||
@ -314,6 +315,25 @@ class NotificationUnread(NotificationReadEdit):
|
||||
target = False
|
||||
|
||||
|
||||
class NotificationReadAll(generics.RetrieveAPIView):
|
||||
"""
|
||||
API endpoint to mark all notifications as read.
|
||||
"""
|
||||
|
||||
queryset = common.models.NotificationMessage.objects.all()
|
||||
|
||||
permission_classes = [
|
||||
UserSettingsPermissions,
|
||||
]
|
||||
|
||||
def get(self, request, *args, **kwargs):
|
||||
try:
|
||||
self.queryset.filter(user=request.user, read=False).update(read=True)
|
||||
return Response({'status': 'ok'})
|
||||
except Exception as exc:
|
||||
raise serializers.ValidationError(detail=serializers.as_serializer_error(exc))
|
||||
|
||||
|
||||
settings_api_urls = [
|
||||
# User settings
|
||||
url(r'^user/', include([
|
||||
@ -346,6 +366,8 @@ common_api_urls = [
|
||||
url(r'^unread/', NotificationUnread.as_view(), name='api-notifications-unread'),
|
||||
url(r'.*$', NotificationDetail.as_view(), name='api-notifications-detail'),
|
||||
])),
|
||||
# Read all
|
||||
url(r'^readall/', NotificationReadAll.as_view(), name='api-notifications-readall'),
|
||||
|
||||
# Notification messages list
|
||||
url(r'^.*$', NotificationList.as_view(), name='api-notifications-list'),
|
||||
|
@ -13,6 +13,9 @@
|
||||
<div class='btn btn-secondary' type='button' id='inbox-refresh' title='{% trans "Refresh Pending Notifications" %}'>
|
||||
<span class='fa fa-sync'></span> {% trans "Refresh Pending Notifications" %}
|
||||
</div>
|
||||
<div class='btn btn-secondary' type='button' id='mark-all' title='{% trans "Mark all as read" %}'>
|
||||
<span class='fa fa-sync'></span> {% trans "Mark all as read" %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
|
@ -120,6 +120,15 @@ $("#inbox-refresh").on('click', function() {
|
||||
$("#inbox-table").bootstrapTable('refresh');
|
||||
});
|
||||
|
||||
$("#mark-all").on('click', function() {
|
||||
inventreeGet(
|
||||
'{% url "api-notifications-readall" %}',
|
||||
{
|
||||
read: false,
|
||||
},
|
||||
);
|
||||
updateNotificationTables();
|
||||
});
|
||||
|
||||
loadNotificationTable("#history-table", {
|
||||
name: 'history',
|
||||
|
Loading…
Reference in New Issue
Block a user