From bbfd72cff0b36cdd6463a2e25f73be08558304b2 Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Thu, 11 Jan 2024 11:02:10 +0100 Subject: [PATCH] Notifications: show attached to `User`, `Project` and `Organization` Render notifications attached to these objects. This is the first pass of this work and there are some things we need to make decisions and improve. - Where (what pages) these notifications should render? - How "global" they should be considered? Note we are rendering these notifications in the template for now, but in the future they will be rendered using the APIv3: #259 --- .../templates/includes/utils/messages.html | 17 +++++++++++++++++ .../organizations/partials/header.html | 9 +++++++++ .../templates/projects/partials/header.html | 8 ++++++++ 3 files changed, 34 insertions(+) diff --git a/readthedocsext/theme/templates/includes/utils/messages.html b/readthedocsext/theme/templates/includes/utils/messages.html index c379eaa5..7fb3b5ca 100644 --- a/readthedocsext/theme/templates/includes/utils/messages.html +++ b/readthedocsext/theme/templates/includes/utils/messages.html @@ -7,6 +7,23 @@ page content pane. {% endcomment %} +{% comment %} +``user_notifications`` comes from a Context Processor. +We need to use a CustomUser to have access to "user.notifications" +See https://docs.djangoproject.com/en/4.2/ref/settings/#std-setting-AUTH_USER_MODEL +{% endcomment %} +{% if user_notifications %} + {% for notification in user_notifications %} +
+ {% comment %} + Add this Xmark here once we implement dismissing notifications. + + {% endcomment %} + {{ notification.get_message.get_rendered_body|safe }} +
+ {% endfor %} +{% endif %} + {% if messages %} {% for message in messages %} {% comment %} diff --git a/readthedocsext/theme/templates/organizations/partials/header.html b/readthedocsext/theme/templates/organizations/partials/header.html index 79366b61..58472314 100644 --- a/readthedocsext/theme/templates/organizations/partials/header.html +++ b/readthedocsext/theme/templates/organizations/partials/header.html @@ -126,4 +126,13 @@ {% endblock organization_header_navigation %} +{# Render all the notifications attached to the organization.#} + {% for notification in organization.notifications.all %} +
+ + {{ notification.get_message.get_rendered_body|safe }} +
+ {% endfor %} + + {% endblock organization_header %} diff --git a/readthedocsext/theme/templates/projects/partials/header.html b/readthedocsext/theme/templates/projects/partials/header.html index 5d44a8cb..a2b7f5de 100644 --- a/readthedocsext/theme/templates/projects/partials/header.html +++ b/readthedocsext/theme/templates/projects/partials/header.html @@ -201,4 +201,12 @@ {% endblock project_header_navigation %} +{# Render all the notifications attached to the project.#} + {% for notification in project.notifications.all %} +
+ + {{ notification.get_message.get_rendered_body|safe }} +
+ {% endfor %} + {% endblock project_header %}