Rewrite notif page

This commit is contained in:
cuom1999 2024-04-26 20:55:24 -05:00
parent 1439dd12c8
commit 55a85689e9
3 changed files with 14 additions and 7 deletions

View file

@ -1163,8 +1163,7 @@ urlpatterns = [
), ),
url( url(
r"^notifications/", r"^notifications/",
login_required(notification.NotificationList.as_view()), paged_list_view(notification.NotificationList, "notification"),
name="notification",
), ),
url( url(
r"^import_users/", r"^import_users/",

View file

@ -2,24 +2,27 @@ from django.contrib.auth.decorators import login_required
from django.views.generic import ListView from django.views.generic import ListView
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
from django.utils.timezone import now from django.utils.timezone import now
from django.http import Http404
from judge.models import Profile, Notification, NotificationProfile from judge.models import Profile, Notification, NotificationProfile
from judge.models.notification import unseen_notifications_count from judge.models.notification import unseen_notifications_count
from judge.utils.infinite_paginator import InfinitePaginationMixin
__all__ = ["NotificationList"] __all__ = ["NotificationList"]
class NotificationList(ListView): class NotificationList(InfinitePaginationMixin, ListView):
model = Notification model = Notification
context_object_name = "notifications" context_object_name = "notifications"
template_name = "notification/list.html" template_name = "notification/list.html"
paginate_by = 50
def get_queryset(self): def get_queryset(self):
self.unseen_cnt = unseen_notifications_count(self.request.profile) self.unseen_cnt = unseen_notifications_count(self.request.profile)
self.queryset = Notification.objects.filter( self.queryset = Notification.objects.filter(
owner=self.request.profile owner=self.request.profile
).order_by("-id")[:100] ).order_by("-id")
return self.queryset return self.queryset
@ -27,11 +30,13 @@ class NotificationList(ListView):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context["unseen_count"] = self.unseen_cnt context["unseen_count"] = self.unseen_cnt
context["title"] = _("Notifications (%d unseen)") % context["unseen_count"] context["title"] = _("Notifications (%d unseen)") % context["unseen_count"]
context["has_notifications"] = self.queryset.exists() context["first_page_href"] = "."
return context return context
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
ret = super().get(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) NotificationProfile.objects.filter(user=request.profile).update(unread_count=0)
unseen_notifications_count.dirty(self.request.profile) unseen_notifications_count.dirty(self.request.profile)
return ret return ret

View file

@ -1,7 +1,7 @@
{% extends "base.html" %} {% extends "base.html" %}
{% block body %} {% block body %}
{% if not has_notifications %} {% if not notifications %}
<h2 style="text-align: center;">{{ _('You have no notifications') }}</h2> <h2 style="text-align: center;">{{ _('You have no notifications') }}</h2>
{% else %} {% else %}
<table class="table"> <table class="table">
@ -14,7 +14,7 @@
{% for notification in notifications %} {% for notification in notifications %}
<tr class="{{ 'highlight' if not notification.seen }}"> <tr class="{{ 'highlight' if not notification.seen }}">
<td> <td>
{{ link_user(notification.author) }} {{ link_user(notification.author_id) }}
</td> </td>
<td> <td>
{{ notification.category }} {{ notification.category }}
@ -31,5 +31,8 @@
{% endfor %} {% endfor %}
</table> </table>
{% endif %} {% endif %}
<div style="margin-top: 10px;">
{% include "list-pages.html" %}
</div>
{% endblock %} {% endblock %}