From 527c0542af193885b546ff6e1a6871deaf674804 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 8 Sep 2021 10:02:06 -0700 Subject: [PATCH] View to hide suggestions --- bookwyrm/templates/feed/feed.html | 4 ++-- bookwyrm/templates/feed/suggested_users.html | 11 ++++++++++- bookwyrm/urls.py | 1 + bookwyrm/views/__init__.py | 2 +- bookwyrm/views/user.py | 12 ++++++++++++ 5 files changed, 26 insertions(+), 4 deletions(-) diff --git a/bookwyrm/templates/feed/feed.html b/bookwyrm/templates/feed/feed.html index 5c4e14e6..b8e351c9 100644 --- a/bookwyrm/templates/feed/feed.html +++ b/bookwyrm/templates/feed/feed.html @@ -37,7 +37,7 @@

{% trans "There aren't any activities right now! Try following a user to get started" %}

- {% if suggested_users %} + {% if request.user.show_suggested_users and suggested_users %} {# suggested users for when things are very lonely #} {% include 'feed/suggested_users.html' with suggested_users=suggested_users %} {% endif %} @@ -46,7 +46,7 @@ {% for activity in activities %} -{% if not activities.number > 1 and forloop.counter0 == 2 and suggested_users %} +{% if request.user.show_suggested_users and not activities.number > 1 and forloop.counter0 == 2 and suggested_users %} {# suggested users on the first page, two statuses down #} {% include 'feed/suggested_users.html' with suggested_users=suggested_users %} {% endif %} diff --git a/bookwyrm/templates/feed/suggested_users.html b/bookwyrm/templates/feed/suggested_users.html index 1de1ae13..4e9f822b 100644 --- a/bookwyrm/templates/feed/suggested_users.html +++ b/bookwyrm/templates/feed/suggested_users.html @@ -1,6 +1,15 @@ {% load i18n %}
-

{% trans "Who to follow" %}

+
+
+

{% trans "Who to follow" %}

+
+
+ {% csrf_token %} + {% trans "Don't show suggested users" as button_text %} + +
+
{% include 'snippets/suggested_users.html' with suggested_users=suggested_users %} {% trans "View directory" %}
diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 991114fa..9ae1b822 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -215,6 +215,7 @@ urlpatterns = [ views.Following.as_view(), name="user-following", ), + re_path(r"^hide-suggestions/?$", views.hide_suggestions, name="hide-suggestions"), # lists re_path(r"%s/lists/?$" % USER_PATH, views.UserLists.as_view(), name="user-lists"), re_path(r"^list/?$", views.Lists.as_view(), name="lists"), diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index 841026a5..5142d532 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -43,6 +43,6 @@ from .shelf import shelve, unshelve from .site import Site from .status import CreateStatus, DeleteStatus, DeleteAndRedraft from .updates import get_notification_count, get_unread_status_count -from .user import User, Followers, Following +from .user import User, Followers, Following, hide_suggestions from .user_admin import UserAdmin, UserAdminList from .wellknown import * diff --git a/bookwyrm/views/user.py b/bookwyrm/views/user.py index 87e42b4e..e335b02c 100644 --- a/bookwyrm/views/user.py +++ b/bookwyrm/views/user.py @@ -1,8 +1,11 @@ """ non-interactive pages """ +from django.contrib.auth.decorators import login_required from django.core.paginator import Paginator +from django.shortcuts import redirect from django.template.response import TemplateResponse from django.utils import timezone from django.views import View +from django.views.decorators.http import require_POST from bookwyrm import models from bookwyrm.activitypub import ActivitypubResponse @@ -118,3 +121,12 @@ class Following(View): "follow_list": paginated.get_page(request.GET.get("page")), } return TemplateResponse(request, "user/relationships/following.html", data) + + +@require_POST +@login_required +def hide_suggestions(request): + """not everyone wants user suggestions""" + request.user.show_suggested_users = False + request.user.save(broadcast=False, update_fields=["show_suggested_users"]) + return redirect(request.headers.get("Referer", "/"))