From 454dd25681af9de9e08ddc021eb29c25ec1ab2f8 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 30 Apr 2021 07:49:34 -0700 Subject: [PATCH 01/20] Only make notification count red for mentions --- bookwyrm/models/user.py | 13 +++++++++++++ bookwyrm/static/js/bookwyrm.js | 2 ++ bookwyrm/templates/layout.html | 7 +++++-- bookwyrm/views/updates.py | 3 ++- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index 3efbd6ac8..257264681 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -150,6 +150,19 @@ class User(OrderedCollectionPageMixin, AbstractUser): """for consistent naming""" return not self.is_active + @property + def unread_notification_count(self): + """ count of notifications, for the templates """ + return self.notification_set.filter(read=False).count() + + @property + def has_unread_mentions(self): + """ whether any of the unread notifications are conversations """ + return self.notification_set.filter( + read=False, + notification_type__in=["REPLY", "MENTION", "TAG"], + ).exists() + activity_serializer = activitypub.Person @classmethod diff --git a/bookwyrm/static/js/bookwyrm.js b/bookwyrm/static/js/bookwyrm.js index 485daf15b..3659a20e4 100644 --- a/bookwyrm/static/js/bookwyrm.js +++ b/bookwyrm/static/js/bookwyrm.js @@ -97,10 +97,12 @@ let BookWyrm = new class { updateCountElement(counter, data) { const currentCount = counter.innerText; const count = data.count; + const hasMentions = data.has_mentions; if (count != currentCount) { this.addRemoveClass(counter.closest('[data-poll-wrapper]'), 'is-hidden', count < 1); counter.innerText = count; + this.addRemoveClass(counter.closest('[data-poll-wrapper]'), 'is-danger', hasMentions); } } diff --git a/bookwyrm/templates/layout.html b/bookwyrm/templates/layout.html index 84482cdfc..770666e80 100644 --- a/bookwyrm/templates/layout.html +++ b/bookwyrm/templates/layout.html @@ -135,8 +135,11 @@ {% trans "Notifications" %} - - {{ request.user | notification_count }} + + {{ request.user.unread_notification_count }} diff --git a/bookwyrm/views/updates.py b/bookwyrm/views/updates.py index 349022724..726145626 100644 --- a/bookwyrm/views/updates.py +++ b/bookwyrm/views/updates.py @@ -10,7 +10,8 @@ def get_notification_count(request): """any notifications waiting?""" return JsonResponse( { - "count": request.user.notification_set.filter(read=False).count(), + "count": request.user.unread_notification_count, + "has_mentions": request.user.has_unread_mentions, } ) From 2867d703ccc32dada6f9e85c815e3c04354a9788 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 30 Apr 2021 07:57:38 -0700 Subject: [PATCH 02/20] Fixes python formatting --- bookwyrm/models/user.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index 257264681..2c5bef4ae 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -152,12 +152,12 @@ class User(OrderedCollectionPageMixin, AbstractUser): @property def unread_notification_count(self): - """ count of notifications, for the templates """ + """count of notifications, for the templates""" return self.notification_set.filter(read=False).count() @property def has_unread_mentions(self): - """ whether any of the unread notifications are conversations """ + """whether any of the unread notifications are conversations""" return self.notification_set.filter( read=False, notification_type__in=["REPLY", "MENTION", "TAG"], From d2355fef96e8ea517815a2163239fb70236164d4 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 30 Apr 2021 08:23:02 -0700 Subject: [PATCH 03/20] Consistent display on followers/following pages --- bookwyrm/templates/user/followers.html | 2 +- bookwyrm/templates/user/following.html | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/bookwyrm/templates/user/followers.html b/bookwyrm/templates/user/followers.html index b294db909..2a7ccd1e9 100644 --- a/bookwyrm/templates/user/followers.html +++ b/bookwyrm/templates/user/followers.html @@ -25,7 +25,7 @@ {% endfor %} - {% if not followers.count %} + {% if not followers %}
{% blocktrans with username=user.display_name %}{{ username }} has no followers{% endblocktrans %}
{% endif %} diff --git a/bookwyrm/templates/user/following.html b/bookwyrm/templates/user/following.html index 38c01ad27..b41d51264 100644 --- a/bookwyrm/templates/user/following.html +++ b/bookwyrm/templates/user/following.html @@ -20,12 +20,12 @@ ({{ follower.username }}) -
+
{% include 'snippets/follow_button.html' with user=follower %}
{% endfor %} - {% if not following.count %} + {% if not following %}
{% blocktrans with username=user|username %}{{ username }} isn't following any users{% endblocktrans %}
{% endif %} From 862ef835366bb716a47f8716c9713ed301e51b36 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 30 Apr 2021 08:40:47 -0700 Subject: [PATCH 04/20] Move user templates into more subdirectories --- bookwyrm/templates/goal.html | 2 +- .../templates/user/{user_layout.html => layout.html} | 0 .../templates/user/{ => relationships}/followers.html | 2 +- .../templates/user/{ => relationships}/following.html | 2 +- bookwyrm/templates/user/{ => shelf}/books_header.html | 0 .../templates/user/{ => shelf}/create_shelf_form.html | 0 .../templates/user/{ => shelf}/edit_shelf_form.html | 0 bookwyrm/templates/user/{ => shelf}/shelf.html | 10 +++++----- bookwyrm/templates/user/user.html | 8 ++++---- bookwyrm/views/shelf.py | 2 +- bookwyrm/views/user.py | 4 ++-- 11 files changed, 15 insertions(+), 15 deletions(-) rename bookwyrm/templates/user/{user_layout.html => layout.html} (100%) rename bookwyrm/templates/user/{ => relationships}/followers.html (96%) rename bookwyrm/templates/user/{ => relationships}/following.html (96%) rename bookwyrm/templates/user/{ => shelf}/books_header.html (100%) rename bookwyrm/templates/user/{ => shelf}/create_shelf_form.html (100%) rename bookwyrm/templates/user/{ => shelf}/edit_shelf_form.html (100%) rename bookwyrm/templates/user/{ => shelf}/shelf.html (94%) diff --git a/bookwyrm/templates/goal.html b/bookwyrm/templates/goal.html index 32b5062dc..22aba08e4 100644 --- a/bookwyrm/templates/goal.html +++ b/bookwyrm/templates/goal.html @@ -1,4 +1,4 @@ -{% extends 'user/user_layout.html' %} +{% extends 'user/layout.html' %} {% load i18n %} {% block header %} diff --git a/bookwyrm/templates/user/user_layout.html b/bookwyrm/templates/user/layout.html similarity index 100% rename from bookwyrm/templates/user/user_layout.html rename to bookwyrm/templates/user/layout.html diff --git a/bookwyrm/templates/user/followers.html b/bookwyrm/templates/user/relationships/followers.html similarity index 96% rename from bookwyrm/templates/user/followers.html rename to bookwyrm/templates/user/relationships/followers.html index 2a7ccd1e9..c69416dce 100644 --- a/bookwyrm/templates/user/followers.html +++ b/bookwyrm/templates/user/relationships/followers.html @@ -1,4 +1,4 @@ -{% extends 'user/user_layout.html' %} +{% extends 'user/layout.html' %} {% load i18n %} {% load bookwyrm_tags %} diff --git a/bookwyrm/templates/user/following.html b/bookwyrm/templates/user/relationships/following.html similarity index 96% rename from bookwyrm/templates/user/following.html rename to bookwyrm/templates/user/relationships/following.html index b41d51264..a1feeb76a 100644 --- a/bookwyrm/templates/user/following.html +++ b/bookwyrm/templates/user/relationships/following.html @@ -1,4 +1,4 @@ -{% extends 'user/user_layout.html' %} +{% extends 'user/layout.html' %} {% load i18n %} {% load bookwyrm_tags %} diff --git a/bookwyrm/templates/user/books_header.html b/bookwyrm/templates/user/shelf/books_header.html similarity index 100% rename from bookwyrm/templates/user/books_header.html rename to bookwyrm/templates/user/shelf/books_header.html diff --git a/bookwyrm/templates/user/create_shelf_form.html b/bookwyrm/templates/user/shelf/create_shelf_form.html similarity index 100% rename from bookwyrm/templates/user/create_shelf_form.html rename to bookwyrm/templates/user/shelf/create_shelf_form.html diff --git a/bookwyrm/templates/user/edit_shelf_form.html b/bookwyrm/templates/user/shelf/edit_shelf_form.html similarity index 100% rename from bookwyrm/templates/user/edit_shelf_form.html rename to bookwyrm/templates/user/shelf/edit_shelf_form.html diff --git a/bookwyrm/templates/user/shelf.html b/bookwyrm/templates/user/shelf/shelf.html similarity index 94% rename from bookwyrm/templates/user/shelf.html rename to bookwyrm/templates/user/shelf/shelf.html index 336162588..93f0c15f2 100644 --- a/bookwyrm/templates/user/shelf.html +++ b/bookwyrm/templates/user/shelf/shelf.html @@ -1,16 +1,16 @@ -{% extends 'user/user_layout.html' %} +{% extends 'user/layout.html' %} {% load bookwyrm_tags %} {% load humanize %} {% load i18n %} {% block title %} -{% include 'user/books_header.html' %} +{% include 'user/shelf/books_header.html' %} {% endblock %} {% block header %}

- {% include 'user/books_header.html' %} + {% include 'user/shelf/books_header.html' %}

{% endblock %} @@ -41,7 +41,7 @@
- {% include 'user/create_shelf_form.html' with controls_text='create-shelf-form' %} + {% include 'user/shelf/create_shelf_form.html' with controls_text='create-shelf-form' %}
@@ -62,7 +62,7 @@
- {% include 'user/edit_shelf_form.html' with controls_text="edit-shelf-form" %} + {% include 'user/shelf/edit_shelf_form.html' with controls_text="edit-shelf-form" %}
diff --git a/bookwyrm/templates/user/user.html b/bookwyrm/templates/user/user.html index a97d26ab8..fead8fcf6 100644 --- a/bookwyrm/templates/user/user.html +++ b/bookwyrm/templates/user/user.html @@ -1,4 +1,4 @@ -{% extends 'user/user_layout.html' %} +{% extends 'user/layout.html' %} {% load i18n %} {% load bookwyrm_tags %} @@ -11,7 +11,7 @@
{% if is_self %}
- + {% trans "Edit profile" %} @@ -25,7 +25,7 @@ {% if user.bookwyrm_user %}

- {% include 'user/books_header.html' %} + {% include 'user/shelf/books_header.html' %}

{% for shelf in shelves %} @@ -56,7 +56,7 @@ {% elif user == request.user %} {% endif %} diff --git a/bookwyrm/views/shelf.py b/bookwyrm/views/shelf.py index 9bcf0a4ac..ca05ec1ee 100644 --- a/bookwyrm/views/shelf.py +++ b/bookwyrm/views/shelf.py @@ -68,7 +68,7 @@ class Shelf(View): "books": paginated.get_page(request.GET.get("page")), } - return TemplateResponse(request, "user/shelf.html", data) + return TemplateResponse(request, "user/shelf/shelf.html", data) @method_decorator(login_required, name="dispatch") # pylint: disable=unused-argument diff --git a/bookwyrm/views/user.py b/bookwyrm/views/user.py index d394c1d73..af31fd47f 100644 --- a/bookwyrm/views/user.py +++ b/bookwyrm/views/user.py @@ -112,7 +112,7 @@ class Followers(View): "is_self": request.user.id == user.id, "followers": paginated.page(request.GET.get("page", 1)), } - return TemplateResponse(request, "user/followers.html", data) + return TemplateResponse(request, "user/relationships/followers.html", data) class Following(View): @@ -138,7 +138,7 @@ class Following(View): "is_self": request.user.id == user.id, "following": paginated.page(request.GET.get("page", 1)), } - return TemplateResponse(request, "user/following.html", data) + return TemplateResponse(request, "user/relationships/following.html", data) @method_decorator(login_required, name="dispatch") From e4cecf2874103890be40f376cb399e2e21e7036c Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 30 Apr 2021 09:02:14 -0700 Subject: [PATCH 05/20] Coherent logic on which tabs show in the user page --- bookwyrm/templates/user/layout.html | 4 ++-- bookwyrm/templates/user/lists.html | 2 +- bookwyrm/templates/user/shelf/shelf.html | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/bookwyrm/templates/user/layout.html b/bookwyrm/templates/user/layout.html index 0c3e94e3c..0f04f6288 100644 --- a/bookwyrm/templates/user/layout.html +++ b/bookwyrm/templates/user/layout.html @@ -41,8 +41,8 @@
{% endif %}
+{% block tabs %} {% with user|username as username %} -{% if 'user/'|add:username|add:'/books' not in request.path and 'user/'|add:username|add:'/shelf' not in request.path %} -{% endif %} {% endwith %} +{% endblock %} {% block panel %}{% endblock %} diff --git a/bookwyrm/templates/user/lists.html b/bookwyrm/templates/user/lists.html index b2fd9eefd..aa8ad7fb6 100644 --- a/bookwyrm/templates/user/lists.html +++ b/bookwyrm/templates/user/lists.html @@ -1,4 +1,4 @@ -{% extends 'user/user_layout.html' %} +{% extends 'user/layout.html' %} {% load i18n %} {% block header %} diff --git a/bookwyrm/templates/user/shelf/shelf.html b/bookwyrm/templates/user/shelf/shelf.html index 93f0c15f2..639ab502f 100644 --- a/bookwyrm/templates/user/shelf/shelf.html +++ b/bookwyrm/templates/user/shelf/shelf.html @@ -15,7 +15,7 @@ {% endblock %} -{% block panel %} +{% block tabs %}
@@ -39,7 +39,9 @@
{% endif %}
+{% endblock %} +{% block panel %}
{% include 'user/shelf/create_shelf_form.html' with controls_text='create-shelf-form' %}
From 418e656aea8d5faf1b84afe27337891324f22f0c Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 30 Apr 2021 09:17:46 -0700 Subject: [PATCH 06/20] Uses layout for followers/following page --- bookwyrm/templates/user/layout.html | 6 +++- .../user/relationships/followers.html | 30 ++++--------------- .../user/relationships/following.html | 30 ++++--------------- .../templates/user/relationships/layout.html | 29 ++++++++++++++++++ bookwyrm/views/user.py | 6 ++-- 5 files changed, 47 insertions(+), 54 deletions(-) create mode 100644 bookwyrm/templates/user/relationships/layout.html diff --git a/bookwyrm/templates/user/layout.html b/bookwyrm/templates/user/layout.html index 0f04f6288..dcdf7ccfc 100644 --- a/bookwyrm/templates/user/layout.html +++ b/bookwyrm/templates/user/layout.html @@ -7,7 +7,11 @@ {% block content %}
- {% block header %}{% endblock %} + {% block header %} +

+ {% trans "User Profile" %} +

+ {% endblock %}
{# user bio #} diff --git a/bookwyrm/templates/user/relationships/followers.html b/bookwyrm/templates/user/relationships/followers.html index c69416dce..223f38c7b 100644 --- a/bookwyrm/templates/user/relationships/followers.html +++ b/bookwyrm/templates/user/relationships/followers.html @@ -1,34 +1,14 @@ -{% extends 'user/layout.html' %} +{% extends 'user/relationships/layout.html' %} {% load i18n %} -{% load bookwyrm_tags %} {% block header %}

- {% trans "User Profile" %} + {% trans "Followers" %}

{% endblock %} -{% block panel %} -
-

{% trans "Followers" %}

- {% for follower in followers %} -
- -
- {% include 'snippets/follow_button.html' with user=follower %} -
-
- {% endfor %} - {% if not followers %} -
{% blocktrans with username=user.display_name %}{{ username }} has no followers{% endblocktrans %}
- {% endif %} +{% block nullstate %} +
+ {% blocktrans with username=user.display_name %}{{ username }} has no followers{% endblocktrans %}
- -{% include 'snippets/pagination.html' with page=followers path=request.path %} {% endblock %} diff --git a/bookwyrm/templates/user/relationships/following.html b/bookwyrm/templates/user/relationships/following.html index a1feeb76a..5689bc613 100644 --- a/bookwyrm/templates/user/relationships/following.html +++ b/bookwyrm/templates/user/relationships/following.html @@ -1,34 +1,14 @@ -{% extends 'user/layout.html' %} +{% extends 'user/relationships/layout.html' %} {% load i18n %} -{% load bookwyrm_tags %} {% block header %}

- {% trans "User Profile" %} + {% trans "Following" %}

{% endblock %} -{% block panel %} -
-

{% trans "Following" %}

- {% for follower in user.following.all %} -
- -
- {% include 'snippets/follow_button.html' with user=follower %} -
-
- {% endfor %} - {% if not following %} -
{% blocktrans with username=user|username %}{{ username }} isn't following any users{% endblocktrans %}
- {% endif %} +{% block nullstate %} +
+ {% blocktrans with username=user.display_name %}{{ username }} isn't following any users{% endblocktrans %}
- -{% include 'snippets/pagination.html' with page=following path=request.path %} {% endblock %} diff --git a/bookwyrm/templates/user/relationships/layout.html b/bookwyrm/templates/user/relationships/layout.html new file mode 100644 index 000000000..ab38e6620 --- /dev/null +++ b/bookwyrm/templates/user/relationships/layout.html @@ -0,0 +1,29 @@ +{% extends 'user/layout.html' %} +{% load i18n %} +{% load bookwyrm_tags %} + +{% block panel %} +
+ {% for follow in follow_list %} +
+ +
+ {% include 'snippets/follow_button.html' with user=follow %} +
+
+ {% endfor %} + + {% if not follow_list %} + {% block nullstate %} + {% endblock %} + {% endif %} +
+ +{% include 'snippets/pagination.html' with page=follow_list path=request.path %} +{% endblock %} diff --git a/bookwyrm/views/user.py b/bookwyrm/views/user.py index af31fd47f..5584ce991 100644 --- a/bookwyrm/views/user.py +++ b/bookwyrm/views/user.py @@ -110,7 +110,7 @@ class Followers(View): data = { "user": user, "is_self": request.user.id == user.id, - "followers": paginated.page(request.GET.get("page", 1)), + "follow_list": paginated.page(request.GET.get("page", 1)), } return TemplateResponse(request, "user/relationships/followers.html", data) @@ -132,11 +132,11 @@ class Following(View): if is_api_request(request): return ActivitypubResponse(user.to_following_activity(**request.GET)) - paginated = Paginator(user.followers.all(), PAGE_LENGTH) + paginated = Paginator(user.following.all(), PAGE_LENGTH) data = { "user": user, "is_self": request.user.id == user.id, - "following": paginated.page(request.GET.get("page", 1)), + "follow_list": paginated.page(request.GET.get("page", 1)), } return TemplateResponse(request, "user/relationships/following.html", data) From b65d0d05c9f49c375f32f8252d33a091aac3f0aa Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 30 Apr 2021 09:23:59 -0700 Subject: [PATCH 07/20] Tabs for relationship views --- bookwyrm/templates/user/layout.html | 1 + .../templates/user/relationships/layout.html | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/bookwyrm/templates/user/layout.html b/bookwyrm/templates/user/layout.html index dcdf7ccfc..661d80781 100644 --- a/bookwyrm/templates/user/layout.html +++ b/bookwyrm/templates/user/layout.html @@ -45,6 +45,7 @@
{% endif %}
+ {% block tabs %} {% with user|username as username %}
From c373a0b818dfea5ebe8a7aa1e9ce1c409c68bf3d Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 30 Apr 2021 13:38:03 -0700 Subject: [PATCH 19/20] Highlight report notifications --- bookwyrm/models/user.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index 2c5bef4ae..7c943bec9 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -160,7 +160,7 @@ class User(OrderedCollectionPageMixin, AbstractUser): """whether any of the unread notifications are conversations""" return self.notification_set.filter( read=False, - notification_type__in=["REPLY", "MENTION", "TAG"], + notification_type__in=["REPLY", "MENTION", "TAG", "REPORT"], ).exists() activity_serializer = activitypub.Person From 544e29fe76754bdaa1589bac7288cddc9d7b3d3c Mon Sep 17 00:00:00 2001 From: Fabien Basmaison Date: Fri, 30 Apr 2021 22:44:53 +0200 Subject: [PATCH 20/20] Fix lists layout for user. --- bookwyrm/templates/user/lists.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/templates/user/lists.html b/bookwyrm/templates/user/lists.html index b2fd9eefd..8fe149d58 100644 --- a/bookwyrm/templates/user/lists.html +++ b/bookwyrm/templates/user/lists.html @@ -23,7 +23,7 @@ {% block panel %} -
+