-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #489 from elixir-luxembourg/implement-notification…
…-views-react Implement notification views
- Loading branch information
Showing
44 changed files
with
12,953 additions
and
5,426 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import logging | ||
|
||
from django.views.decorators.http import require_http_methods | ||
from django.core.exceptions import PermissionDenied | ||
from django.db.models import QuerySet | ||
from django.http import JsonResponse | ||
|
||
from notification.models import Notification | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def jsonify(data): | ||
if isinstance(data, QuerySet) or isinstance(data, list): | ||
data = [o.to_json() for o in data] | ||
else: | ||
data = data.to_json() | ||
|
||
return JsonResponse({"data": data}, status=200) | ||
|
||
|
||
@require_http_methods(["PATCH"]) | ||
def api_dismiss_notification(request, pk): | ||
notification = Notification.objects.get(pk=pk) | ||
if request.user != notification.recipient: | ||
raise PermissionDenied( | ||
"You cannot dismiss a notification you are not the recipient of" | ||
) | ||
logger.debug(f"Dismissing user {request.user.pk} notification {notification.pk}") | ||
notification.dismissed = True | ||
notification.save() | ||
|
||
notification_list = Notification.objects.filter( | ||
recipient=request.user, | ||
content_type=notification.content_type, | ||
dispatch_in_app=True, | ||
) | ||
return jsonify(notification_list) | ||
|
||
|
||
@require_http_methods(["PATCH"]) | ||
def api_dismiss_all_notifications(request, object_type): | ||
logger.debug(f"Dismissing notifications for object_type {object_type}") | ||
notification_list = Notification.objects.filter( | ||
recipient=request.user, | ||
content_type__model=object_type, | ||
dispatch_in_app=True, | ||
) | ||
for notif in notification_list: | ||
notif.dismissed = True | ||
notif.save() | ||
|
||
logger.debug( | ||
f"Successfully dismissed {len(notification_list)} notifications for user {request.user.pk}" | ||
) | ||
return jsonify(notification_list) | ||
|
||
|
||
@require_http_methods(["GET"]) | ||
def api_get_notifications(request): | ||
notifications_list = Notification.objects.filter( | ||
dispatch_in_app=True, | ||
) | ||
if request.GET.get("show_dismissed") != "true": | ||
notifications_list = notifications_list.filter(dismissed=False) | ||
if request.GET.get("as_admin") != "true": | ||
notifications_list = notifications_list.filter(recipient__pk=request.user.pk) | ||
elif request.GET.get("recipient", ""): | ||
notifications_list = notifications_list.filter( | ||
recipient__pk=request.GET.get("recipient") | ||
) | ||
|
||
return jsonify(notifications_list.all()) | ||
|
||
|
||
@require_http_methods(["GET"]) | ||
def api_get_notifications_number(request): | ||
number = Notification.objects.filter( | ||
recipient=request.user, | ||
dismissed=False, | ||
dispatch_in_app=True, | ||
).count() | ||
|
||
return JsonResponse({"success": True, "data": number}, status=200) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
.dataTables_wrapper .dataTables_length, | ||
.dataTables_wrapper .dataTables_filter, | ||
.dataTables_wrapper .dataTables_info, | ||
.dataTables_wrapper .dataTables_processing, | ||
.dataTables_wrapper .dataTables_paginate { | ||
display: flex; | ||
color: #333333; | ||
} | ||
|
||
.dataTables_wrapper .dataTables_paginate span { | ||
display: flex; | ||
} | ||
|
||
.dataTables_wrapper .dataTables_paginate .paginate_button { | ||
min-width: 2.6em; | ||
margin-right: 0.5em; | ||
text-align: center; | ||
border-radius: 4em; | ||
position: relative; | ||
display: block; | ||
padding: 0.5rem 0.75rem; | ||
margin-left: 0; | ||
line-height: 1.25; | ||
color: #023452 !important; | ||
background: transparent !important; | ||
border: 0 solid #dee2e6 !important; | ||
} | ||
|
||
.dataTables_wrapper .dataTables_paginate .paginate_button:hover { | ||
z-index: 2; | ||
text-decoration: none; | ||
color: #000507 !important; | ||
background-color: #e9ecef !important; | ||
border-color: #dee2e6 !important; | ||
} | ||
|
||
.dataTables_wrapper .dataTables_paginate .paginate_button:active, | ||
.dataTables_wrapper .dataTables_paginate .paginate_button:not(:disabled):not(.disabled).active, | ||
.dataTables_wrapper .dataTables_paginate .paginate_button:not(:disabled):not(.disabled).active:hover, | ||
.dataTables_wrapper .dataTables_paginate .paginate_button:not(:disabled):not(.disabled).current, | ||
.dataTables_wrapper .dataTables_paginate .paginate_button:not(:disabled):not(.disabled).current:hover { | ||
z-index: 1; | ||
color: #fff !important; | ||
background-color: #023452 !important; | ||
border-color: #023452 !important; | ||
} | ||
|
||
.dataTables_wrapper .dataTables_paginate .paginate_button:focus { | ||
z-index: 2; | ||
outline: 0; | ||
box-shadow: 0 0 0 0.2rem rgba(2, 52, 82, 0.25); | ||
} | ||
|
||
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled, | ||
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled:hover, | ||
.dataTables_wrapper .dataTables_paginate .paginate_button.disabled:active { | ||
cursor: default; | ||
color: #666 !important; | ||
border: 0 solid transparent !important; | ||
background: transparent !important; | ||
box-shadow: none !important; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.card-badge { | ||
position: absolute; | ||
right: 25px; | ||
bottom: 35%; | ||
} |
Oops, something went wrong.