bookwyrm-mastodon/bookwyrm/views/notifications.py

29 lines
1.0 KiB
Python
Raw Normal View History

2021-03-08 11:49:10 -05:00
""" non-interactive pages """
2021-01-12 14:07:29 -05: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 11:49:10 -05:00
@method_decorator(login_required, name="dispatch")
2021-01-12 14:07:29 -05:00
class Notifications(View):
2021-04-26 12:15:42 -04:00
"""notifications view"""
2021-03-08 11:49:10 -05:00
2021-01-12 14:07:29 -05:00
def get(self, request):
2021-04-26 12:15:42 -04:00
"""people are interacting with you, get hyped"""
2021-03-08 11:49:10 -05:00
notifications = request.user.notification_set.all().order_by("-created_date")
2021-01-12 14:07:29 -05:00
unread = [n.id for n in notifications.filter(read=False)]
data = {
2021-03-08 11:49:10 -05:00
"notifications": notifications,
"unread": unread,
2021-01-12 14:07:29 -05:00
}
notifications.update(read=True)
2021-03-08 11:49:10 -05:00
return TemplateResponse(request, "notifications.html", data)
2021-01-12 14:07:29 -05:00
def post(self, request):
2021-04-26 12:15:42 -04:00
"""permanently delete notification for user"""
2021-01-12 14:07:29 -05:00
request.user.notification_set.filter(read=True).delete()
2021-03-08 11:49:10 -05:00
return redirect("/notifications")