From 3e31aa62f684afd39d211585916e18372d08d113 Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Thu, 11 Jan 2024 11:02:10 +0100 Subject: [PATCH 1/3] 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 Closes #260 --- .../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 %} From 84073ef88fbe3fb3ea7365ac1525214f5a7e8392 Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Tue, 16 Jan 2024 09:37:15 +0100 Subject: [PATCH 2/3] Render notifications before project/organization header --- .../organizations/partials/header.html | 19 ++++++++++--------- .../templates/projects/partials/header.html | 16 ++++++++-------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/readthedocsext/theme/templates/organizations/partials/header.html b/readthedocsext/theme/templates/organizations/partials/header.html index 58472314..e617fcf8 100644 --- a/readthedocsext/theme/templates/organizations/partials/header.html +++ b/readthedocsext/theme/templates/organizations/partials/header.html @@ -20,6 +20,16 @@ {% endcomment %} {% block organization_header %} + {# Render all the notifications attached to the organization.#} + {% for notification in organization.notifications.all %} +
+ + {{ notification.get_message.get_rendered_body|safe }} +
+ {% endfor %} + + +
{% block organization_header_metadata %} @@ -126,13 +136,4 @@
{% 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 a2b7f5de..ca116984 100644 --- a/readthedocsext/theme/templates/projects/partials/header.html +++ b/readthedocsext/theme/templates/projects/partials/header.html @@ -20,6 +20,14 @@ {% endcomment %} {% block project_header %} + {# Render all the notifications attached to the project.#} + {% for notification in project.notifications.all %} +
+ + {{ notification.get_message.get_rendered_body|safe }} +
+ {% endfor %} +
{% block project_header_metadata %} @@ -201,12 +209,4 @@
{% 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 %} From 1531452b7b96b07fbf5320821534c90d2e4dd09b Mon Sep 17 00:00:00 2001 From: Manuel Kaufmann Date: Wed, 17 Jan 2024 10:44:00 +0100 Subject: [PATCH 3/3] Apply suggestions from code review Co-authored-by: Anthony --- .../theme/templates/organizations/partials/header.html | 2 +- readthedocsext/theme/templates/projects/partials/header.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/readthedocsext/theme/templates/organizations/partials/header.html b/readthedocsext/theme/templates/organizations/partials/header.html index e617fcf8..5c6fed5e 100644 --- a/readthedocsext/theme/templates/organizations/partials/header.html +++ b/readthedocsext/theme/templates/organizations/partials/header.html @@ -23,7 +23,7 @@ {# Render all the notifications attached to the organization.#} {% for notification in organization.notifications.all %}
- + {{ notification.get_message.get_rendered_body|safe }}
{% endfor %} diff --git a/readthedocsext/theme/templates/projects/partials/header.html b/readthedocsext/theme/templates/projects/partials/header.html index ca116984..2be5e26d 100644 --- a/readthedocsext/theme/templates/projects/partials/header.html +++ b/readthedocsext/theme/templates/projects/partials/header.html @@ -23,7 +23,7 @@ {# Render all the notifications attached to the project.#} {% for notification in project.notifications.all %}
- + {{ notification.get_message.get_rendered_body|safe }}
{% endfor %}