diff --git a/dmoj/urls.py b/dmoj/urls.py index f2d3265..91a649a 100644 --- a/dmoj/urls.py +++ b/dmoj/urls.py @@ -1163,8 +1163,7 @@ urlpatterns = [ ), url( r"^notifications/", - login_required(notification.NotificationList.as_view()), - name="notification", + paged_list_view(notification.NotificationList, "notification"), ), url( r"^import_users/", diff --git a/judge/views/notification.py b/judge/views/notification.py index bb79317..ee720c1 100644 --- a/judge/views/notification.py +++ b/judge/views/notification.py @@ -2,24 +2,27 @@ from django.contrib.auth.decorators import login_required from django.views.generic import ListView from django.utils.translation import ugettext as _ from django.utils.timezone import now +from django.http import Http404 from judge.models import Profile, Notification, NotificationProfile from judge.models.notification import unseen_notifications_count +from judge.utils.infinite_paginator import InfinitePaginationMixin __all__ = ["NotificationList"] -class NotificationList(ListView): +class NotificationList(InfinitePaginationMixin, ListView): model = Notification context_object_name = "notifications" template_name = "notification/list.html" + paginate_by = 50 def get_queryset(self): self.unseen_cnt = unseen_notifications_count(self.request.profile) self.queryset = Notification.objects.filter( owner=self.request.profile - ).order_by("-id")[:100] + ).order_by("-id") return self.queryset @@ -27,11 +30,13 @@ class NotificationList(ListView): context = super().get_context_data(**kwargs) context["unseen_count"] = self.unseen_cnt context["title"] = _("Notifications (%d unseen)") % context["unseen_count"] - context["has_notifications"] = self.queryset.exists() + context["first_page_href"] = "." return context def get(self, request, *args, **kwargs): ret = super().get(request, *args, **kwargs) + if not request.user.is_authenticated: + raise Http404() NotificationProfile.objects.filter(user=request.profile).update(unread_count=0) unseen_notifications_count.dirty(self.request.profile) return ret diff --git a/templates/notification/list.html b/templates/notification/list.html index 6aa7351..e266081 100644 --- a/templates/notification/list.html +++ b/templates/notification/list.html @@ -1,7 +1,7 @@ {% extends "base.html" %} {% block body %} - {% if not has_notifications %} + {% if not notifications %}

{{ _('You have no notifications') }}

{% else %} @@ -14,7 +14,7 @@ {% for notification in notifications %}
- {{ link_user(notification.author) }} + {{ link_user(notification.author_id) }} {{ notification.category }} @@ -31,5 +31,8 @@ {% endfor %}
{% endif %} +
+ {% include "list-pages.html" %} +
{% endblock %}