2021-03-08 08:49:10 -08:00
|
|
|
""" non-interactive pages """
|
2021-01-12 11:07:29 -08:00
|
|
|
from django.contrib.auth.decorators import login_required
|
|
|
|
from django.template.response import TemplateResponse
|
|
|
|
from django.utils.decorators import method_decorator
|
|
|
|
from django.shortcuts import redirect
|
|
|
|
from django.views import View
|
|
|
|
|
|
|
|
|
|
|
|
# pylint: disable= no-self-use
|
2021-03-08 08:49:10 -08:00
|
|
|
@method_decorator(login_required, name="dispatch")
|
2021-01-12 11:07:29 -08:00
|
|
|
class Notifications(View):
|
2021-04-26 09:15:42 -07:00
|
|
|
"""notifications view"""
|
2021-03-08 08:49:10 -08:00
|
|
|
|
2021-05-07 13:55:41 -07:00
|
|
|
def get(self, request, notification_type=None):
|
2021-04-26 09:15:42 -07:00
|
|
|
"""people are interacting with you, get hyped"""
|
2021-10-02 10:10:25 -07:00
|
|
|
notifications = (
|
|
|
|
request.user.notification_set.all()
|
2022-07-04 21:32:53 -07:00
|
|
|
.order_by("-updated_date")
|
|
|
|
.select_related(
|
|
|
|
"related_status",
|
2022-07-06 19:16:14 -07:00
|
|
|
"related_status__reply_parent",
|
2022-07-04 21:32:53 -07:00
|
|
|
"related_group",
|
2022-07-06 19:16:14 -07:00
|
|
|
"related_import",
|
2022-07-04 21:32:53 -07:00
|
|
|
)
|
2022-07-04 18:51:07 -07:00
|
|
|
.prefetch_related(
|
|
|
|
"related_reports",
|
|
|
|
"related_users",
|
|
|
|
"related_list_items",
|
2021-10-02 10:10:25 -07:00
|
|
|
)
|
|
|
|
)
|
2021-05-07 13:55:41 -07:00
|
|
|
if notification_type == "mentions":
|
|
|
|
notifications = notifications.filter(
|
|
|
|
notification_type__in=["REPLY", "MENTION", "TAG"]
|
|
|
|
)
|
|
|
|
unread = [n.id for n in notifications.filter(read=False)[:50]]
|
2021-01-12 11:07:29 -08:00
|
|
|
data = {
|
2021-04-26 10:26:27 -07:00
|
|
|
"notifications": notifications[:50],
|
2021-03-08 08:49:10 -08:00
|
|
|
"unread": unread,
|
2021-01-12 11:07:29 -08:00
|
|
|
}
|
|
|
|
notifications.update(read=True)
|
2021-10-02 07:58:20 -07:00
|
|
|
return TemplateResponse(request, "notifications/notifications_page.html", data)
|
2021-01-12 11:07:29 -08:00
|
|
|
|
|
|
|
def post(self, request):
|
2021-04-26 09:15:42 -07:00
|
|
|
"""permanently delete notification for user"""
|
2021-01-12 11:07:29 -08:00
|
|
|
request.user.notification_set.filter(read=True).delete()
|
2021-09-27 10:17:16 -07:00
|
|
|
return redirect("notifications")
|