Skip to content
Snippets Groups Projects
Verified Commit ec82cb36 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Add own page with own menu item for notifications

parent 496a07cf
No related branches found
No related tags found
1 merge request!447Resolve "Add own menu entry for notifications"
Pipeline #5333 passed
from django.conf import settings
from django.utils.translation import gettext_lazy as _
from .util.core_helpers import unread_notifications_badge
MENUS = {
"NAV_MENU_CORE": [
{
......@@ -15,6 +17,15 @@ MENUS = {
"icon": "home",
"validators": ["menu_generator.validators.is_authenticated"],
},
{
"name": _("Notifications"),
"url": "notifications",
"icon": "notifications",
"badge": unread_notifications_badge,
"validators": [
("aleksis.core.util.predicates.permission_validator", "core.view_notifications",),
],
},
{
"name": _("Account"),
"url": "#",
......
......@@ -16,6 +16,9 @@ rules.add_perm("core", rules.always_allow)
# View dashboard
rules.add_perm("core.view_dashboard", has_person)
# View notifications
rules.add_perm("core.view_notifications", has_person)
# Use search
search_predicate = has_person & has_global_perm("core.search")
rules.add_perm("core.search", search_predicate)
......
{% extends 'core/base.html' %}
{% load i18n static dashboard %}
{% block browser_title %}{% blocktrans %}Notifications{% endblocktrans %}{% endblock %}
{% block page_title %}{% blocktrans %}Notifications{% endblocktrans %}{% endblock %}
{% block content %}
{% if object_list %}
<ul class="collection">
{% for notification in object_list %}
<li class="collection-item">
<span class="badge new primary-color">{{ notification.sender }}</span>
<span class="title">{{ notification.title }}</span>
<p>
<i class="material-icons left">access_time</i> {{ notification.created }}
</p>
<p>
{{ notification.description }}
</p>
{% if notification.link %}
<p>
<a href="{{ notification.link }}">{% blocktrans %}More information →{% endblocktrans %}</a>
</p>
{% endif %}
</li>
{% endfor %}
</ul>
{% else %}
<p>{% blocktrans %}No notifications available yet.{% endblocktrans %}</p>
{% endif %}
{% endblock %}
......@@ -57,6 +57,7 @@ urlpatterns = [
path("group/<int:id_>/edit", views.edit_group, name="edit_group_by_id"),
path("group/<int:id_>/delete", views.delete_group, name="delete_group_by_id"),
path("", views.index, name="index"),
path("notifications/", views.Notifications.as_view(), name="notifications"),
path("dashboard/edit/", views.EditDashboardView.as_view(), name="edit_dashboard"),
path(
"notifications/mark-read/<int:id_>",
......
......@@ -401,3 +401,8 @@ def queryset_rules_filter(
wanted_objects.add(item.pk)
return queryset.filter(pk__in=wanted_objects)
def unread_notifications_badge(request: HttpRequest) -> int:
"""Generate badge content with the number of unread notifications."""
return request.user.person.notifications.all().filter(read=False).count()
......@@ -109,6 +109,18 @@ def index(request: HttpRequest) -> HttpResponse:
return render(request, "core/index.html", context)
class Notifications(PermissionRequiredMixin, ListView):
permission_required = "core.view_notifications"
template_name = "core/notifications.html"
def get_queryset(self) -> QuerySet:
return self.request.user.person.notifications.order_by("-created")
def get_context_data(self, **kwargs: Any) -> Dict[str, Any]:
self.get_queryset().filter(read=False).update(read=True)
return super().get_context_data(**kwargs)
def about(request: HttpRequest) -> HttpResponse:
"""About page listing all apps."""
context = {}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment