From 8ba875af4a4b936e9b2d513489918df6ef3aa28d Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Tue, 26 Oct 2021 14:37:43 -0700 Subject: [PATCH 001/169] Improve federation compability with Hubzilla and Zap Co-authored-by: hubzilla Fixes #1564 --- bookwyrm/connectors/abstract_connector.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bookwyrm/connectors/abstract_connector.py b/bookwyrm/connectors/abstract_connector.py index c032986d..79d79be4 100644 --- a/bookwyrm/connectors/abstract_connector.py +++ b/bookwyrm/connectors/abstract_connector.py @@ -227,8 +227,12 @@ def get_data(url, params=None, timeout=10): resp = requests.get( url, params=params, - headers={ - "Accept": "application/json; charset=utf-8", + headers={ # pylint: disable=line-too-long + "Accept": ( + "application/activity+json," + ' application/ld+json; profile="https://www.w3.org/ns/activitystreams",' + " application/json; charset=utf-8" + ), "User-Agent": settings.USER_AGENT, }, timeout=timeout, From a0093a8a2e63c42fa89e09c0d1061b8e4f41dda5 Mon Sep 17 00:00:00 2001 From: Joachim Date: Mon, 22 Nov 2021 00:25:47 +0100 Subject: [PATCH 002/169] Add status type filters --- bookwyrm/forms.py | 23 ++++++++++++ bookwyrm/models/user.py | 9 ++++- bookwyrm/templates/feed/feed.html | 21 +++++++++++ .../widgets/checkbox_select_horizontal.html | 11 ++++++ .../checkbox_select_horizontal_option.html | 4 +++ bookwyrm/views/feed.py | 35 +++++++++++++++++-- 6 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 bookwyrm/templates/widgets/checkbox_select_horizontal.html create mode 100644 bookwyrm/templates/widgets/checkbox_select_horizontal_option.html diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index 847ca05c..fc8f018d 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -174,6 +174,29 @@ class UserGroupForm(CustomForm): fields = ["groups"] +class CheckboxSelectMultipleHorizontal(widgets.CheckboxSelectMultiple): + template_name = "widgets/checkbox_select_horizontal.html" + option_template_name = "widgets/checkbox_select_horizontal_option.html" + + +class FeedStatusTypes(CustomForm): + class Meta: + model = models.User + fields = ["feed_status_types"] + help_texts = {f: None for f in fields} + labels = {"feed_status_types": ""} + widgets = { + "feed_status_types": CheckboxSelectMultipleHorizontal( + choices=[ + ("review", _("Reviews")), + ("comment", _("Comments")), + ("quotation", _("Quotations")), + ("everything", _("Everything else")), + ], + ), + } + + class CoverForm(CustomForm): class Meta: model = models.Book diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index d7945843..7ca92e4f 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -4,7 +4,7 @@ from urllib.parse import urlparse from django.apps import apps from django.contrib.auth.models import AbstractUser, Group -from django.contrib.postgres.fields import CICharField +from django.contrib.postgres.fields import ArrayField, CICharField from django.core.validators import MinValueValidator from django.dispatch import receiver from django.db import models, transaction @@ -128,6 +128,13 @@ class User(OrderedCollectionPageMixin, AbstractUser): show_suggested_users = models.BooleanField(default=True) discoverable = fields.BooleanField(default=False) + # feed options + feed_status_types = ArrayField( + models.CharField(max_length=10, blank=False), + size=8, + default=list(["review", "comment", "quotation", "everything"]), + ) + preferred_timezone = models.CharField( choices=[(str(tz), str(tz)) for tz in pytz.all_timezones], default=str(pytz.utc), diff --git a/bookwyrm/templates/feed/feed.html b/bookwyrm/templates/feed/feed.html index a6175199..9783e212 100644 --- a/bookwyrm/templates/feed/feed.html +++ b/bookwyrm/templates/feed/feed.html @@ -16,6 +16,27 @@ + +
+ + What to display? + {% if settings_saved %} + Saved! + {% endif %} + +
+ {% csrf_token %} +
+ {{ feed_status_types_form }} +
+
+ +
+
+
+ {# announcements and system messages #} {% if not activities.number > 1 %}
{% if request.user.show_goal and not goal and tab.key == 'home' %} diff --git a/bookwyrm/views/feed.py b/bookwyrm/views/feed.py index bd39b083..7cf56d48 100644 --- a/bookwyrm/views/feed.py +++ b/bookwyrm/views/feed.py @@ -59,6 +59,7 @@ class Feed(View): "streams": STREAMS, "goal_form": forms.GoalForm(), "feed_status_types_options": FeedFilterChoices, + "allowed_status_types": request.user.feed_status_types, "settings_saved": settings_saved, "path": f"/{tab['key']}", }, diff --git a/bookwyrm/views/updates.py b/bookwyrm/views/updates.py index 72614562..2bbc5477 100644 --- a/bookwyrm/views/updates.py +++ b/bookwyrm/views/updates.py @@ -22,4 +22,9 @@ def get_unread_status_count(request, stream="home"): stream = activitystreams.streams.get(stream) if not stream: return JsonResponse({}) - return JsonResponse({"count": stream.get_unread_count(request.user)}) + return JsonResponse( + { + "count": stream.get_unread_count(request.user), + "count_by_type": stream.get_unread_count_by_status_type(request.user), + } + ) From 8712b2fdab12dc4ab059575432d6fef62011485e Mon Sep 17 00:00:00 2001 From: Joachim Date: Wed, 24 Nov 2021 19:02:07 +0100 Subject: [PATCH 011/169] ESLint --- bookwyrm/static/js/bookwyrm.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bookwyrm/static/js/bookwyrm.js b/bookwyrm/static/js/bookwyrm.js index b4557800..a5f7d7e9 100644 --- a/bookwyrm/static/js/bookwyrm.js +++ b/bookwyrm/static/js/bookwyrm.js @@ -127,6 +127,7 @@ let BookWyrm = new class { // This concerns 'review', 'quotation', 'comment' count = allowedStatusTypes.reduce(function(prev, currentKey) { const currentValue = count_by_type[currentKey] | 0; + return prev + currentValue; }, 0); @@ -143,6 +144,7 @@ let BookWyrm = new class { function(prev, currentKey) { const currentValue = count_by_everything_else[currentKey] | 0 + return prev + currentValue; }, count From 0001d6e92a2c4107188c5b7cdf618df35fcfc0ae Mon Sep 17 00:00:00 2001 From: Joachim Date: Wed, 24 Nov 2021 19:04:14 +0100 Subject: [PATCH 012/169] PyLint --- bookwyrm/models/user.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bookwyrm/models/user.py b/bookwyrm/models/user.py index f4183812..4d98f5c5 100644 --- a/bookwyrm/models/user.py +++ b/bookwyrm/models/user.py @@ -37,6 +37,7 @@ FeedFilterChoices = [ def get_feed_filter_choices(): + """return a list of filter choice keys""" return [f[0] for f in FeedFilterChoices] From 5f81be74cb3beb0a8392d7f96e55b86d3ae7726f Mon Sep 17 00:00:00 2001 From: Joachim Date: Wed, 24 Nov 2021 20:52:30 +0100 Subject: [PATCH 013/169] Add test --- bookwyrm/tests/views/test_updates.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bookwyrm/tests/views/test_updates.py b/bookwyrm/tests/views/test_updates.py index 27181fc9..d510fba6 100644 --- a/bookwyrm/tests/views/test_updates.py +++ b/bookwyrm/tests/views/test_updates.py @@ -50,10 +50,13 @@ class UpdateViews(TestCase): request = self.factory.get("") request.user = self.local_user - with patch("bookwyrm.activitystreams.ActivityStream.get_unread_count") as mock: - mock.return_value = 3 - result = views.get_unread_status_count(request, "home") + with patch("bookwyrm.activitystreams.ActivityStream.get_unread_count") as mock_count: + with patch("bookwyrm.activitystreams.ActivityStream.get_unread_count_by_status_type") as mock_count_by_status: + mock_count.return_value = 3 + mock_count_by_status.return_value = {"review": 5} + result = views.get_unread_status_count(request, "home") self.assertIsInstance(result, JsonResponse) data = json.loads(result.getvalue()) self.assertEqual(data["count"], 3) + self.assertEqual(data["count_by_type"]["review"], 5) From 7d24568dcda7cbec7af3647ab33b46e7b9fab457 Mon Sep 17 00:00:00 2001 From: Joachim Date: Wed, 24 Nov 2021 20:54:53 +0100 Subject: [PATCH 014/169] Update test_updates.py --- bookwyrm/tests/views/test_updates.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bookwyrm/tests/views/test_updates.py b/bookwyrm/tests/views/test_updates.py index d510fba6..e7b466cc 100644 --- a/bookwyrm/tests/views/test_updates.py +++ b/bookwyrm/tests/views/test_updates.py @@ -50,8 +50,12 @@ class UpdateViews(TestCase): request = self.factory.get("") request.user = self.local_user - with patch("bookwyrm.activitystreams.ActivityStream.get_unread_count") as mock_count: - with patch("bookwyrm.activitystreams.ActivityStream.get_unread_count_by_status_type") as mock_count_by_status: + with patch( + "bookwyrm.activitystreams.ActivityStream.get_unread_count" + ) as mock_count: + with patch( + "bookwyrm.activitystreams.ActivityStream.get_unread_count_by_status_type" + ) as mock_count_by_status: mock_count.return_value = 3 mock_count_by_status.return_value = {"review": 5} result = views.get_unread_status_count(request, "home") From 9d52e3cf273e1fa97051b23fbc4508b2fb574005 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sat, 27 Nov 2021 18:32:50 +1100 Subject: [PATCH 015/169] add ostatus subscribe to webfinger links --- bookwyrm/views/wellknown.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bookwyrm/views/wellknown.py b/bookwyrm/views/wellknown.py index 04aa88bf..c9b1c129 100644 --- a/bookwyrm/views/wellknown.py +++ b/bookwyrm/views/wellknown.py @@ -30,6 +30,10 @@ def webfinger(request): "rel": "self", "type": "application/activity+json", "href": user.remote_id, + }, + { + "rel": "http://ostatus.org/schema/1.0/subscribe", + "template": f"https://{DOMAIN}/ostatus_subscribe?acct={{uri}}" } ], } From f7c8f121b9c95f0c4ef7e68a358736f1dd209067 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sun, 28 Nov 2021 12:43:29 +1100 Subject: [PATCH 016/169] add remote follow ostatus templates --- bookwyrm/templates/ostatus/ostatus_error.html | 57 ++++++++++ .../templates/ostatus/ostatus_subscribe.html | 48 ++++++++ bookwyrm/templates/ostatus/template.html | 106 ++++++++++++++++++ 3 files changed, 211 insertions(+) create mode 100644 bookwyrm/templates/ostatus/ostatus_error.html create mode 100644 bookwyrm/templates/ostatus/ostatus_subscribe.html create mode 100644 bookwyrm/templates/ostatus/template.html diff --git a/bookwyrm/templates/ostatus/ostatus_error.html b/bookwyrm/templates/ostatus/ostatus_error.html new file mode 100644 index 00000000..5fbc8e94 --- /dev/null +++ b/bookwyrm/templates/ostatus/ostatus_error.html @@ -0,0 +1,57 @@ +{% extends 'ostatus/template.html' %} +{% load i18n %} +{% load utilities %} +{% load markdown %} + +{% block title %} +{% if not request.user.is_authenticated %} +{% trans "Log in to " %} +{% else %} +{% trans "Error following from " %} +{% endif %} +{% endblock %} + +{% block heading %} +{% if not request.user.is_authenticated %} +Let's log in first... +{% else %} +Uh oh... +{% endif %} +{% endblock %} + +{% block content %} +
+ {% if not request.user.is_authenticated %} + + {% elif error == 'ostatus_subscribe' %} +
+

{% blocktrans %}Something went wrong trying to follow {{ account }}{% endblocktrans %}

+

{% trans 'Check you have the correct username before trying again.' %}

+
+ {% endif %} +
+{% endblock %} diff --git a/bookwyrm/templates/ostatus/ostatus_subscribe.html b/bookwyrm/templates/ostatus/ostatus_subscribe.html new file mode 100644 index 00000000..7e929202 --- /dev/null +++ b/bookwyrm/templates/ostatus/ostatus_subscribe.html @@ -0,0 +1,48 @@ +{% extends 'ostatus/template.html' %} +{% load i18n %} +{% load utilities %} +{% load markdown %} + +{% if error or not request.user.is_authenticated %} + {% include 'ostatus/ostatus_error.html' %} +{% else %} + +{% block title %}{% trans "Follow from " %}{% endblock %} + +{% block heading %}Follow from {{ site.name }}{% endblock %} + +{% block content %} +
+
+ +
+ {% if user.summary %} + {{ user.summary|to_markdown|safe|truncatechars_html:120 }} + {% else %} {% endif %} +
+
+
+{% endblock %} + +{% endif %} diff --git a/bookwyrm/templates/ostatus/template.html b/bookwyrm/templates/ostatus/template.html new file mode 100644 index 00000000..2e8ee7b3 --- /dev/null +++ b/bookwyrm/templates/ostatus/template.html @@ -0,0 +1,106 @@ +{% load layout %} +{% load i18n %} +{% load static %} +{% load utilities %} +{% load markdown %} + + + + + {% block title %}{% endblock %}{{ site.name }} + + + + + + + + + + {% if preview_images_enabled is True %} + + {% else %} + + {% endif %} + + + + + + {% block opengraph_images %} + {% include 'snippets/opengraph_images.html' %} + {% endblock %} + + + + + + + +
+
+ {% block content%}{% endblock %} +
+
+ + + + + + + + + + + +{% block scripts %}{% endblock %} + + From d05e100421eaf53946e6cd420b2d32f45b35ab2f Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sun, 28 Nov 2021 13:28:58 +1100 Subject: [PATCH 017/169] update ostatus templates --- bookwyrm/templates/ostatus/ostatus_error.html | 19 ------------- .../templates/ostatus/ostatus_subscribe.html | 28 ++++++++++++++----- 2 files changed, 21 insertions(+), 26 deletions(-) diff --git a/bookwyrm/templates/ostatus/ostatus_error.html b/bookwyrm/templates/ostatus/ostatus_error.html index 5fbc8e94..de2ba988 100644 --- a/bookwyrm/templates/ostatus/ostatus_error.html +++ b/bookwyrm/templates/ostatus/ostatus_error.html @@ -1,23 +1,4 @@ -{% extends 'ostatus/template.html' %} {% load i18n %} -{% load utilities %} -{% load markdown %} - -{% block title %} -{% if not request.user.is_authenticated %} -{% trans "Log in to " %} -{% else %} -{% trans "Error following from " %} -{% endif %} -{% endblock %} - -{% block heading %} -{% if not request.user.is_authenticated %} -Let's log in first... -{% else %} -Uh oh... -{% endif %} -{% endblock %} {% block content %}
diff --git a/bookwyrm/templates/ostatus/ostatus_subscribe.html b/bookwyrm/templates/ostatus/ostatus_subscribe.html index 7e929202..9d87d8ef 100644 --- a/bookwyrm/templates/ostatus/ostatus_subscribe.html +++ b/bookwyrm/templates/ostatus/ostatus_subscribe.html @@ -3,15 +3,30 @@ {% load utilities %} {% load markdown %} -{% if error or not request.user.is_authenticated %} - {% include 'ostatus/ostatus_error.html' %} +{% block title %} +{% if not request.user.is_authenticated %} +{% trans "Log in to " %} +{% elif error %} +{% trans "Error following from " %} {% else %} +{% trans "Follow from " %} +{% endif %} +{% endblock %} -{% block title %}{% trans "Follow from " %}{% endblock %} - -{% block heading %}Follow from {{ site.name }}{% endblock %} +{% block heading %} +{% if not request.user.is_authenticated %} +{% trans "Let's log in first..." %} +{% elif error %} +{% trans 'Uh oh...' %} +{% else %} +{% blocktrans %}Follow from {{ site.name }}{% endblocktrans %} +{% endif %} +{% endblock %} {% block content %} +{% if error or not request.user.is_authenticated %} + {% include 'ostatus/ostatus_error.html' with error=error user=user account=account %} +{% else %}
@@ -43,6 +58,5 @@
-{% endblock %} - {% endif %} +{% endblock %} From 610114b4ebfcd27cde9f76244d559c226e4d78b5 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sun, 28 Nov 2021 16:54:25 +1100 Subject: [PATCH 018/169] rearrange ostatus templates --- .../{ostatus_error.html => error.html} | 14 +++++++- ...{ostatus_subscribe.html => subscribe.html} | 7 ++-- bookwyrm/templates/ostatus/success.html | 32 +++++++++++++++++++ 3 files changed, 49 insertions(+), 4 deletions(-) rename bookwyrm/templates/ostatus/{ostatus_error.html => error.html} (71%) rename bookwyrm/templates/ostatus/{ostatus_subscribe.html => subscribe.html} (86%) create mode 100644 bookwyrm/templates/ostatus/success.html diff --git a/bookwyrm/templates/ostatus/ostatus_error.html b/bookwyrm/templates/ostatus/error.html similarity index 71% rename from bookwyrm/templates/ostatus/ostatus_error.html rename to bookwyrm/templates/ostatus/error.html index de2ba988..b6e858e2 100644 --- a/bookwyrm/templates/ostatus/ostatus_error.html +++ b/bookwyrm/templates/ostatus/error.html @@ -29,10 +29,22 @@
{% elif error == 'ostatus_subscribe' %} -
+

{% blocktrans %}Something went wrong trying to follow {{ account }}{% endblocktrans %}

{% trans 'Check you have the correct username before trying again.' %}

+ {% elif error == 'is_blocked' %} +
+

{% blocktrans %}You have blocked {{ account }}{% endblocktrans %}

+
+ {% elif error == 'already_following' %} +
+

{% blocktrans %}You are already following {{ account }}{% endblocktrans %}

+
+ {% elif error == 'already_requested' %} +
+

{% blocktrans %}You have already requested to follow {{ account }}{% endblocktrans %}

+
{% endif %}
{% endblock %} diff --git a/bookwyrm/templates/ostatus/ostatus_subscribe.html b/bookwyrm/templates/ostatus/subscribe.html similarity index 86% rename from bookwyrm/templates/ostatus/ostatus_subscribe.html rename to bookwyrm/templates/ostatus/subscribe.html index 9d87d8ef..e64be602 100644 --- a/bookwyrm/templates/ostatus/ostatus_subscribe.html +++ b/bookwyrm/templates/ostatus/subscribe.html @@ -25,7 +25,7 @@ {% block content %} {% if error or not request.user.is_authenticated %} - {% include 'ostatus/ostatus_error.html' with error=error user=user account=account %} + {% include 'ostatus/error.html' with error=error user=user account=account %} {% else %}
@@ -45,13 +45,14 @@ @{{ user|username }} -
+ {% csrf_token %} +
-
+
{% if user.summary %} {{ user.summary|to_markdown|safe|truncatechars_html:120 }} {% else %} {% endif %} diff --git a/bookwyrm/templates/ostatus/success.html b/bookwyrm/templates/ostatus/success.html new file mode 100644 index 00000000..10b4409f --- /dev/null +++ b/bookwyrm/templates/ostatus/success.html @@ -0,0 +1,32 @@ +{% extends 'ostatus/template.html' %} +{% load i18n %} +{% load utilities %} + +{% block content %} + +{% endblock %} From e275b98183cdaed4e33d3e11e51307aa63187def Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sun, 28 Nov 2021 16:56:21 +1100 Subject: [PATCH 019/169] ostatus remote follow views --- bookwyrm/urls.py | 3 ++ bookwyrm/views/__init__.py | 2 +- bookwyrm/views/follow.py | 82 +++++++++++++++++++++++++++++++++++++- 3 files changed, 85 insertions(+), 2 deletions(-) diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 514bb7e6..79e6e2a9 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -44,6 +44,7 @@ urlpatterns = [ re_path(r"^api/v1/instance/?$", views.instance_info), re_path(r"^api/v1/instance/peers/?$", views.peers), re_path(r"^opensearch.xml$", views.opensearch, name="opensearch"), + re_path(r"^ostatus_subscribe/?$", views.ostatus_follow_request), # polling updates re_path("^api/updates/notifications/?$", views.get_notification_count), re_path("^api/updates/stream/(?P[a-z]+)/?$", views.get_unread_status_count), @@ -450,4 +451,6 @@ urlpatterns = [ re_path(r"^unfollow/?$", views.unfollow, name="unfollow"), re_path(r"^accept-follow-request/?$", views.accept_follow_request), re_path(r"^delete-follow-request/?$", views.delete_follow_request), + # re_path(r"^ostatus_follow/?$", views.remote_follow), + re_path(r"^ostatus_success/?$", views.ostatus_follow_success, name="ostatus-success"), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index d79de424..034b1830 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -58,7 +58,7 @@ from .author import Author, EditAuthor from .directory import Directory from .discover import Discover from .feed import DirectMessage, Feed, Replies, Status -from .follow import follow, unfollow +from .follow import follow, unfollow, ostatus_follow_request, ostatus_follow_success from .follow import accept_follow_request, delete_follow_request from .get_started import GetStartedBooks, GetStartedProfile, GetStartedUsers from .goal import Goal, hide_goal diff --git a/bookwyrm/views/follow.py b/bookwyrm/views/follow.py index 7d91ce5b..471fe307 100644 --- a/bookwyrm/views/follow.py +++ b/bookwyrm/views/follow.py @@ -1,11 +1,14 @@ """ views for actions you can take in the application """ +import urllib.parse +import re from django.contrib.auth.decorators import login_required from django.db import IntegrityError from django.shortcuts import get_object_or_404, redirect +from django.template.response import TemplateResponse from django.views.decorators.http import require_POST from bookwyrm import models -from .helpers import get_user_from_username +from .helpers import get_user_from_username, handle_remote_webfinger @login_required @@ -23,9 +26,13 @@ def follow(request): except IntegrityError: pass + if request.GET.get("next"): + return redirect(request.GET.get("next", "/")) + return redirect(to_follow.local_path) + @login_required @require_POST def unfollow(request): @@ -84,3 +91,76 @@ def delete_follow_request(request): follow_request.delete() return redirect(f"/user/{request.user.localname}") + +def ostatus_follow_request(request): + """prepare an outgoing remote follow request""" + + # parse the acct URI into a user string + uri = urllib.parse.unquote(request.GET.get("acct")) + username_parts = re.search("(?:^http(?:s?):\/\/)([\w\-\.]*)(?:.)*(?:(?:\/)([\w]*))", uri) + account = f"{username_parts[2]}@{username_parts[1]}" + user = handle_remote_webfinger(account) + error = None + + if user is None or user == "": + error = "ostatus_subscribe" + + if bool(user) and user in request.user.blocks.all(): + error = "is_blocked" + + if hasattr(user, "followers") and request.user in user.followers.all(): + error = "already_following" + + if hasattr(user, "follower_requests") and request.user in user.follower_requests.all(): + error = "already_requested" + + data = { + "account": account, + "user": user, + "error": error + } + + return TemplateResponse(request, "ostatus/subscribe.html", data) + + +@login_required +def ostatus_follow_success(request): + """display success message for remote follow""" + user = get_user_from_username(request.user, request.GET.get("following")) + data = { + "account": user.name, + "user": user, + "error": None + } + return TemplateResponse(request, "ostatus/success.html", data) + +@login_required +@require_POST +def remote_follow(request): + """complete an incoming remote follow request""" + + # this is triggered from remote follow form + # attempt the follow request + # on success [[return success page]] + # on fail return [[ostatus_error]] + + +""" +REQUEST TO FOLLOW FROM REMOTE ACCOUNT +1. click remote follow button [default checked option to open new window] +2. popup new small window +3. enter user acct to follow from (user@domain.tld) and submit form +5. GET {base_url}/.well-known/webfinger/?resource=acct:{user@domain.tld} +6. parse json for links +6.1 rel="http://ostatus.org/schema/1.0/subscribe" and return 'template' +6.2 rel="self" and return href +7. replace '{uri}' in the returned string with self.href +8. GET the URI at 6.1 + +REQUEST TO FOLLOW FROM LOCAL ACCOUNT +1. receive request to /ostatus_subscribe?acct={uri} +2. check user is logged in and present confirmation screen (remote_follow_request) +3. On confirmation, 3. parse user into info needed for a normal follow +4. send follow request, on 200 response display success else display error (remote_follow) +5. Include button inviting to close window +""" From 2e428e6ea1687c15c87856f682a572cdff098e9c Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sun, 28 Nov 2021 20:08:54 +1100 Subject: [PATCH 020/169] add remote follow templates --- bookwyrm/templates/ostatus/remote_follow.html | 43 +++++++++++++++++++ .../ostatus/remote_follow_button.html | 16 +++++++ 2 files changed, 59 insertions(+) create mode 100644 bookwyrm/templates/ostatus/remote_follow.html create mode 100644 bookwyrm/templates/ostatus/remote_follow_button.html diff --git a/bookwyrm/templates/ostatus/remote_follow.html b/bookwyrm/templates/ostatus/remote_follow.html new file mode 100644 index 00000000..ea8881e4 --- /dev/null +++ b/bookwyrm/templates/ostatus/remote_follow.html @@ -0,0 +1,43 @@ +{% extends 'ostatus/template.html' %} +{% load i18n %} +{% load utilities %} + +{% block content %} +
+
+

{% blocktrans %}Follow {{ user.display_name }} on the fediverse{% endblocktrans %}

+
+ +
+
+
+
+ {% csrf_token %} + + + +
+
+
+
+{% endblock %} diff --git a/bookwyrm/templates/ostatus/remote_follow_button.html b/bookwyrm/templates/ostatus/remote_follow_button.html new file mode 100644 index 00000000..4789d306 --- /dev/null +++ b/bookwyrm/templates/ostatus/remote_follow_button.html @@ -0,0 +1,16 @@ +{% load i18n %} +{% if request.user == user %} +{% else %} + +
+
+
+ {% csrf_token %} + + +
+
+
+{% endif %} From 6e7d23c1aec60317e7989aaf5cafa08112d49cc0 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sun, 28 Nov 2021 20:09:29 +1100 Subject: [PATCH 021/169] add remote follow button --- bookwyrm/templates/user/layout.html | 3 +++ bookwyrm/urls.py | 3 ++- bookwyrm/views/__init__.py | 2 +- bookwyrm/views/follow.py | 34 +++++++++++++++-------------- bookwyrm/views/helpers.py | 27 +++++++++++++++++++++++ 5 files changed, 51 insertions(+), 18 deletions(-) diff --git a/bookwyrm/templates/user/layout.html b/bookwyrm/templates/user/layout.html index d7557ae7..03e3dfce 100755 --- a/bookwyrm/templates/user/layout.html +++ b/bookwyrm/templates/user/layout.html @@ -39,6 +39,9 @@ {% if not is_self and request.user.is_authenticated %} {% include 'snippets/follow_button.html' with user=user %} {% endif %} + {% if not is_self %} + {% include 'ostatus/remote_follow_button.html' with user=user %} + {% endif %} {% if is_self and user.follower_requests.all %}
diff --git a/bookwyrm/templates/ostatus/template.html b/bookwyrm/templates/ostatus/template.html index 2e8ee7b3..cb922f9b 100644 --- a/bookwyrm/templates/ostatus/template.html +++ b/bookwyrm/templates/ostatus/template.html @@ -92,7 +92,6 @@
- diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 48fe0f6c..45837ec1 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -453,5 +453,7 @@ urlpatterns = [ re_path(r"^delete-follow-request/?$", views.delete_follow_request), re_path(r"^ostatus_follow/?$", views.remote_follow, name="remote-follow"), re_path(r"^remote_follow/?$", views.remote_follow_page, name="remote-follow-page"), - re_path(r"^ostatus_success/?$", views.ostatus_follow_success, name="ostatus-success"), + re_path( + r"^ostatus_success/?$", views.ostatus_follow_success, name="ostatus-success" + ), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index 3b5bf823..4a92578c 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -58,7 +58,14 @@ from .author import Author, EditAuthor from .directory import Directory from .discover import Discover from .feed import DirectMessage, Feed, Replies, Status -from .follow import follow, unfollow, ostatus_follow_request, ostatus_follow_success, remote_follow, remote_follow_page +from .follow import ( + follow, + unfollow, + ostatus_follow_request, + ostatus_follow_success, + remote_follow, + remote_follow_page, +) from .follow import accept_follow_request, delete_follow_request from .get_started import GetStartedBooks, GetStartedProfile, GetStartedUsers from .goal import Goal, hide_goal diff --git a/bookwyrm/views/follow.py b/bookwyrm/views/follow.py index 2ebe0ce0..58d97985 100644 --- a/bookwyrm/views/follow.py +++ b/bookwyrm/views/follow.py @@ -8,7 +8,11 @@ from django.template.response import TemplateResponse from django.views.decorators.http import require_POST from bookwyrm import models -from .helpers import get_user_from_username, handle_remote_webfinger, subscribe_remote_webfinger +from .helpers import ( + get_user_from_username, + handle_remote_webfinger, + subscribe_remote_webfinger, +) @login_required @@ -32,7 +36,6 @@ def follow(request): return redirect(to_follow.local_path) - @login_required @require_POST def unfollow(request): @@ -92,12 +95,15 @@ def delete_follow_request(request): follow_request.delete() return redirect(f"/user/{request.user.localname}") + def ostatus_follow_request(request): """prepare an outgoing remote follow request""" # parse the acct URI into a user string uri = urllib.parse.unquote(request.GET.get("acct")) - username_parts = re.search("(?:^http(?:s?):\/\/)([\w\-\.]*)(?:.)*(?:(?:\/)([\w]*))", uri) + username_parts = re.search( + "(?:^http(?:s?):\/\/)([\w\-\.]*)(?:.)*(?:(?:\/)([\w]*))", uri + ) account = f"{username_parts[2]}@{username_parts[1]}" user = handle_remote_webfinger(account) error = None @@ -111,14 +117,13 @@ def ostatus_follow_request(request): if hasattr(user, "followers") and request.user in user.followers.all(): error = "already_following" - if hasattr(user, "follower_requests") and request.user in user.follower_requests.all(): + if ( + hasattr(user, "follower_requests") + and request.user in user.follower_requests.all() + ): error = "already_requested" - data = { - "account": account, - "user": user, - "error": error - } + data = {"account": account, "user": user, "error": error} return TemplateResponse(request, "ostatus/subscribe.html", data) @@ -127,21 +132,17 @@ def ostatus_follow_request(request): def ostatus_follow_success(request): """display success message for remote follow""" user = get_user_from_username(request.user, request.GET.get("following")) - data = { - "account": user.name, - "user": user, - "error": None - } + data = {"account": user.name, "user": user, "error": None} return TemplateResponse(request, "ostatus/success.html", data) + def remote_follow_page(request): """Display remote follow page""" user = get_user_from_username(request.user, request.GET.get("user")) - data = { - "user": user - } + data = {"user": user} return TemplateResponse(request, "ostatus/remote_follow.html", data) + @require_POST def remote_follow(request): """direct user to follow from remote account using ostatus subscribe protocol""" diff --git a/bookwyrm/views/helpers.py b/bookwyrm/views/helpers.py index 60718148..650087ec 100644 --- a/bookwyrm/views/helpers.py +++ b/bookwyrm/views/helpers.py @@ -84,6 +84,7 @@ def handle_remote_webfinger(query): return None return user + def subscribe_remote_webfinger(query): """get subscribe template from other servers""" template = None @@ -112,6 +113,7 @@ def subscribe_remote_webfinger(query): return template + def get_edition(book_id): """look up a book in the db and return an edition""" book = models.Book.objects.select_subclasses().get(id=book_id) diff --git a/bookwyrm/views/wellknown.py b/bookwyrm/views/wellknown.py index c9b1c129..03e619df 100644 --- a/bookwyrm/views/wellknown.py +++ b/bookwyrm/views/wellknown.py @@ -32,9 +32,9 @@ def webfinger(request): "href": user.remote_id, }, { - "rel": "http://ostatus.org/schema/1.0/subscribe", - "template": f"https://{DOMAIN}/ostatus_subscribe?acct={{uri}}" - } + "rel": "http://ostatus.org/schema/1.0/subscribe", + "template": f"https://{DOMAIN}/ostatus_subscribe?acct={{uri}}", + }, ], } ) From 6abf5d69107c4440e1809e34458e169e823d7e92 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Sun, 28 Nov 2021 21:48:03 +1100 Subject: [PATCH 024/169] add submit button to remote follow form --- bookwyrm/templates/ostatus/remote_follow.html | 1 + 1 file changed, 1 insertion(+) diff --git a/bookwyrm/templates/ostatus/remote_follow.html b/bookwyrm/templates/ostatus/remote_follow.html index ea8881e4..3ff76943 100644 --- a/bookwyrm/templates/ostatus/remote_follow.html +++ b/bookwyrm/templates/ostatus/remote_follow.html @@ -36,6 +36,7 @@ +
From feaf0d5e52ec8d2887b2d14e3bcd3bfc49446cf4 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 29 Nov 2021 07:11:57 +1100 Subject: [PATCH 025/169] handle username errors in remote follow form --- bookwyrm/templates/ostatus/error.html | 5 +++++ bookwyrm/views/follow.py | 3 +++ 2 files changed, 8 insertions(+) diff --git a/bookwyrm/templates/ostatus/error.html b/bookwyrm/templates/ostatus/error.html index b6e858e2..cb1aec40 100644 --- a/bookwyrm/templates/ostatus/error.html +++ b/bookwyrm/templates/ostatus/error.html @@ -33,6 +33,11 @@

{% blocktrans %}Something went wrong trying to follow {{ account }}{% endblocktrans %}

{% trans 'Check you have the correct username before trying again.' %}

+ {% elif error == 'remote_subscribe' %} +
+

{% blocktrans %}Something went wrong trying to follow from {{ account }}{% endblocktrans %}

+

{% trans 'Check you have the correct username before trying again.' %}

+
{% elif error == 'is_blocked' %}

{% blocktrans %}You have blocked {{ account }}{% endblocktrans %}

diff --git a/bookwyrm/views/follow.py b/bookwyrm/views/follow.py index 58d97985..fcab5d6a 100644 --- a/bookwyrm/views/follow.py +++ b/bookwyrm/views/follow.py @@ -148,5 +148,8 @@ def remote_follow(request): """direct user to follow from remote account using ostatus subscribe protocol""" remote_user = request.POST.get("remote_user") template = subscribe_remote_webfinger(remote_user) + if template is None: + data = {"account": remote_user, "user": None, "error": "remote_subscribe"} + return TemplateResponse(request, "ostatus/subscribe.html", data) url = template.replace("{uri}", request.POST.get("user")) return redirect(url) From 403e282d888da9ad02a1a5e6da88c190d9f48994 Mon Sep 17 00:00:00 2001 From: Joachim Date: Sun, 28 Nov 2021 21:52:28 +0100 Subject: [PATCH 026/169] Add `aria-describedby` to field help/error messages --- bookwyrm/forms.py | 43 +++++++++++++++++++ .../templates/preferences/delete_user.html | 4 +- bookwyrm/templates/preferences/edit_user.html | 22 ++++++---- bookwyrm/templates/settings/site.html | 8 ++-- 4 files changed, 62 insertions(+), 15 deletions(-) diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index 847ca05c..aed5a794 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -9,6 +9,7 @@ from django.utils import timezone from django.utils.translation import gettext_lazy as _ from bookwyrm import models +from bookwyrm.models.fields import ClearableFileInputWithWarning class CustomForm(ModelForm): @@ -147,6 +148,23 @@ class EditUserForm(CustomForm): "preferred_language", ] help_texts = {f: None for f in fields} + widgets = { + "avatar": ClearableFileInputWithWarning( + attrs={'aria-describedby': "desc_avatar"} + ), + "name": forms.TextInput( + attrs={'aria-describedby': "desc_name"} + ), + "summary": forms.Textarea( + attrs={'aria-describedby': "desc_summary"} + ), + "email": forms.EmailInput( + attrs={'aria-describedby': "desc_email"} + ), + "discoverable": forms.CheckboxInput( + attrs={'aria-describedby': "desc_discoverable"} + ), + } class LimitedEditUserForm(CustomForm): @@ -160,6 +178,20 @@ class LimitedEditUserForm(CustomForm): "discoverable", ] help_texts = {f: None for f in fields} + widgets = { + "avatar": ClearableFileInputWithWarning( + attrs={'aria-describedby': "desc_avatar"} + ), + "name": forms.TextInput( + attrs={'aria-describedby': "desc_name"} + ), + "summary": forms.Textarea( + attrs={'aria-describedby': "desc_summary"} + ), + "discoverable": forms.CheckboxInput( + attrs={'aria-describedby': "desc_discoverable"} + ), + } class DeleteUserForm(CustomForm): @@ -288,6 +320,17 @@ class SiteForm(CustomForm): class Meta: model = models.SiteSettings exclude = [] + widgets = { + "instance_short_description": forms.TextInput( + attrs={'aria-describedby': "desc_instance_short_description"} + ), + "require_confirm_email": forms.CheckboxInput( + attrs={'aria-describedby': "desc_require_confirm_email"} + ), + "invite_request_text": forms.Textarea( + attrs={'aria-describedby': "desc_invite_request_text"} + ), + } class AnnouncementForm(CustomForm): diff --git a/bookwyrm/templates/preferences/delete_user.html b/bookwyrm/templates/preferences/delete_user.html index 63bd2f86..a72cc97d 100644 --- a/bookwyrm/templates/preferences/delete_user.html +++ b/bookwyrm/templates/preferences/delete_user.html @@ -18,9 +18,9 @@ {% csrf_token %}
- + {% for error in form.password.errors %} -

{{ error | escape }}

+

{{ error | escape }}

{% endfor %}
diff --git a/bookwyrm/templates/preferences/edit_user.html b/bookwyrm/templates/preferences/edit_user.html index 72c49dbe..a3f8962c 100644 --- a/bookwyrm/templates/preferences/edit_user.html +++ b/bookwyrm/templates/preferences/edit_user.html @@ -34,7 +34,7 @@
{{ form.avatar }} {% for error in form.avatar.errors %} -

{{ error | escape }}

+

{{ error | escape }}

{% endfor %}
@@ -42,21 +42,21 @@ {{ form.name }} {% for error in form.name.errors %} -

{{ error | escape }}

+

{{ error | escape }}

{% endfor %}
{{ form.summary }} {% for error in form.summary.errors %} -

{{ error | escape }}

+

{{ error | escape }}

{% endfor %}
{{ form.email }} {% for error in form.email.errors %} -

{{ error | escape }}

+

{{ error | escape }}

{% endfor %}
@@ -69,19 +69,23 @@
+
+
+
+
{% url 'directory' as path %} -

+

{% blocktrans %}Your account will show up in the directory, and may be recommended to other BookWyrm users.{% endblocktrans %}

@@ -107,8 +111,8 @@
diff --git a/bookwyrm/templates/settings/site.html b/bookwyrm/templates/settings/site.html index 94a4dd45..01b25036 100644 --- a/bookwyrm/templates/settings/site.html +++ b/bookwyrm/templates/settings/site.html @@ -33,8 +33,8 @@ {{ site_form.instance_description }}
- -

{% trans "Used when the instance is previewed on joinbookwyrm.com. Does not support HTML or Markdown." %}

+ +

{% trans "Used when the instance is previewed on joinbookwyrm.com. Does not support HTML or Markdown." %}

{{ site_form.instance_short_description }}
@@ -114,7 +114,7 @@ {{ site_form.require_confirm_email }} {% trans "Require users to confirm email address" %} -

{% trans "(Recommended if registration is open)" %}

+

{% trans "(Recommended if registration is open)" %}

@@ -124,7 +124,7 @@ {{ site_form.invite_request_text }} {% for error in site_form.invite_request_text.errors %} -

{{ error|escape }}

+

{{ error|escape }}

{% endfor %}
From 46f32944315b9add4f04776668bbf7c2117efc12 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 29 Nov 2021 07:56:09 +1100 Subject: [PATCH 027/169] fix remote follow template --- bookwyrm/templates/ostatus/remote_follow.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/templates/ostatus/remote_follow.html b/bookwyrm/templates/ostatus/remote_follow.html index 3ff76943..98442547 100644 --- a/bookwyrm/templates/ostatus/remote_follow.html +++ b/bookwyrm/templates/ostatus/remote_follow.html @@ -24,7 +24,7 @@ @{{ user|username }} -

Follow {{ user.name }} from another Fediverse account like Bookwyrm, Mastodon, or Pleroma.

+

Follow {{ user.display_name }} from another Fediverse account like Bookwyrm, Mastodon, or Pleroma.

From c7242b6022c9e70725e9445255fe766ecedee2ed Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 29 Nov 2021 07:56:31 +1100 Subject: [PATCH 028/169] add popup warning --- bookwyrm/templates/ostatus/remote_follow_button.html | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bookwyrm/templates/ostatus/remote_follow_button.html b/bookwyrm/templates/ostatus/remote_follow_button.html index 2848fde0..fc869229 100644 --- a/bookwyrm/templates/ostatus/remote_follow_button.html +++ b/bookwyrm/templates/ostatus/remote_follow_button.html @@ -4,9 +4,12 @@ {% endif %} From 85c688b1475bf79649f49619d8ab56a3200cd9b7 Mon Sep 17 00:00:00 2001 From: Joachim Date: Sun, 28 Nov 2021 22:01:49 +0100 Subject: [PATCH 029/169] Update forms.py --- bookwyrm/forms.py | 34 ++++++++++++---------------------- 1 file changed, 12 insertions(+), 22 deletions(-) diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index aed5a794..ffbb237b 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -150,19 +150,13 @@ class EditUserForm(CustomForm): help_texts = {f: None for f in fields} widgets = { "avatar": ClearableFileInputWithWarning( - attrs={'aria-describedby': "desc_avatar"} - ), - "name": forms.TextInput( - attrs={'aria-describedby': "desc_name"} - ), - "summary": forms.Textarea( - attrs={'aria-describedby': "desc_summary"} - ), - "email": forms.EmailInput( - attrs={'aria-describedby': "desc_email"} + attrs={"aria-describedby": "desc_avatar"} ), + "name": forms.TextInput(attrs={"aria-describedby": "desc_name"}), + "summary": forms.Textarea(attrs={"aria-describedby": "desc_summary"}), + "email": forms.EmailInput(attrs={"aria-describedby": "desc_email"}), "discoverable": forms.CheckboxInput( - attrs={'aria-describedby': "desc_discoverable"} + attrs={"aria-describedby": "desc_discoverable"} ), } @@ -180,16 +174,12 @@ class LimitedEditUserForm(CustomForm): help_texts = {f: None for f in fields} widgets = { "avatar": ClearableFileInputWithWarning( - attrs={'aria-describedby': "desc_avatar"} - ), - "name": forms.TextInput( - attrs={'aria-describedby': "desc_name"} - ), - "summary": forms.Textarea( - attrs={'aria-describedby': "desc_summary"} + attrs={"aria-describedby": "desc_avatar"} ), + "name": forms.TextInput(attrs={"aria-describedby": "desc_name"}), + "summary": forms.Textarea(attrs={"aria-describedby": "desc_summary"}), "discoverable": forms.CheckboxInput( - attrs={'aria-describedby': "desc_discoverable"} + attrs={"aria-describedby": "desc_discoverable"} ), } @@ -322,13 +312,13 @@ class SiteForm(CustomForm): exclude = [] widgets = { "instance_short_description": forms.TextInput( - attrs={'aria-describedby': "desc_instance_short_description"} + attrs={"aria-describedby": "desc_instance_short_description"} ), "require_confirm_email": forms.CheckboxInput( - attrs={'aria-describedby': "desc_require_confirm_email"} + attrs={"aria-describedby": "desc_require_confirm_email"} ), "invite_request_text": forms.Textarea( - attrs={'aria-describedby': "desc_invite_request_text"} + attrs={"aria-describedby": "desc_invite_request_text"} ), } From 4a9713b812d65d2bc2f9ef4ecbc1eeec8f6a617f Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 29 Nov 2021 08:03:01 +1100 Subject: [PATCH 030/169] fix template for remote follower error --- bookwyrm/templates/ostatus/error.html | 2 +- bookwyrm/templates/ostatus/subscribe.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bookwyrm/templates/ostatus/error.html b/bookwyrm/templates/ostatus/error.html index cb1aec40..442c35b9 100644 --- a/bookwyrm/templates/ostatus/error.html +++ b/bookwyrm/templates/ostatus/error.html @@ -2,7 +2,7 @@ {% block content %}
- {% if not request.user.is_authenticated %} + {% if not request.user.is_authenticated and not error == 'remote_subscribe' %}
diff --git a/bookwyrm/templates/ostatus/success.html b/bookwyrm/templates/ostatus/success.html index 10b4409f..d8c31182 100644 --- a/bookwyrm/templates/ostatus/success.html +++ b/bookwyrm/templates/ostatus/success.html @@ -22,11 +22,14 @@ @{{ user|username }} - - - {% include 'snippets/avatar.html' with user=user large=True %} - +

+ + {% trans 'You are now following ' %}{{ user.display_name }}! +

+ {% endblock %} From 3d73ea92e85b84bfc4f7e2fc5a8fab5179767e00 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 29 Nov 2021 18:08:25 +1100 Subject: [PATCH 033/169] handle user blocks properly --- bookwyrm/templates/ostatus/error.html | 4 +++ bookwyrm/views/follow.py | 36 +++++++++++++++++++-------- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/bookwyrm/templates/ostatus/error.html b/bookwyrm/templates/ostatus/error.html index 91bb6a0a..8a047172 100644 --- a/bookwyrm/templates/ostatus/error.html +++ b/bookwyrm/templates/ostatus/error.html @@ -42,6 +42,10 @@

{% blocktrans %}You have blocked {{ account }}{% endblocktrans %}

+ {% elif error == 'has_blocked' %} +
+

{% blocktrans %}{{ account }} has blocked you{% endblocktrans %}

+
{% elif error == 'already_following' %}

{% blocktrans %}You are already following {{ account }}{% endblocktrans %}

diff --git a/bookwyrm/views/follow.py b/bookwyrm/views/follow.py index 1555fc5e..83b90035 100644 --- a/bookwyrm/views/follow.py +++ b/bookwyrm/views/follow.py @@ -109,17 +109,33 @@ def ostatus_follow_request(request): if user is None or user == "": error = "ostatus_subscribe" - if hasattr(request.user, "blocks") and user in request.user.blocks.all(): - error = "is_blocked" + # don't do these checks for AnonymousUser before they sign in + if request.user.id: - if hasattr(user, "followers") and request.user in user.followers.all(): - error = "already_following" - - if ( - hasattr(user, "follower_requests") - and request.user in user.follower_requests.all() - ): - error = "already_requested" + # you have blocked them so you probably don't want to follow + if ( + hasattr(request.user, "blocks") + and user in request.user.blocks.all() + ): + error = "is_blocked" + # they have blocked you + if ( + hasattr(user, "blocks") + and request.user in user.blocks.all() + ): + error = "has_blocked" + # you're already following them + if ( + hasattr(user, "followers") + and request.user in user.followers.all() + ): + error = "already_following" + # you're not following yet but you already asked + if ( + hasattr(user, "follower_requests") + and request.user in user.follower_requests.all() + ): + error = "already_requested" data = {"account": account, "user": user, "error": error} From f5d9a204ebfd0045a04046200feaeaa3b21d68d8 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 29 Nov 2021 19:37:56 +1100 Subject: [PATCH 034/169] clean up ostatus templates --- bookwyrm/templates/ostatus/error.html | 46 +++--- bookwyrm/templates/ostatus/remote_follow.html | 67 +++++---- bookwyrm/templates/ostatus/success.html | 46 +++--- bookwyrm/templates/ostatus/template.html | 133 +++++++++--------- 4 files changed, 145 insertions(+), 147 deletions(-) diff --git a/bookwyrm/templates/ostatus/error.html b/bookwyrm/templates/ostatus/error.html index 8a047172..085fa345 100644 --- a/bookwyrm/templates/ostatus/error.html +++ b/bookwyrm/templates/ostatus/error.html @@ -4,30 +4,28 @@
{% if not request.user.is_authenticated and not error == 'remote_subscribe' %} +
+
+
+ {% csrf_token %} +
+
+ + +
+
+ + +

{% trans "Forgot your password?" %}

+
+
+ +
+
+
+
+
+
{% elif error == 'ostatus_subscribe' %}

{% blocktrans %}Something went wrong trying to follow {{ account }}{% endblocktrans %}

diff --git a/bookwyrm/templates/ostatus/remote_follow.html b/bookwyrm/templates/ostatus/remote_follow.html index ef8f1b90..6a4e565a 100644 --- a/bookwyrm/templates/ostatus/remote_follow.html +++ b/bookwyrm/templates/ostatus/remote_follow.html @@ -4,41 +4,40 @@ {% block content %}
-
-

{% blocktrans %}Follow {{ user.display_name }} on the fediverse{% endblocktrans %}

-
-
-
- - {% include 'snippets/avatar.html' with user=user large=True %} - -
- - - {{ user.display_name }} - {% if user.manually_approves_followers %} - - {% trans "Locked account" %} - - {% endif %} - - @{{ user|username }} - -

{% blocktrans %}Follow {{ user.display_name }} from another Fediverse account like Bookwyrm, Mastodon, or Pleroma.{% endblocktrans %}

-
-
+
+

{% blocktrans %}Follow {{ user.display_name }} on the fediverse{% endblocktrans %}

+
+
+
+ + {% include 'snippets/avatar.html' with user=user large=True %} + +
+ + + {{ user.display_name }} + {% if user.manually_approves_followers %} + + {% trans "Locked account" %} + + {% endif %} + + @{{ user|username }} + +

{% blocktrans %}Follow {{ user.display_name }} from another Fediverse account like Bookwyrm, Mastodon, or Pleroma.{% endblocktrans %}

+
+
-
-
-
- {% csrf_token %} - - - - -
-
-
+
+
+
+ {% csrf_token %} + + + + +
+
{% endblock %} diff --git a/bookwyrm/templates/ostatus/success.html b/bookwyrm/templates/ostatus/success.html index d8c31182..89f66273 100644 --- a/bookwyrm/templates/ostatus/success.html +++ b/bookwyrm/templates/ostatus/success.html @@ -4,29 +4,29 @@ {% block content %}
-
diff --git a/bookwyrm/templates/ostatus/template.html b/bookwyrm/templates/ostatus/template.html index cb922f9b..1dbb32a3 100644 --- a/bookwyrm/templates/ostatus/template.html +++ b/bookwyrm/templates/ostatus/template.html @@ -7,45 +7,46 @@ - {% block title %}{% endblock %}{{ site.name }} - - - - + {% block title %}{% endblock %}{{ site.name }} + + + + - + - + - {% if preview_images_enabled is True %} - - {% else %} - - {% endif %} - - - - + {% if preview_images_enabled is True %} + + {% else %} + + {% endif %} + + + + - {% block opengraph_images %} - {% include 'snippets/opengraph_images.html' %} - {% endblock %} - - + {% block opengraph_images %} + {% include 'snippets/opengraph_images.html' %} + {% endblock %} + + @@ -57,43 +58,43 @@ From 9a3ec4362b85ce7920632ff6a74ee44f4b99d9ff Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 29 Nov 2021 19:45:52 +1100 Subject: [PATCH 035/169] code cleanup --- bookwyrm/static/js/bookwyrm.js | 13 ++++++------- bookwyrm/views/follow.py | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/bookwyrm/static/js/bookwyrm.js b/bookwyrm/static/js/bookwyrm.js index 86a021af..ebac78a9 100644 --- a/bookwyrm/static/js/bookwyrm.js +++ b/bookwyrm/static/js/bookwyrm.js @@ -376,12 +376,11 @@ let BookWyrm = new class { * @param {string} windowName windowName * @return {undefined} */ - displayPopUp(url, windowName){ - - window.open( - url, - windowName, - "left=100,top=100,width=430,height=600" - ) + displayPopUp(url, windowName) { + window.open( + url, + windowName, + "left=100,top=100,width=430,height=600" + ); } }(); diff --git a/bookwyrm/views/follow.py b/bookwyrm/views/follow.py index 83b90035..11bff60a 100644 --- a/bookwyrm/views/follow.py +++ b/bookwyrm/views/follow.py @@ -100,7 +100,7 @@ def ostatus_follow_request(request): """prepare an outgoing remote follow request""" uri = urllib.parse.unquote(request.GET.get("acct")) username_parts = re.search( - "(?:^http(?:s?):\/\/)([\w\-\.]*)(?:.)*(?:(?:\/)([\w]*))", uri + r"(?:^http(?:s?):\/\/)([\w\-\.]*)(?:.)*(?:(?:\/)([\w]*))", uri ) account = f"{username_parts[2]}@{username_parts[1]}" user = handle_remote_webfinger(account) From 1211fda7ff82a2eca793981cb5fbddda4643af5b Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 29 Nov 2021 19:53:13 +1100 Subject: [PATCH 036/169] beautiful code quality, pylint will be pleased --- bookwyrm/templates/ostatus/template.html | 2 +- bookwyrm/views/follow.py | 19 ++++--------------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/bookwyrm/templates/ostatus/template.html b/bookwyrm/templates/ostatus/template.html index 1dbb32a3..7d670b0a 100644 --- a/bookwyrm/templates/ostatus/template.html +++ b/bookwyrm/templates/ostatus/template.html @@ -33,7 +33,7 @@ diff --git a/bookwyrm/views/follow.py b/bookwyrm/views/follow.py index 11bff60a..7af8b0db 100644 --- a/bookwyrm/views/follow.py +++ b/bookwyrm/views/follow.py @@ -113,22 +113,13 @@ def ostatus_follow_request(request): if request.user.id: # you have blocked them so you probably don't want to follow - if ( - hasattr(request.user, "blocks") - and user in request.user.blocks.all() - ): + if hasattr(request.user, "blocks") and user in request.user.blocks.all(): error = "is_blocked" # they have blocked you - if ( - hasattr(user, "blocks") - and request.user in user.blocks.all() - ): + if hasattr(user, "blocks") and request.user in user.blocks.all(): error = "has_blocked" # you're already following them - if ( - hasattr(user, "followers") - and request.user in user.followers.all() - ): + if hasattr(user, "followers") and request.user in user.followers.all(): error = "already_following" # you're not following yet but you already asked if ( @@ -165,8 +156,6 @@ def remote_follow(request): if template is None: data = {"account": remote_user, "user": None, "error": "remote_subscribe"} return TemplateResponse(request, "ostatus/subscribe.html", data) - user = get_object_or_404( - models.User, id=request.POST.get("user") - ) + user = get_object_or_404(models.User, id=request.POST.get("user")) url = template.replace("{uri}", urllib.parse.quote(user.remote_id)) return redirect(url) From 1d90ca6fa62362e840ca2ba9fd0306b0ea8a2752 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 29 Nov 2021 20:35:26 +1100 Subject: [PATCH 037/169] keep footer DRY Pulls footer and scripts after it into a separate component template. This allows ostatus/template to use the footer without having to use layout without repeating the same code. --- bookwyrm/templates/components/footer.html | 49 +++++++++++++++++++++++ bookwyrm/templates/layout.html | 45 +-------------------- bookwyrm/templates/ostatus/template.html | 48 +--------------------- 3 files changed, 51 insertions(+), 91 deletions(-) create mode 100644 bookwyrm/templates/components/footer.html diff --git a/bookwyrm/templates/components/footer.html b/bookwyrm/templates/components/footer.html new file mode 100644 index 00000000..047d7bfa --- /dev/null +++ b/bookwyrm/templates/components/footer.html @@ -0,0 +1,49 @@ +{% load layout %} +{% load i18n %} +{% load static %} + + + + + + + + + +{% block scripts %}{% endblock %} diff --git a/bookwyrm/templates/layout.html b/bookwyrm/templates/layout.html index f2d04f96..50a7ae6d 100644 --- a/bookwyrm/templates/layout.html +++ b/bookwyrm/templates/layout.html @@ -222,50 +222,7 @@
- +{% include 'components/footer.html' %} - - - - - - -{% block scripts %}{% endblock %} diff --git a/bookwyrm/templates/ostatus/template.html b/bookwyrm/templates/ostatus/template.html index 7d670b0a..04e432aa 100644 --- a/bookwyrm/templates/ostatus/template.html +++ b/bookwyrm/templates/ostatus/template.html @@ -48,59 +48,13 @@
- -
{% block content%}{% endblock %}
- - +{% include 'components/footer.html' %} - - - - - - -{% block scripts %}{% endblock %} From 1636dfd308ca8eb8827a6aa8f6be9587bc902656 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Mon, 29 Nov 2021 20:42:16 +1100 Subject: [PATCH 038/169] fix footer indentation --- bookwyrm/templates/components/footer.html | 68 +++++++++++------------ 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/bookwyrm/templates/components/footer.html b/bookwyrm/templates/components/footer.html index 047d7bfa..df11e9d5 100644 --- a/bookwyrm/templates/components/footer.html +++ b/bookwyrm/templates/components/footer.html @@ -3,43 +3,43 @@ {% load static %} From dd0114c64468b84323aa7cc7526baee683ca07b5 Mon Sep 17 00:00:00 2001 From: Joachim Date: Mon, 29 Nov 2021 22:33:03 +0100 Subject: [PATCH 039/169] Include errors display snippet --- .../templates/preferences/delete_user.html | 5 ++--- bookwyrm/templates/preferences/edit_user.html | 20 ++++++++----------- bookwyrm/templates/settings/site.html | 5 ++--- bookwyrm/templates/snippets/form_errors.html | 9 +++++++++ 4 files changed, 21 insertions(+), 18 deletions(-) create mode 100644 bookwyrm/templates/snippets/form_errors.html diff --git a/bookwyrm/templates/preferences/delete_user.html b/bookwyrm/templates/preferences/delete_user.html index a72cc97d..b009230c 100644 --- a/bookwyrm/templates/preferences/delete_user.html +++ b/bookwyrm/templates/preferences/delete_user.html @@ -19,9 +19,8 @@
- {% for error in form.password.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.password.errors id="desc_password" %}
diff --git a/bookwyrm/templates/preferences/edit_user.html b/bookwyrm/templates/preferences/edit_user.html index a3f8962c..b18eb4e9 100644 --- a/bookwyrm/templates/preferences/edit_user.html +++ b/bookwyrm/templates/preferences/edit_user.html @@ -33,31 +33,27 @@ {% endif %}
{{ form.avatar }} - {% for error in form.avatar.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.avatar.errors id="desc_avatar" %}
{{ form.name }} - {% for error in form.name.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.name.errors id="desc_name" %}
{{ form.summary }} - {% for error in form.summary.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.summary.errors id="desc_summary" %}
{{ form.email }} - {% for error in form.email.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.email.errors id="desc_email" %}
diff --git a/bookwyrm/templates/settings/site.html b/bookwyrm/templates/settings/site.html index 01b25036..3c05e147 100644 --- a/bookwyrm/templates/settings/site.html +++ b/bookwyrm/templates/settings/site.html @@ -123,9 +123,8 @@
{{ site_form.invite_request_text }} - {% for error in site_form.invite_request_text.errors %} -

{{ error|escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=site_form.invite_request_text.errors id="desc_invite_request_text" %}
diff --git a/bookwyrm/templates/snippets/form_errors.html b/bookwyrm/templates/snippets/form_errors.html new file mode 100644 index 00000000..ecbf7ff8 --- /dev/null +++ b/bookwyrm/templates/snippets/form_errors.html @@ -0,0 +1,9 @@ +{% if errors_list %} +
+ {% for error in errors_list %} +

+ {{ error | escape }} +

+ {% endfor %} +
+{% endif %} From 28f0882ba61dec1f41748d7e0ea9477ae1f71168 Mon Sep 17 00:00:00 2001 From: Joachim Date: Mon, 29 Nov 2021 22:39:01 +0100 Subject: [PATCH 040/169] Handle Author form errors --- bookwyrm/forms.py | 34 ++++++++++++++- bookwyrm/templates/author/edit_author.html | 50 +++++++++------------- 2 files changed, 53 insertions(+), 31 deletions(-) diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index ffbb237b..88820c8f 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -236,7 +236,39 @@ class AuthorForm(CustomForm): "librarything_key", "goodreads_key", ] - + widgets = { + "name": forms.TextInput( + attrs={"aria-describedby": "desc_name"} + ), + "aliases": forms.TextInput( + attrs={"aria-describedby": "desc_aliases"} + ), + "bio": forms.Textarea( + attrs={"aria-describedby": "desc_bio"} + ), + "wikipedia_link": forms.TextInput( + attrs={"aria-describedby": "desc_wikipedia_link"} + ), + "born": forms.SelectDateWidget( + attrs={"aria-describedby": "desc_born"} + ), + "died": forms.SelectDateWidget( + attrs={"aria-describedby": "desc_died"} + ), + "oepnlibrary_key": forms.TextInput( + attrs={"aria-describedby": "desc_oepnlibrary_key"} + ), + "inventaire_id": forms.TextInput( + attrs={"aria-describedby": "desc_inventaire_id"} + ), + "librarything_key": forms.TextInput( + attrs={"aria-describedby": "desc_librarything_key"} + ), + "goodreads_key": forms.TextInput( + attrs={"aria-describedby": "desc_goodreads_key"} + ), + } + class ImportForm(forms.Form): csv_file = forms.FileField() diff --git a/bookwyrm/templates/author/edit_author.html b/bookwyrm/templates/author/edit_author.html index 54d7f4f1..de1a7875 100644 --- a/bookwyrm/templates/author/edit_author.html +++ b/bookwyrm/templates/author/edit_author.html @@ -34,47 +34,41 @@
{{ form.name }} - {% for error in form.name.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.name.errors id="desc_name" %}
{{ form.aliases }} {% trans "Separate multiple values with commas." %} - {% for error in form.aliases.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.aliases.errors id="desc_aliases" %}
{{ form.bio }} - {% for error in form.bio.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.bio.errors id="desc_bio" %}

{{ form.wikipedia_link }}

- {% for error in form.wikipedia_link.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.wikipedia_link.errors id="desc_wikipedia_link" %}
- {% for error in form.born.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.born.errors id="desc_born" %}
- {% for error in form.died.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.died.errors id="desc_died" %}
@@ -82,33 +76,29 @@
{{ form.openlibrary_key }} - {% for error in form.openlibrary_key.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.oepnlibrary_key.errors id="desc_oepnlibrary_key" %}
{{ form.inventaire_id }} - {% for error in form.inventaire_id.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.inventaire_id.errors id="desc_inventaire_id" %}
{{ form.librarything_key }} - {% for error in form.librarything_key.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.librarything_key.errors id="desc_librarything_key" %}
{{ form.goodreads_key }} - {% for error in form.goodreads_key.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.goodreads_key.errors id="desc_goodreads_key" %}
From adb0d356a8d81ed63c64e74befa9a4ac9dcfea76 Mon Sep 17 00:00:00 2001 From: Joachim Date: Mon, 29 Nov 2021 22:39:44 +0100 Subject: [PATCH 041/169] Update site.html --- bookwyrm/templates/settings/site.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/templates/settings/site.html b/bookwyrm/templates/settings/site.html index 3c05e147..8efad308 100644 --- a/bookwyrm/templates/settings/site.html +++ b/bookwyrm/templates/settings/site.html @@ -124,7 +124,7 @@ {{ site_form.invite_request_text }} - {% include 'snippets/form_errors.html' with errors_list=site_form.invite_request_text.errors id="desc_invite_request_text" %} + {% include 'snippets/form_errors.html' with errors_list=site_form.invite_request_text.errors id="desc_invite_request_text" %} From c2873c601f4deb2efa05af166fe49c9a373479af Mon Sep 17 00:00:00 2001 From: Joachim Date: Mon, 29 Nov 2021 23:26:25 +0100 Subject: [PATCH 042/169] Register form --- .../templates/snippets/register_form.html | 25 +++++++++---------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/bookwyrm/templates/snippets/register_form.html b/bookwyrm/templates/snippets/register_form.html index 9e610bd1..a1af78ef 100644 --- a/bookwyrm/templates/snippets/register_form.html +++ b/bookwyrm/templates/snippets/register_form.html @@ -3,32 +3,31 @@
- + + + {% include 'snippets/form_errors.html' with errors_list=register_form.localname.errors id="desc_localname_register" %}
- {% for error in register_form.localname.errors %} -

{{ error | escape }}

- {% endfor %}
- - {% for error in register_form.email.errors %} -

{{ error | escape }}

- {% endfor %} + + + {% include 'snippets/form_errors.html' with errors_list=register_form.email.errors id="desc_email_register" %}
- - {% for error in register_form.password.errors %} -

{{ error | escape }}

- {% endfor %} + + + {% include 'snippets/form_errors.html' with errors_list=register_form.password.errors id="desc_password_register" %}
- +
From 08b4c538e621f0ba979f94aeefa89064a304d5e7 Mon Sep 17 00:00:00 2001 From: Joachim Date: Mon, 29 Nov 2021 23:26:43 +0100 Subject: [PATCH 043/169] User moderation actions --- .../users/user_moderation_actions.html | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/bookwyrm/templates/settings/users/user_moderation_actions.html b/bookwyrm/templates/settings/users/user_moderation_actions.html index a976359f..b5f69529 100644 --- a/bookwyrm/templates/settings/users/user_moderation_actions.html +++ b/bookwyrm/templates/settings/users/user_moderation_actions.html @@ -50,18 +50,23 @@ {% endif %} {% with group=user.groups.first %}
- {% for value, name in group_form.fields.groups.choices %} - + {% endfor %} - +
- {% for error in group_form.groups.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=group_form.groups.errors id="desc_user_group" %} {% endwith %} - + {% endif %} From a154597de179d76f491499a06c72db430db198f1 Mon Sep 17 00:00:00 2001 From: Joachim Date: Mon, 29 Nov 2021 23:26:53 +0100 Subject: [PATCH 044/169] Delete user form --- bookwyrm/templates/settings/users/delete_user_form.html | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bookwyrm/templates/settings/users/delete_user_form.html b/bookwyrm/templates/settings/users/delete_user_form.html index 158745d0..1ea63269 100644 --- a/bookwyrm/templates/settings/users/delete_user_form.html +++ b/bookwyrm/templates/settings/users/delete_user_form.html @@ -15,10 +15,9 @@

- - {% for error in form.password.errors %} -

{{ error | escape }}

- {% endfor %} + + + {% include 'snippets/form_errors.html' with errors_list=form.password.errors id="desc_password" %}
From 0a621550b8863d7dda304864f09a12b4e0248baf Mon Sep 17 00:00:00 2001 From: Joachim Date: Mon, 29 Nov 2021 23:27:04 +0100 Subject: [PATCH 045/169] IP address form --- .../settings/ip_blocklist/ip_address_form.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bookwyrm/templates/settings/ip_blocklist/ip_address_form.html b/bookwyrm/templates/settings/ip_blocklist/ip_address_form.html index c8a4c3e7..4a776987 100644 --- a/bookwyrm/templates/settings/ip_blocklist/ip_address_form.html +++ b/bookwyrm/templates/settings/ip_blocklist/ip_address_form.html @@ -20,16 +20,16 @@
- +
- {% for error in form.address.errors %} -

{{ error | escape }}

- {% endfor %} + {% include 'snippets/form_errors.html' with errors_list=form.address.errors id="desc_address" %}
- +
From 5d0c6bdde24d9964848826bdf12f5683145655d6 Mon Sep 17 00:00:00 2001 From: Joachim Date: Mon, 29 Nov 2021 23:27:25 +0100 Subject: [PATCH 046/169] Edit instance form --- .../settings/federation/edit_instance.html | 45 +++++++++++-------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/bookwyrm/templates/settings/federation/edit_instance.html b/bookwyrm/templates/settings/federation/edit_instance.html index 7c2e6be6..0a67895c 100644 --- a/bookwyrm/templates/settings/federation/edit_instance.html +++ b/bookwyrm/templates/settings/federation/edit_instance.html @@ -27,11 +27,12 @@
- - - {% for error in form.server_name.errors %} -

{{ error | escape }}

- {% endfor %} + + + + {% include 'snippets/form_errors.html' with errors_list=form.server_name.errors id="desc_server_name" %}
@@ -49,29 +50,37 @@
- - - {% for error in form.application_type.errors %} -

{{ error | escape }}

- {% endfor %} + + + + {% include 'snippets/form_errors.html' with errors_list=form.application_type.errors id="desc_application_type" %}
- - - {% for error in form.application_version.errors %} -

{{ error | escape }}

- {% endfor %} + + + + {% include 'snippets/form_errors.html' with errors_list=form.application_version.errors id="desc_application_version" %}
- - + +
- + {% endblock %} From a6760cabc86d99b23bda32e36464a4a913aa7c3c Mon Sep 17 00:00:00 2001 From: Joachim Date: Mon, 29 Nov 2021 23:28:29 +0100 Subject: [PATCH 047/169] Email domain form --- bookwyrm/forms.py | 5 +++++ bookwyrm/templates/settings/email_blocklist/domain_form.html | 4 +--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index 88820c8f..ddb02d93 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -383,6 +383,11 @@ class EmailBlocklistForm(CustomForm): class Meta: model = models.EmailBlocklist fields = ["domain"] + widgets = { + "avatar": forms.TextInput( + attrs={'aria-describedby': "desc_domain"} + ), + } class IPBlocklistForm(CustomForm): diff --git a/bookwyrm/templates/settings/email_blocklist/domain_form.html b/bookwyrm/templates/settings/email_blocklist/domain_form.html index e9333749..cebc97c8 100644 --- a/bookwyrm/templates/settings/email_blocklist/domain_form.html +++ b/bookwyrm/templates/settings/email_blocklist/domain_form.html @@ -17,10 +17,8 @@ {{ form.domain }}
- {% for error in form.domain.errors %} -

{{ error | escape }}

- {% endfor %} + {% include 'snippets/form_errors.html' with errors_list=form.domain.errors id="desc_domain" %}
From 659d13d0a60e80ac17e28ba2c41a295fb2b73422 Mon Sep 17 00:00:00 2001 From: Joachim Date: Mon, 29 Nov 2021 23:28:51 +0100 Subject: [PATCH 048/169] Announcement form --- bookwyrm/forms.py | 20 +++++++ .../announcements/announcement_form.html | 58 +++++++++++-------- 2 files changed, 53 insertions(+), 25 deletions(-) diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index ddb02d93..e8136a54 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -359,6 +359,26 @@ class AnnouncementForm(CustomForm): class Meta: model = models.Announcement exclude = ["remote_id"] + widgets = { + "preview": forms.TextInput( + attrs={"aria-describedby": "desc_preview"} + ), + "content": forms.Textarea( + attrs={"aria-describedby": "desc_content"} + ), + "event_date": forms.SelectDateWidget( + attrs={"aria-describedby": "desc_event_date"} + ), + "start_date": forms.SelectDateWidget( + attrs={"aria-describedby": "desc_start_date"} + ), + "end_date": forms.SelectDateWidget( + attrs={"aria-describedby": "desc_end_date"} + ), + "active": forms.CheckboxInput( + attrs={"aria-describedby": "desc_active"} + ), + } class ListForm(CustomForm): diff --git a/bookwyrm/templates/settings/announcements/announcement_form.html b/bookwyrm/templates/settings/announcements/announcement_form.html index ffdbfc2f..8f68e255 100644 --- a/bookwyrm/templates/settings/announcements/announcement_form.html +++ b/bookwyrm/templates/settings/announcements/announcement_form.html @@ -13,60 +13,68 @@ {% csrf_token %}

- + {{ form.preview }} - {% for error in form.preview.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.preview.errors id="desc_preview" %}

- + {{ form.content }} - {% for error in form.content.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.content.errors id="desc_content" %}

- + - {% for error in form.event_date.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.event_date.errors id="desc_event_date" %}

- + - {% for error in form.start_date.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.start_date.errors id="desc_start_date" %}

- + - {% for error in form.end_date.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.end_date.errors id="desc_end_date" %}

- + {{ form.active }} - {% for error in form.active.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.active.errors id="desc_active" %}

- +
{% endblock %} From 63d31b8623d5eb084b049b5acbf8ae0a91da8408 Mon Sep 17 00:00:00 2001 From: Joachim Date: Mon, 29 Nov 2021 23:29:22 +0100 Subject: [PATCH 049/169] Edit book form --- bookwyrm/forms.py | 61 ++++- .../templates/book/edit/edit_book_form.html | 229 ++++++++++-------- 2 files changed, 194 insertions(+), 96 deletions(-) diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index e8136a54..3f46be34 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -218,6 +218,65 @@ class EditionForm(CustomForm): "connector", "search_vector", ] + widgets = { + "title": forms.TextInput( + attrs={"aria-describedby": "desc_title"} + ), + "subtitle": forms.TextInput( + attrs={"aria-describedby": "desc_subtitle"} + ), + "description": forms.Textarea( + attrs={"aria-describedby": "desc_description"} + ), + "series": forms.TextInput( + attrs={"aria-describedby": "desc_series"} + ), + "series_number": forms.TextInput( + attrs={"aria-describedby": "desc_series_number"} + ), + "languages": forms.TextInput( + attrs={"aria-describedby": "desc_languages_help desc_languages"} + ), + "publishers": forms.TextInput( + attrs={"aria-describedby": "desc_publishers_help desc_publishers"} + ), + "first_published_date": forms.SelectDateWidget( + attrs={"aria-describedby": "desc_first_published_date"} + ), + "published_date": forms.SelectDateWidget( + attrs={"aria-describedby": "desc_published_date"} + ), + "cover": ClearableFileInputWithWarning( + attrs={"aria-describedby": "desc_cover"} + ), + "physical_format": forms.Select( + attrs={"aria-describedby": "desc_physical_format"} + ), + "physical_format_detail": forms.TextInput( + attrs={"aria-describedby": "desc_physical_format_detail"} + ), + "pages": forms.NumberInput( + attrs={"aria-describedby": "desc_pages"} + ), + "isbn_13": forms.TextInput( + attrs={"aria-describedby": "desc_isbn_13"} + ), + "isbn_10": forms.TextInput( + attrs={"aria-describedby": "desc_isbn_10"} + ), + "openlibrary_key": forms.TextInput( + attrs={"aria-describedby": "desc_openlibrary_key"} + ), + "inventaire_id": forms.TextInput( + attrs={"aria-describedby": "desc_inventaire_id"} + ), + "oclc_number": forms.TextInput( + attrs={"aria-describedby": "desc_oclc_number"} + ), + "ASIN": forms.TextInput( + attrs={"aria-describedby": "desc_ASIN"} + ), + } class AuthorForm(CustomForm): @@ -268,7 +327,7 @@ class AuthorForm(CustomForm): attrs={"aria-describedby": "desc_goodreads_key"} ), } - + class ImportForm(forms.Form): csv_file = forms.FileField() diff --git a/bookwyrm/templates/book/edit/edit_book_form.html b/bookwyrm/templates/book/edit/edit_book_form.html index 982bb56d..feebb803 100644 --- a/bookwyrm/templates/book/edit/edit_book_form.html +++ b/bookwyrm/templates/book/edit/edit_book_form.html @@ -12,106 +12,125 @@
-

{% trans "Metadata" %}

+

+ {% trans "Metadata" %} +

- - - {% for error in form.title.errors %} -

{{ error | escape }}

- {% endfor %} + + + + {% include 'snippets/form_errors.html' with errors_list=form.title.errors id="desc_title" %}
- - - {% for error in form.subtitle.errors %} -

{{ error | escape }}

- {% endfor %} + + + + {% include 'snippets/form_errors.html' with errors_list=form.subtitle.errors id="desc_subtitle" %}
- + {{ form.description }} - {% for error in form.description.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.description.errors id="desc_description" %}
- - - {% for error in form.series.errors %} -

{{ error | escape }}

- {% endfor %} + + + + {% include 'snippets/form_errors.html' with errors_list=form.series.errors id="desc_series" %}
- + {{ form.series_number }} - {% for error in form.series_number.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.series_number.errors id="desc_series_number" %}
- + {{ form.languages }} - {% trans "Separate multiple values with commas." %} - {% for error in form.languages.errors %} -

{{ error | escape }}

- {% endfor %} + + {% trans "Separate multiple values with commas." %} + + + {% include 'snippets/form_errors.html' with errors_list=form.languages.errors id="desc_languages" %}
-

{% trans "Publication" %}

+

+ {% trans "Publication" %} +

- + {{ form.publishers }} - {% trans "Separate multiple values with commas." %} - {% for error in form.publishers.errors %} -

{{ error | escape }}

- {% endfor %} + + {% trans "Separate multiple values with commas." %} + + + {% include 'snippets/form_errors.html' with errors_list=form.publishers.errors id="desc_publishers" %}
- - - {% for error in form.first_published_date.errors %} -

{{ error | escape }}

- {% endfor %} + + + + {% include 'snippets/form_errors.html' with errors_list=form.first_published_date.errors id="desc_first_published_date" %}
- - - {% for error in form.published_date.errors %} -

{{ error | escape }}

- {% endfor %} + + + + {% include 'snippets/form_errors.html' with errors_list=form.published_date.errors id="desc_published_date" %}
-

{% trans "Authors" %}

+

+ {% trans "Authors" %} +

{% if book.authors.exists %}
{% for author in book.authors.all %}
-

+

{% blocktrans with name=author.name %}Author page for {{ name }}{% endblocktrans %}

@@ -119,9 +138,13 @@
{% endif %}
- - - {% trans "Separate multiple values with commas." %} + + + + {% trans "Separate multiple values with commas." %} +
@@ -129,7 +152,9 @@
-

{% trans "Cover" %}

+

+ {% trans "Cover" %} +

{% if book.cover %} @@ -140,108 +165,122 @@
- + {{ form.cover }}
- +
- {% for error in form.cover.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.cover.errors id="desc_cover" %}
-

{% trans "Physical Properties" %}

+

+ {% trans "Physical Properties" %} +

- +
{{ form.physical_format }}
- {% for error in form.physical_format.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.physical_format.errors id="desc_physical_format" %}
- + {{ form.physical_format_detail }} - {% for error in form.physical_format_detail.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.physical_format_detail.errors id="desc_physical_format_detail" %}
- + {{ form.pages }} - {% for error in form.pages.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.pages.errors id="desc_pages" %}
-

{% trans "Book Identifiers" %}

+

+ {% trans "Book Identifiers" %} +

- + {{ form.isbn_13 }} - {% for error in form.isbn_13.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.isbn_13.errors id="desc_isbn_13" %}
- + {{ form.isbn_10 }} - {% for error in form.isbn_10.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.isbn_10.errors id="desc_isbn_10" %}
- + {{ form.openlibrary_key }} - {% for error in form.openlibrary_key.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.openlibrary_key.errors id="desc_openlibrary_key" %}
- + {{ form.inventaire_id }} - {% for error in form.inventaire_id.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.inventaire_id.errors id="desc_inventaire_id" %}
- + {{ form.oclc_number }} - {% for error in form.oclc_number.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.oclc_number.errors id="desc_oclc_number" %}
- + {{ form.asin }} - {% for error in form.ASIN.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.ASIN.errors id="desc_ASIN" %}
From 3eb4dfdc9be1cb4bc8b7e7ce718a030fa9ce4985 Mon Sep 17 00:00:00 2001 From: Joachim Date: Mon, 29 Nov 2021 23:29:36 +0100 Subject: [PATCH 050/169] Get started user form --- bookwyrm/templates/get_started/profile.html | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/bookwyrm/templates/get_started/profile.html b/bookwyrm/templates/get_started/profile.html index 90cdb410..ef33afac 100644 --- a/bookwyrm/templates/get_started/profile.html +++ b/bookwyrm/templates/get_started/profile.html @@ -14,16 +14,14 @@
- {% for error in form.name.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.name.errors id="desc_name" %}
- {% for error in form.summary.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.summary.errors id="desc_summary" %}
@@ -31,9 +29,8 @@
{{ form.avatar }} - {% for error in form.avatar.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=form.avatar.errors id="desc_avatar" %}
From 3cf9660df30f4eec6f4779029ce33cbf3752bf0f Mon Sep 17 00:00:00 2001 From: Joachim Date: Mon, 29 Nov 2021 23:29:56 +0100 Subject: [PATCH 051/169] Login form --- bookwyrm/templates/landing/layout.html | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bookwyrm/templates/landing/layout.html b/bookwyrm/templates/landing/layout.html index 0d6f231c..56985768 100644 --- a/bookwyrm/templates/landing/layout.html +++ b/bookwyrm/templates/landing/layout.html @@ -65,10 +65,9 @@ {% csrf_token %}
- - {% for error in request_form.email.errors %} -

{{ error|escape }}

- {% endfor %} + + + {% include 'snippets/form_errors.html' with errors_list=request_form.email.errors id="desc_request_email" %}
From 80535a3b0caee396b82ca39207a4d03e251c9174 Mon Sep 17 00:00:00 2001 From: Joachim Date: Mon, 29 Nov 2021 23:30:14 +0100 Subject: [PATCH 052/169] Login form --- bookwyrm/templates/landing/login.html | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bookwyrm/templates/landing/login.html b/bookwyrm/templates/landing/login.html index 95baa06d..c9ac2526 100644 --- a/bookwyrm/templates/landing/login.html +++ b/bookwyrm/templates/landing/login.html @@ -26,11 +26,10 @@
- +
- {% for error in login_form.password.errors %} -

{{ error | escape }}

- {% endfor %} + + {% include 'snippets/form_errors.html' with errors_list=login_form.password.errors id="desc_password" %}
From 43072a357f2f100907dafc608f9319444dc16f48 Mon Sep 17 00:00:00 2001 From: Joachim Date: Mon, 29 Nov 2021 23:30:23 +0100 Subject: [PATCH 053/169] Password reset form --- .../templates/landing/password_reset.html | 26 ++++++++++++++----- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/bookwyrm/templates/landing/password_reset.html b/bookwyrm/templates/landing/password_reset.html index be1dccf8..8348efd4 100644 --- a/bookwyrm/templates/landing/password_reset.html +++ b/bookwyrm/templates/landing/password_reset.html @@ -8,21 +8,33 @@

{% trans "Reset Password" %}

- {% for error in errors %} -

{{ error }}

- {% endfor %} + + {% if errors %} +
+ {% for error in errors %} +

+ {{ error }} +

+ {% endfor %} +
+ + {% endif %}
{% csrf_token %}
- +
- +
- +
- +
From 4d93545d885400cc6370e2410b5311d1502e2dd5 Mon Sep 17 00:00:00 2001 From: Joachim Date: Mon, 29 Nov 2021 23:31:05 +0100 Subject: [PATCH 054/169] Lint forms --- bookwyrm/forms.py | 64 ++++++++++++----------------------------------- 1 file changed, 16 insertions(+), 48 deletions(-) diff --git a/bookwyrm/forms.py b/bookwyrm/forms.py index 3f46be34..aff1e29c 100644 --- a/bookwyrm/forms.py +++ b/bookwyrm/forms.py @@ -219,18 +219,12 @@ class EditionForm(CustomForm): "search_vector", ] widgets = { - "title": forms.TextInput( - attrs={"aria-describedby": "desc_title"} - ), - "subtitle": forms.TextInput( - attrs={"aria-describedby": "desc_subtitle"} - ), + "title": forms.TextInput(attrs={"aria-describedby": "desc_title"}), + "subtitle": forms.TextInput(attrs={"aria-describedby": "desc_subtitle"}), "description": forms.Textarea( attrs={"aria-describedby": "desc_description"} ), - "series": forms.TextInput( - attrs={"aria-describedby": "desc_series"} - ), + "series": forms.TextInput(attrs={"aria-describedby": "desc_series"}), "series_number": forms.TextInput( attrs={"aria-describedby": "desc_series_number"} ), @@ -255,15 +249,9 @@ class EditionForm(CustomForm): "physical_format_detail": forms.TextInput( attrs={"aria-describedby": "desc_physical_format_detail"} ), - "pages": forms.NumberInput( - attrs={"aria-describedby": "desc_pages"} - ), - "isbn_13": forms.TextInput( - attrs={"aria-describedby": "desc_isbn_13"} - ), - "isbn_10": forms.TextInput( - attrs={"aria-describedby": "desc_isbn_10"} - ), + "pages": forms.NumberInput(attrs={"aria-describedby": "desc_pages"}), + "isbn_13": forms.TextInput(attrs={"aria-describedby": "desc_isbn_13"}), + "isbn_10": forms.TextInput(attrs={"aria-describedby": "desc_isbn_10"}), "openlibrary_key": forms.TextInput( attrs={"aria-describedby": "desc_openlibrary_key"} ), @@ -273,9 +261,7 @@ class EditionForm(CustomForm): "oclc_number": forms.TextInput( attrs={"aria-describedby": "desc_oclc_number"} ), - "ASIN": forms.TextInput( - attrs={"aria-describedby": "desc_ASIN"} - ), + "ASIN": forms.TextInput(attrs={"aria-describedby": "desc_ASIN"}), } @@ -296,24 +282,14 @@ class AuthorForm(CustomForm): "goodreads_key", ] widgets = { - "name": forms.TextInput( - attrs={"aria-describedby": "desc_name"} - ), - "aliases": forms.TextInput( - attrs={"aria-describedby": "desc_aliases"} - ), - "bio": forms.Textarea( - attrs={"aria-describedby": "desc_bio"} - ), + "name": forms.TextInput(attrs={"aria-describedby": "desc_name"}), + "aliases": forms.TextInput(attrs={"aria-describedby": "desc_aliases"}), + "bio": forms.Textarea(attrs={"aria-describedby": "desc_bio"}), "wikipedia_link": forms.TextInput( attrs={"aria-describedby": "desc_wikipedia_link"} ), - "born": forms.SelectDateWidget( - attrs={"aria-describedby": "desc_born"} - ), - "died": forms.SelectDateWidget( - attrs={"aria-describedby": "desc_died"} - ), + "born": forms.SelectDateWidget(attrs={"aria-describedby": "desc_born"}), + "died": forms.SelectDateWidget(attrs={"aria-describedby": "desc_died"}), "oepnlibrary_key": forms.TextInput( attrs={"aria-describedby": "desc_oepnlibrary_key"} ), @@ -419,12 +395,8 @@ class AnnouncementForm(CustomForm): model = models.Announcement exclude = ["remote_id"] widgets = { - "preview": forms.TextInput( - attrs={"aria-describedby": "desc_preview"} - ), - "content": forms.Textarea( - attrs={"aria-describedby": "desc_content"} - ), + "preview": forms.TextInput(attrs={"aria-describedby": "desc_preview"}), + "content": forms.Textarea(attrs={"aria-describedby": "desc_content"}), "event_date": forms.SelectDateWidget( attrs={"aria-describedby": "desc_event_date"} ), @@ -434,9 +406,7 @@ class AnnouncementForm(CustomForm): "end_date": forms.SelectDateWidget( attrs={"aria-describedby": "desc_end_date"} ), - "active": forms.CheckboxInput( - attrs={"aria-describedby": "desc_active"} - ), + "active": forms.CheckboxInput(attrs={"aria-describedby": "desc_active"}), } @@ -463,9 +433,7 @@ class EmailBlocklistForm(CustomForm): model = models.EmailBlocklist fields = ["domain"] widgets = { - "avatar": forms.TextInput( - attrs={'aria-describedby': "desc_domain"} - ), + "avatar": forms.TextInput(attrs={"aria-describedby": "desc_domain"}), } From 386371baa3ee85e54c1f918c41297dc3c0681120 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Tue, 30 Nov 2021 12:42:52 +1100 Subject: [PATCH 055/169] improve a11y on notifications Also change close link to a button. Co-authored-by: Joachim --- bookwyrm/templates/ostatus/error.html | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bookwyrm/templates/ostatus/error.html b/bookwyrm/templates/ostatus/error.html index 085fa345..99a2a9ac 100644 --- a/bookwyrm/templates/ostatus/error.html +++ b/bookwyrm/templates/ostatus/error.html @@ -27,34 +27,34 @@
{% elif error == 'ostatus_subscribe' %} -
+

{% blocktrans %}Something went wrong trying to follow {{ account }}{% endblocktrans %}

{% trans 'Check you have the correct username before trying again.' %}

{% elif error == 'remote_subscribe' %} -
+

{% blocktrans %}Something went wrong trying to follow from {{ account }}{% endblocktrans %}

{% trans 'Check you have the correct username before trying again.' %}

{% elif error == 'is_blocked' %} -
+

{% blocktrans %}You have blocked {{ account }}{% endblocktrans %}

{% elif error == 'has_blocked' %} -
+

{% blocktrans %}{{ account }} has blocked you{% endblocktrans %}

{% elif error == 'already_following' %} -
+

{% blocktrans %}You are already following {{ account }}{% endblocktrans %}

{% elif error == 'already_requested' %} -
+

{% blocktrans %}You have already requested to follow {{ account }}{% endblocktrans %}

{% endif %}
- Close window +
{% endblock %} From 4ee234258a15edb56485306480cb141f291e6c1b Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Tue, 30 Nov 2021 12:47:04 +1100 Subject: [PATCH 056/169] remove OG meta in ostatus template It's just a temporary popup so would be weird to share and just gunks things up. Co-authored-by: Joachim --- bookwyrm/templates/ostatus/template.html | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/bookwyrm/templates/ostatus/template.html b/bookwyrm/templates/ostatus/template.html index 04e432aa..68284a35 100644 --- a/bookwyrm/templates/ostatus/template.html +++ b/bookwyrm/templates/ostatus/template.html @@ -17,20 +17,6 @@ - {% if preview_images_enabled is True %} - - {% else %} - - {% endif %} - - - - - - {% block opengraph_images %} - {% include 'snippets/opengraph_images.html' %} - {% endblock %} - - - - - - -{% block scripts %}{% endblock %} diff --git a/bookwyrm/templates/layout.html b/bookwyrm/templates/layout.html index 50a7ae6d..bc85e678 100644 --- a/bookwyrm/templates/layout.html +++ b/bookwyrm/templates/layout.html @@ -222,7 +222,51 @@
-{% include 'components/footer.html' %} + + + + + + + + +{% block scripts %}{% endblock %} From 7848ff792766b67d171e27dcab13f485cbf23bd4 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Tue, 30 Nov 2021 20:46:41 +1100 Subject: [PATCH 058/169] fix translation strings --- bookwyrm/templates/ostatus/remote_follow.html | 11 +++++++---- bookwyrm/templates/ostatus/subscribe.html | 10 +++++----- bookwyrm/templates/ostatus/success.html | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/bookwyrm/templates/ostatus/remote_follow.html b/bookwyrm/templates/ostatus/remote_follow.html index 6a4e565a..96c7f945 100644 --- a/bookwyrm/templates/ostatus/remote_follow.html +++ b/bookwyrm/templates/ostatus/remote_follow.html @@ -2,11 +2,12 @@ {% load i18n %} {% load utilities %} +{% block heading %} +{% blocktrans with username=user.localname sitename=site.name %}Follow {{ username }} on the fediverse{% endblocktrans %} +{% endblock %} + {% block content %}
-
-

{% blocktrans %}Follow {{ user.display_name }} on the fediverse{% endblocktrans %}

-
@@ -24,11 +25,13 @@ @{{ user|username }} -

{% blocktrans %}Follow {{ user.display_name }} from another Fediverse account like Bookwyrm, Mastodon, or Pleroma.{% endblocktrans %}

+
+

{% blocktrans with username=user.display_name %}Follow {{ username }} from another Fediverse account like Bookwyrm, Mastodon, or Pleroma.{% endblocktrans %}

+
diff --git a/bookwyrm/templates/ostatus/subscribe.html b/bookwyrm/templates/ostatus/subscribe.html index d41ce674..51dec438 100644 --- a/bookwyrm/templates/ostatus/subscribe.html +++ b/bookwyrm/templates/ostatus/subscribe.html @@ -5,11 +5,11 @@ {% block title %} {% if not request.user.is_authenticated %} -{% trans "Log in to " %} +{% blocktrans with sitename=site.name %}Log in to {{ sitename }}{% endblocktrans %} {% elif error %} -{% trans "Error following from " %} +{% blocktrans with sitename=site.name %}Error following from {{ sitename }}{% endblocktrans %} {% else %} -{% trans "Follow from " %} +{% blocktrans with sitename=site.name %}Follow from {{ sitename }}{% endblocktrans %} {% endif %} {% endblock %} @@ -19,7 +19,7 @@ {% elif error %} {% trans 'Uh oh...' %} {% else %} -{% trans 'Follow from ' %}{{ site.name }} +{% blocktrans with sitename=site.name %}Follow from {{ sitename }}{% endblocktrans %} {% endif %} {% endblock %} @@ -48,7 +48,7 @@ {% csrf_token %} - +
diff --git a/bookwyrm/templates/ostatus/success.html b/bookwyrm/templates/ostatus/success.html index 89f66273..a652989b 100644 --- a/bookwyrm/templates/ostatus/success.html +++ b/bookwyrm/templates/ostatus/success.html @@ -25,7 +25,7 @@

- {% trans 'You are now following ' %}{{ user.display_name }}! + {% blocktrans with display_name=user.display_name %}You are now following {{ display_name }}!{% endblocktrans %}

From 080fa72c84b6608d0788e2fc1b31cf0e34ed2b1c Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Tue, 30 Nov 2021 21:01:07 +1100 Subject: [PATCH 059/169] ostatus template fixes - remove unnecessary links - remove footer - remove unnecessary JS scripts - make block title and block heading empty --- bookwyrm/templates/ostatus/template.html | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/bookwyrm/templates/ostatus/template.html b/bookwyrm/templates/ostatus/template.html index 68284a35..8d2d193e 100644 --- a/bookwyrm/templates/ostatus/template.html +++ b/bookwyrm/templates/ostatus/template.html @@ -7,16 +7,11 @@ - {% block title %}{% endblock %}{{ site.name }} + {% block title %}{% endblock %} - - - - - + From 461c35f416e1838c470824d03f10c8eed8a7ff73 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Tue, 30 Nov 2021 21:02:39 +1100 Subject: [PATCH 060/169] fix buttons --- bookwyrm/templates/ostatus/error.html | 2 +- bookwyrm/templates/ostatus/success.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bookwyrm/templates/ostatus/error.html b/bookwyrm/templates/ostatus/error.html index 99a2a9ac..0c8d6f76 100644 --- a/bookwyrm/templates/ostatus/error.html +++ b/bookwyrm/templates/ostatus/error.html @@ -55,6 +55,6 @@ {% endif %}
- +
{% endblock %} diff --git a/bookwyrm/templates/ostatus/success.html b/bookwyrm/templates/ostatus/success.html index a652989b..a4f78ace 100644 --- a/bookwyrm/templates/ostatus/success.html +++ b/bookwyrm/templates/ostatus/success.html @@ -30,6 +30,6 @@
- Close window +
{% endblock %} From 9be1a8f4557e98e9bfe4aee072f074fed3fc4d5a Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Wed, 1 Dec 2021 07:45:30 +1100 Subject: [PATCH 061/169] keep close button simple --- bookwyrm/templates/ostatus/error.html | 2 +- bookwyrm/templates/ostatus/success.html | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/bookwyrm/templates/ostatus/error.html b/bookwyrm/templates/ostatus/error.html index 0c8d6f76..b5a3bf40 100644 --- a/bookwyrm/templates/ostatus/error.html +++ b/bookwyrm/templates/ostatus/error.html @@ -55,6 +55,6 @@ {% endif %}
- +
{% endblock %} diff --git a/bookwyrm/templates/ostatus/success.html b/bookwyrm/templates/ostatus/success.html index a4f78ace..66577e83 100644 --- a/bookwyrm/templates/ostatus/success.html +++ b/bookwyrm/templates/ostatus/success.html @@ -30,6 +30,6 @@
- +
{% endblock %} From 2602ae42b02c243e4550cda7407eec86009aaa6e Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Wed, 1 Dec 2021 20:07:52 +1100 Subject: [PATCH 062/169] add translation strings - add logic when default shelves used - add trans strings in a few spots they were missing --- bookwyrm/templates/directory/directory.html | 4 ++-- bookwyrm/templates/get_started/book_preview.html | 9 +++++++-- bookwyrm/templates/search/book.html | 2 +- bookwyrm/templates/shelf/shelf.html | 5 ++++- bookwyrm/templates/snippets/shelf_selector.html | 9 ++++++++- bookwyrm/templates/user/user.html | 11 ++++++++--- 6 files changed, 30 insertions(+), 10 deletions(-) diff --git a/bookwyrm/templates/directory/directory.html b/bookwyrm/templates/directory/directory.html index 9753c4c0..c3ddb3c5 100644 --- a/bookwyrm/templates/directory/directory.html +++ b/bookwyrm/templates/directory/directory.html @@ -18,7 +18,7 @@

{% csrf_token %} - +

{% url 'prefs-profile' as path %} {% blocktrans with path=path %}You can opt-out at any time in your profile settings.{% endblocktrans %} @@ -28,7 +28,7 @@

{% trans "Dismiss message" as button_text %}
diff --git a/bookwyrm/templates/get_started/book_preview.html b/bookwyrm/templates/get_started/book_preview.html index 893e7593..8a20d0d7 100644 --- a/bookwyrm/templates/get_started/book_preview.html +++ b/bookwyrm/templates/get_started/book_preview.html @@ -4,9 +4,14 @@
diff --git a/bookwyrm/templates/search/book.html b/bookwyrm/templates/search/book.html index 704f055b..66adb8c8 100644 --- a/bookwyrm/templates/search/book.html +++ b/bookwyrm/templates/search/book.html @@ -39,7 +39,7 @@
diff --git a/bookwyrm/templates/shelf/shelf.html b/bookwyrm/templates/shelf/shelf.html index 01d41aa0..0184ab1d 100644 --- a/bookwyrm/templates/shelf/shelf.html +++ b/bookwyrm/templates/shelf/shelf.html @@ -80,7 +80,10 @@

- {{ shelf.name }} + {% if shelf.identifier == 'to-read' %}{% trans "To Read" %} + {% elif shelf.identifier == 'reading' %}{% trans "Currently Reading" %} + {% elif shelf.identifier == 'read' %}{% trans "Read" %} + {% else %}{{ shelf.name }}{% endif %} {% include 'snippets/privacy-icons.html' with item=shelf %} diff --git a/bookwyrm/templates/snippets/shelf_selector.html b/bookwyrm/templates/snippets/shelf_selector.html index ca5a39f6..2bb5e253 100644 --- a/bookwyrm/templates/snippets/shelf_selector.html +++ b/bookwyrm/templates/snippets/shelf_selector.html @@ -13,7 +13,14 @@ - + {% endfor %} diff --git a/bookwyrm/templates/user/user.html b/bookwyrm/templates/user/user.html index 36e646aa..9e75cefc 100755 --- a/bookwyrm/templates/user/user.html +++ b/bookwyrm/templates/user/user.html @@ -29,8 +29,13 @@
{% for shelf in shelves %}
-

{{ shelf.name }} - {% if shelf.size > 3 %}({% blocktrans with size=shelf.size %}View all {{ size }}{% endblocktrans %}){% endif %}

+

+ {% if shelf.name == 'To Read' %}{% trans "To Read" %} + {% elif shelf.name == 'Currently Reading' %}{% trans "Currently Reading" %} + {% elif shelf.name == 'Read' %}{% trans "Read" %} + {% else %}{{ shelf.name }}{% endif %} + {% if shelf.size > 3 %}({% blocktrans with size=shelf.size %}View all {{ size }}{% endblocktrans %}){% endif %} +

{% for book in shelf.books %}
@@ -49,7 +54,7 @@ {% if goal %}
-

{% now 'Y' %} Reading Goal

+

{% now 'Y' %} {% trans 'Reading Goal' %}

{% include 'snippets/goal_progress.html' with goal=goal %}
{% endif %} From 8e6619294f1864b83a51457a9475567eace42055 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Wed, 1 Dec 2021 21:02:25 +1100 Subject: [PATCH 063/169] oclc server sure is slow --- bookwyrm/utils/isni.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/utils/isni.py b/bookwyrm/utils/isni.py index a35c3f24..65d20c85 100644 --- a/bookwyrm/utils/isni.py +++ b/bookwyrm/utils/isni.py @@ -19,7 +19,7 @@ def request_isni_data(search_index, search_term, max_records=5): "recordPacking": "xml", "sortKeys": "RLV,pica,0,,", } - result = requests.get("http://isni.oclc.org/sru/", params=query_params, timeout=10) + result = requests.get("http://isni.oclc.org/sru/", params=query_params, timeout=15) # the OCLC ISNI server asserts the payload is encoded # in latin1, but we know better result.encoding = "utf-8" From 5f10ccd9c7cb0f953b197bc5239515c5d33b0fa0 Mon Sep 17 00:00:00 2001 From: Olof Pettersson Date: Wed, 1 Dec 2021 14:18:28 +0100 Subject: [PATCH 064/169] Comment out trailing block ending For people installing an instance with only the reverse proxy server, the hidden trailing `}` at the end of the second server block is quite hard to catch and it took me a good while to figure it out. Having the entire server commented out makes the whole process more understandable in my opinion. --- nginx/production | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nginx/production b/nginx/production index 8a13413a..3d9cfa5a 100644 --- a/nginx/production +++ b/nginx/production @@ -17,7 +17,8 @@ server { # # redirect http to https # return 301 https://your-domain.com$request_uri; -# } +} + # # server { # listen [::]:443 ssl http2; @@ -54,7 +55,7 @@ server { # location /static/ { # alias /app/static/; # } -} +# } # Reverse-Proxy server # server { From 2ec6e566986de5ea4c85cf2ec43e002d58a9d4ac Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Thu, 2 Dec 2021 07:28:35 +1100 Subject: [PATCH 065/169] blocktrans for reading goal --- bookwyrm/templates/user/user.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bookwyrm/templates/user/user.html b/bookwyrm/templates/user/user.html index 9e75cefc..ccc4a44e 100755 --- a/bookwyrm/templates/user/user.html +++ b/bookwyrm/templates/user/user.html @@ -54,7 +54,8 @@ {% if goal %}
-

{% now 'Y' %} {% trans 'Reading Goal' %}

+ {% now 'Y' as current_year%} +

{% blocktrans %}{{ current_year }} Reading Goal{% endblocktrans %}

{% include 'snippets/goal_progress.html' with goal=goal %}
{% endif %} From f6dfe3530a2ca7063a7d2c3ca023632a3756028c Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 3 Dec 2021 09:58:14 -0800 Subject: [PATCH 066/169] Use book preview card for social media on status page --- bookwyrm/templates/feed/status.html | 12 ++++++++++++ bookwyrm/views/feed.py | 7 +++++++ 2 files changed, 19 insertions(+) diff --git a/bookwyrm/templates/feed/status.html b/bookwyrm/templates/feed/status.html index 5febf4e2..8dcad088 100644 --- a/bookwyrm/templates/feed/status.html +++ b/bookwyrm/templates/feed/status.html @@ -2,6 +2,18 @@ {% load i18n %} {% load bookwyrm_tags %} +{% block opengraph_images %} + +{% firstof status.book status.mention_books.first as book %} +{% if book %} + {% include 'snippets/opengraph_images.html' with image=preview %} +{% else %} + {% include 'snippets/opengraph_images.html' %} +{% endif %} + +{% endblock %} + + {% block panel %}
diff --git a/bookwyrm/views/feed.py b/bookwyrm/views/feed.py index 7cf56d48..ba6c3af5 100644 --- a/bookwyrm/views/feed.py +++ b/bookwyrm/views/feed.py @@ -177,12 +177,19 @@ class Status(View): params=[status.id, visible_thread, visible_thread], ) + preview = None + if hasattr(status, "book"): + preview = status.book.preview_image + elif status.mention_books.exists(): + preview = status.mention_books.first().preview_image + data = { **feed_page_data(request.user), **{ "status": status, "children": children, "ancestors": ancestors, + "preview": preview, }, } return TemplateResponse(request, "feed/status.html", data) From 3bd28afe93db282be61cbc4a50205a3b8179288e Mon Sep 17 00:00:00 2001 From: Joachim Date: Sat, 4 Dec 2021 16:06:07 +0100 Subject: [PATCH 067/169] Add unique embed_key to List model --- bookwyrm/migrations/0120_list_embed_key.py | 29 ++++++++++++++++++++++ bookwyrm/models/list.py | 9 +++++++ 2 files changed, 38 insertions(+) create mode 100644 bookwyrm/migrations/0120_list_embed_key.py diff --git a/bookwyrm/migrations/0120_list_embed_key.py b/bookwyrm/migrations/0120_list_embed_key.py new file mode 100644 index 00000000..40db1f0f --- /dev/null +++ b/bookwyrm/migrations/0120_list_embed_key.py @@ -0,0 +1,29 @@ +# Generated by Django 3.2.5 on 2021-12-04 10:55 + +from django.db import migrations, models +import uuid + + +def gen_uuid(apps, schema_editor): + """sets an unique UUID for embed_key""" + book_lists = apps.get_model("bookwyrm", "List") + db_alias = schema_editor.connection.alias + for book_list in book_lists.objects.using(db_alias).all(): + book_list.embed_key = uuid.uuid4() + book_list.save(broadcast=False) + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookwyrm", "0119_user_feed_status_types"), + ] + + operations = [ + migrations.AddField( + model_name="list", + name="embed_key", + field=models.UUIDField(editable=False, null=True, unique=True), + ), + migrations.RunPython(gen_uuid, reverse_code=migrations.RunPython.noop), + ] diff --git a/bookwyrm/models/list.py b/bookwyrm/models/list.py index 978a7a9b..61cb41ef 100644 --- a/bookwyrm/models/list.py +++ b/bookwyrm/models/list.py @@ -1,4 +1,6 @@ """ make a list of books!! """ +import uuid + from django.apps import apps from django.db import models from django.db.models import Q @@ -43,6 +45,7 @@ class List(OrderedCollectionMixin, BookWyrmModel): through="ListItem", through_fields=("book_list", "book"), ) + embed_key = models.UUIDField(unique=True, null=True, editable=False) activity_serializer = activitypub.BookList def get_remote_id(self): @@ -105,6 +108,12 @@ class List(OrderedCollectionMixin, BookWyrmModel): group=None, curation="closed" ) + def save(self, *args, **kwargs): + """on save, update embed_key and avoid clash with existing code""" + if not self.embed_key: + self.embed_key = uuid.uuid4() + return super(List, self).save(*args, **kwargs) + class ListItem(CollectionItemMixin, BookWyrmModel): """ok""" From d22167e105068f81acc3e78393af471532b25d53 Mon Sep 17 00:00:00 2001 From: Joachim Date: Sat, 4 Dec 2021 16:07:21 +0100 Subject: [PATCH 068/169] Add EmbedList view with an X-Frame-Options exemption --- bookwyrm/views/list.py | 69 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/bookwyrm/views/list.py b/bookwyrm/views/list.py index 97eaf9d6..89e7fa46 100644 --- a/bookwyrm/views/list.py +++ b/bookwyrm/views/list.py @@ -7,13 +7,14 @@ from django.core.paginator import Paginator from django.db import IntegrityError, transaction from django.db.models import Avg, Count, DecimalField, Q, Max from django.db.models.functions import Coalesce -from django.http import HttpResponseBadRequest, HttpResponse +from django.http import HttpResponseBadRequest, HttpResponse, Http404 from django.shortcuts import get_object_or_404, redirect from django.template.response import TemplateResponse from django.urls import reverse from django.utils.decorators import method_decorator from django.views import View from django.views.decorators.http import require_POST +from django.views.decorators.clickjacking import xframe_options_exempt from bookwyrm import book_search, forms, models from bookwyrm.activitypub import ActivitypubResponse @@ -200,6 +201,64 @@ class List(View): return redirect(book_list.local_path) +class EmbedList(View): + """embeded book list page""" + + def get(self, request, list_id, list_key): + """display a book list""" + book_list = get_object_or_404(models.List, id=list_id) + + embed_key = str(book_list.embed_key.hex) + + if list_key != embed_key: + raise Http404() + + query = request.GET.get("q") + suggestions = None + + # sort_by shall be "order" unless a valid alternative is given + sort_by = request.GET.get("sort_by", "order") + if sort_by not in ("order", "title", "rating"): + sort_by = "order" + + # direction shall be "ascending" unless a valid alternative is given + direction = request.GET.get("direction", "ascending") + if direction not in ("ascending", "descending"): + direction = "ascending" + + directional_sort_by = { + "order": "order", + "title": "book__title", + "rating": "average_rating", + }[sort_by] + if direction == "descending": + directional_sort_by = "-" + directional_sort_by + + items = book_list.listitem_set.prefetch_related("user", "book", "book__authors") + if sort_by == "rating": + items = items.annotate( + average_rating=Avg( + Coalesce("book__review__rating", 0.0), + output_field=DecimalField(), + ) + ) + items = items.filter(approved=True).order_by(directional_sort_by) + + paginated = Paginator(items, PAGE_LENGTH) + + page = paginated.get_page(request.GET.get("page")) + + data = { + "list": book_list, + "items": page, + "page_range": paginated.get_elided_page_range( + page.number, on_each_side=2, on_ends=1 + ), + "query": query or "", + } + return TemplateResponse(request, "lists/embed-list.html", data) + + class Curate(View): """approve or discard list suggestsions""" @@ -447,3 +506,11 @@ def normalize_book_list_ordering(book_list_id, start=0, add_offset=0): if item.order != effective_order: item.order = effective_order item.save() + + +@xframe_options_exempt +def unsafe_embed_list(request, *args, **kwargs): + """allows the EmbedList view to be loaded through unsafe iframe origins""" + + embed_list_view = EmbedList.as_view() + return embed_list_view(request, *args, **kwargs) From 8ee09a2284734eed4d486d480d38fb67a31a324c Mon Sep 17 00:00:00 2001 From: Joachim Date: Sat, 4 Dec 2021 16:07:38 +0100 Subject: [PATCH 069/169] Add url to reach the view --- bookwyrm/urls.py | 5 +++++ bookwyrm/views/__init__.py | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 514bb7e6..1f62c2be 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -336,6 +336,11 @@ urlpatterns = [ ), re_path(r"^save-list/(?P\d+)/?$", views.save_list, name="list-save"), re_path(r"^unsave-list/(?P\d+)/?$", views.unsave_list, name="list-unsave"), + re_path( + r"^list/(?P\d+)/embed/(?P[0-9a-f]+)?$", + views.unsafe_embed_list, + name="embed-list", + ), # User books re_path(rf"{USER_PATH}/books/?$", views.Shelf.as_view(), name="user-shelves"), re_path( diff --git a/bookwyrm/views/__init__.py b/bookwyrm/views/__init__.py index d79de424..d363431c 100644 --- a/bookwyrm/views/__init__.py +++ b/bookwyrm/views/__init__.py @@ -76,7 +76,7 @@ from .inbox import Inbox from .interaction import Favorite, Unfavorite, Boost, Unboost from .isbn import Isbn from .list import Lists, SavedLists, List, Curate, UserLists -from .list import save_list, unsave_list, delete_list +from .list import save_list, unsave_list, delete_list, unsafe_embed_list from .notifications import Notifications from .outbox import Outbox from .reading import create_readthrough, delete_readthrough, delete_progressupdate From 2c7c3fd1c9bee871ff56e5106a2bcf9f04374094 Mon Sep 17 00:00:00 2001 From: Joachim Date: Sat, 4 Dec 2021 16:08:15 +0100 Subject: [PATCH 070/169] Create a new layout for embedded content --- bookwyrm/templates/embed-layout.html | 53 ++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 bookwyrm/templates/embed-layout.html diff --git a/bookwyrm/templates/embed-layout.html b/bookwyrm/templates/embed-layout.html new file mode 100644 index 00000000..d9b1198c --- /dev/null +++ b/bookwyrm/templates/embed-layout.html @@ -0,0 +1,53 @@ +{% load layout %} +{% load i18n %} +{% load static %} + + + + {% block title %}BookWyrm{% endblock %} - {{ site.name }} + + + + + + + + + + + +
+ + + {{ site.name }} + +
+ +
+ {% block content %} + {% endblock %} +
+ + + +{% block scripts %}{% endblock %} + + From 1b9291616b6046acc1d0dce43dfa3d949c35af81 Mon Sep 17 00:00:00 2001 From: Joachim Date: Sat, 4 Dec 2021 16:08:47 +0100 Subject: [PATCH 071/169] Add EmbedList view template --- bookwyrm/templates/lists/embed-list.html | 59 ++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 bookwyrm/templates/lists/embed-list.html diff --git a/bookwyrm/templates/lists/embed-list.html b/bookwyrm/templates/lists/embed-list.html new file mode 100644 index 00000000..54dc80ab --- /dev/null +++ b/bookwyrm/templates/lists/embed-list.html @@ -0,0 +1,59 @@ +{% extends 'embed-layout.html' %} +{% load i18n %} +{% load bookwyrm_tags %} +{% load bookwyrm_group_tags %} +{% load markdown %} + +{% block title %}{% blocktrans with list_name=list.name owner=list.user.display_name %}{{ list_name }}, a list by {{owner}}{% endblocktrans %}{% endblock title %} + +{% block content %} +
+

+ {{ list.name }} + {% include 'snippets/privacy-icons.html' with item=list %} +

+

+ {% include 'lists/created_text.html' with list=list %} + {% blocktrans with site_name=site.name %}on {{ site_name }}{% endblocktrans %} +

+ +
+ {% include 'snippets/trimmed_text.html' with full=list.description %} +
+ +
+ {% if not items.object_list.exists %} +

{% trans "This list is currently empty" %}

+ {% else %} +
    + {% for item in items %} + {% with book=item.book %} +
  1. +
    + + +
    +

    + {% include 'snippets/book_titleby.html' %} +

    +

    + {% include 'snippets/stars.html' with rating=item.book|rating:request.user %} +

    +
    + {{ book|book_description|to_markdown|default:""|safe|truncatewords_html:20 }} +
    +
    +
    +
  2. + {% endwith %} + {% endfor %} +
+ {% endif %} + {% include "snippets/pagination.html" with page=items %} +
+
+{% endblock %} From 306ea962c4700556c05e56c95e82923a93d63662 Mon Sep 17 00:00:00 2001 From: Joachim Date: Sat, 4 Dec 2021 16:17:21 +0100 Subject: [PATCH 072/169] Add embed URL component to list layout --- bookwyrm/templates/lists/list.html | 7 +++++++ bookwyrm/views/list.py | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/bookwyrm/templates/lists/list.html b/bookwyrm/templates/lists/list.html index 61e31c06..412ca470 100644 --- a/bookwyrm/templates/lists/list.html +++ b/bookwyrm/templates/lists/list.html @@ -186,6 +186,13 @@ {% endfor %} {% endif %} {% endif %} +
+

+ {% trans "Embed this list on a website" %} +

+ +
+
{% endblock %} diff --git a/bookwyrm/views/list.py b/bookwyrm/views/list.py index 89e7fa46..82c39f4a 100644 --- a/bookwyrm/views/list.py +++ b/bookwyrm/views/list.py @@ -168,6 +168,14 @@ class List(View): ][: 5 - len(suggestions)] page = paginated.get_page(request.GET.get("page")) + + embed_key = str(book_list.embed_key.hex) + embed_url = reverse("embed-list", args=[book_list.id, embed_key]) + embed_url = request.build_absolute_uri(embed_url) + + if request.GET: + embed_url = "%s?%s" % (embed_url, request.GET.urlencode()) + data = { "list": book_list, "items": page, @@ -181,6 +189,7 @@ class List(View): "sort_form": forms.SortListForm( {"direction": direction, "sort_by": sort_by} ), + "embed_url": embed_url, } return TemplateResponse(request, "lists/list.html", data) From b2a274ba41bc6f93a5f45e34a57ab323a2169e6b Mon Sep 17 00:00:00 2001 From: Joachim Date: Sat, 4 Dec 2021 16:17:33 +0100 Subject: [PATCH 073/169] Add JS code for copy text component --- bookwyrm/static/js/bookwyrm.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/bookwyrm/static/js/bookwyrm.js b/bookwyrm/static/js/bookwyrm.js index d656ed18..0816231d 100644 --- a/bookwyrm/static/js/bookwyrm.js +++ b/bookwyrm/static/js/bookwyrm.js @@ -66,6 +66,9 @@ let BookWyrm = new class { document.querySelectorAll('input[type="file"]').forEach( bookwyrm.disableIfTooLarge.bind(bookwyrm) ); + document.querySelectorAll('[data-copytext]').forEach( + bookwyrm.copyText.bind(bookwyrm) + ); }); } @@ -430,4 +433,31 @@ let BookWyrm = new class { parent.appendChild(label) parent.appendChild(input) } + + /** + * Set up a "click-to-copy" component from a textarea element + * with `data-copytext`, `data-copytext-label`, `data-copytext-success` + * attributes. + * + * @param {object} node - DOM node of the text container + * @return {undefined} + */ + + copyText(textareaEl) { + const text = textareaEl.textContent; + + const copyButtonEl = document.createElement('button'); + + copyButtonEl.textContent = textareaEl.dataset.copytextLabel; + copyButtonEl.classList.add("mt-2","button","is-small","is-fullwidth","is-primary","is-light"); + copyButtonEl.addEventListener('click', () => { + navigator.clipboard.writeText(text).then(function() { + textareaEl.classList.add('is-success'); + copyButtonEl.classList.replace('is-primary', 'is-success'); + copyButtonEl.textContent = textareaEl.dataset.copytextSuccess; + }); + }); + + textareaEl.parentNode.appendChild(copyButtonEl) + } }(); From 78a0092f922fd6a3ae5b562e190eb859701d5a63 Mon Sep 17 00:00:00 2001 From: Joachim Date: Sat, 4 Dec 2021 16:17:51 +0100 Subject: [PATCH 074/169] Translate `home page` on main layout --- bookwyrm/templates/layout.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/templates/layout.html b/bookwyrm/templates/layout.html index f2d04f96..901c417f 100644 --- a/bookwyrm/templates/layout.html +++ b/bookwyrm/templates/layout.html @@ -34,7 +34,7 @@

{% endwith %} {% endspaceless %} From b6106691ef85afe7ab15b4f1b239e676503aad9d Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 4 Dec 2021 09:57:45 -0800 Subject: [PATCH 085/169] Force dropdown menus to always visible --- bookwyrm/static/css/bookwyrm.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/static/css/bookwyrm.css b/bookwyrm/static/css/bookwyrm.css index 3d9db301..4f4d2efc 100644 --- a/bookwyrm/static/css/bookwyrm.css +++ b/bookwyrm/static/css/bookwyrm.css @@ -115,7 +115,7 @@ input[type=file]::file-selector-button:hover { color: #363636; } -details[open] .dropdown-menu { +details .dropdown-menu { display: block !important; } From 5e9e7db9356cbdecc3c302c69eeb2f6723915508 Mon Sep 17 00:00:00 2001 From: Joachim Date: Sat, 4 Dec 2021 19:08:55 +0100 Subject: [PATCH 086/169] Fix preview image text wrap length Closes #1634 --- bookwyrm/preview_images.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/bookwyrm/preview_images.py b/bookwyrm/preview_images.py index 32465d6e..164ba9e9 100644 --- a/bookwyrm/preview_images.py +++ b/bookwyrm/preview_images.py @@ -49,6 +49,25 @@ def get_font(font_name, size=28): return font +def get_wrapped_text(text, font, content_width): + """text wrap length depends on the max width of the content""" + + low = 0 + high = len(text) + + # ideal length is determined via binary search + while low < high: + mid = math.floor(low + high) + wrapped_text = textwrap.fill(text, width=mid) + width = font.getsize_multiline(wrapped_text)[0] + if width < content_width: + low = mid + else: + high = mid - 1 + + return wrapped_text + + def generate_texts_layer(texts, content_width): """Adds text for images""" font_text_zero = get_font("bold", size=20) @@ -63,7 +82,8 @@ def generate_texts_layer(texts, content_width): if "text_zero" in texts and texts["text_zero"]: # Text one (Book title) - text_zero = textwrap.fill(texts["text_zero"], width=72) + text_zero = get_wrapped_text(texts["text_zero"], font_text_zero, content_width) + text_layer_draw.multiline_text( (0, text_y), text_zero, font=font_text_zero, fill=TEXT_COLOR ) @@ -75,7 +95,8 @@ def generate_texts_layer(texts, content_width): if "text_one" in texts and texts["text_one"]: # Text one (Book title) - text_one = textwrap.fill(texts["text_one"], width=28) + text_one = get_wrapped_text(texts["text_one"], font_text_one, content_width) + text_layer_draw.multiline_text( (0, text_y), text_one, font=font_text_one, fill=TEXT_COLOR ) @@ -87,7 +108,8 @@ def generate_texts_layer(texts, content_width): if "text_two" in texts and texts["text_two"]: # Text one (Book subtitle) - text_two = textwrap.fill(texts["text_two"], width=36) + text_two = get_wrapped_text(texts["text_two"], font_text_two, content_width) + text_layer_draw.multiline_text( (0, text_y), text_two, font=font_text_two, fill=TEXT_COLOR ) @@ -99,7 +121,10 @@ def generate_texts_layer(texts, content_width): if "text_three" in texts and texts["text_three"]: # Text three (Book authors) - text_three = textwrap.fill(texts["text_three"], width=36) + text_three = get_wrapped_text( + texts["text_three"], font_text_three, content_width + ) + text_layer_draw.multiline_text( (0, text_y), text_three, font=font_text_three, fill=TEXT_COLOR ) From c813ce1144d31a90d16f556428578f8e63c3f628 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 4 Dec 2021 10:41:42 -0800 Subject: [PATCH 087/169] Creates consistent styling for details element --- bookwyrm/static/css/bookwyrm.css | 13 +++++ bookwyrm/templates/feed/feed.html | 83 ++++++++++++++++--------------- 2 files changed, 57 insertions(+), 39 deletions(-) diff --git a/bookwyrm/static/css/bookwyrm.css b/bookwyrm/static/css/bookwyrm.css index 0d280fd5..8f6167b7 100644 --- a/bookwyrm/static/css/bookwyrm.css +++ b/bookwyrm/static/css/bookwyrm.css @@ -115,6 +115,19 @@ input[type=file]::file-selector-button:hover { color: #363636; } +summary::marker { + content: none; +} +.detail-pinned-button summary { + position: absolute; + right: 0; +} +.detail-pinned-button form { + float: left; + width: -webkit-fill-available; + margin-top: 1em; +} + /** Shelving ******************************************************************************/ diff --git a/bookwyrm/templates/feed/feed.html b/bookwyrm/templates/feed/feed.html index 1a2488af..eda4c0c0 100644 --- a/bookwyrm/templates/feed/feed.html +++ b/bookwyrm/templates/feed/feed.html @@ -6,49 +6,54 @@

{{ tab.name }}

-
- -
+
+
+
+ +
+
-{# feed settings #} -
- - - {{ _("Feed settings") }} - - {% if settings_saved %} - {{ _("Saved!") }} - {% endif %} - - - {% csrf_token %} + {# feed settings #} +
+ + + + {{ _("Feed settings") }} + + {% if settings_saved %} + {{ _("Saved!") }} + {% endif %} + + + {% csrf_token %} -
-
-
- - {% for name, value in feed_status_types_options %} - - {% endfor %} +
+
+
+ + {% for name, value in feed_status_types_options %} + + {% endfor %} +
-
-
- -
- -
+
+ +
+ +
+
{# announcements and system messages #} {% if not activities.number > 1 %} From 5b690532fadea83fcb5ddfcb0db4ee75f439f963 Mon Sep 17 00:00:00 2001 From: Joachim Date: Sat, 4 Dec 2021 19:59:45 +0100 Subject: [PATCH 088/169] Add an AttributeError exception for CI tests --- bookwyrm/preview_images.py | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/bookwyrm/preview_images.py b/bookwyrm/preview_images.py index 164ba9e9..a97ae2d5 100644 --- a/bookwyrm/preview_images.py +++ b/bookwyrm/preview_images.py @@ -55,15 +55,18 @@ def get_wrapped_text(text, font, content_width): low = 0 high = len(text) - # ideal length is determined via binary search - while low < high: - mid = math.floor(low + high) - wrapped_text = textwrap.fill(text, width=mid) - width = font.getsize_multiline(wrapped_text)[0] - if width < content_width: - low = mid - else: - high = mid - 1 + try: + # ideal length is determined via binary search + while low < high: + mid = math.floor(low + high) + wrapped_text = textwrap.fill(text, width=mid) + width = font.getsize_multiline(wrapped_text)[0] + if width < content_width: + low = mid + else: + high = mid - 1 + except AttributeError: + wrapped_text = text return wrapped_text From 56609bbc2bf0d3b5f13b488815421213fda1a5ca Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 4 Dec 2021 11:18:41 -0800 Subject: [PATCH 089/169] Css linting --- bookwyrm/static/css/bookwyrm.css | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bookwyrm/static/css/bookwyrm.css b/bookwyrm/static/css/bookwyrm.css index 8f6167b7..ca164244 100644 --- a/bookwyrm/static/css/bookwyrm.css +++ b/bookwyrm/static/css/bookwyrm.css @@ -118,10 +118,12 @@ input[type=file]::file-selector-button:hover { summary::marker { content: none; } + .detail-pinned-button summary { position: absolute; right: 0; } + .detail-pinned-button form { float: left; width: -webkit-fill-available; From f98fe0348a041c1b230e02a1acee4421211808dc Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 4 Dec 2021 11:45:02 -0800 Subject: [PATCH 090/169] Fixes merge error --- bookwyrm/static/css/bookwyrm.css | 1 + 1 file changed, 1 insertion(+) diff --git a/bookwyrm/static/css/bookwyrm.css b/bookwyrm/static/css/bookwyrm.css index 145bf439..7e2b24bc 100644 --- a/bookwyrm/static/css/bookwyrm.css +++ b/bookwyrm/static/css/bookwyrm.css @@ -117,6 +117,7 @@ input[type=file]::file-selector-button:hover { details .dropdown-menu { display: block !important; +} summary::marker { content: none; From 7050013144eb410f098fa0b627c3d34285393663 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 4 Dec 2021 11:51:57 -0800 Subject: [PATCH 091/169] Close menus when the rest of the page is clicked Ce-authored-by: Joachim --- bookwyrm/static/css/bookwyrm.css | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/bookwyrm/static/css/bookwyrm.css b/bookwyrm/static/css/bookwyrm.css index 7e2b24bc..0e812e2a 100644 --- a/bookwyrm/static/css/bookwyrm.css +++ b/bookwyrm/static/css/bookwyrm.css @@ -119,6 +119,15 @@ details .dropdown-menu { display: block !important; } +details.dropdown[open] summary.dropdown-trigger::before { + content: ""; + position: fixed; + top: 0; + bottom: 0; + left: 0; + right: 0; +} + summary::marker { content: none; } From ba34e11fb01e7253dcf7baf0173dbcdbed5ddf81 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 4 Dec 2021 12:11:29 -0800 Subject: [PATCH 092/169] Fixes auto-closing menu --- bookwyrm/static/js/status_cache.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bookwyrm/static/js/status_cache.js b/bookwyrm/static/js/status_cache.js index 418b7dee..dbc238c4 100644 --- a/bookwyrm/static/js/status_cache.js +++ b/bookwyrm/static/js/status_cache.js @@ -210,10 +210,10 @@ let StatusCache = new class { .forEach(item => BookWyrm.addRemoveClass(item, "is-hidden", true)); // Close menu - let menu = button.querySelector(".dropdown-trigger[aria-expanded=true]"); + let menu = button.querySelector("details[open]"); if (menu) { - menu.click(); + menu.removeAttribute("open"); } } From 597d537461acdf0b03cbf7ce3e989e94c1306f59 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Sat, 4 Dec 2021 13:43:01 -0800 Subject: [PATCH 093/169] Display "saved!" indicator in status form --- bookwyrm/templates/feed/feed.html | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bookwyrm/templates/feed/feed.html b/bookwyrm/templates/feed/feed.html index eda4c0c0..010ba0f9 100644 --- a/bookwyrm/templates/feed/feed.html +++ b/bookwyrm/templates/feed/feed.html @@ -26,9 +26,6 @@ {{ _("Feed settings") }} - {% if settings_saved %} - {{ _("Saved!") }} - {% endif %}
{% csrf_token %} @@ -36,7 +33,12 @@
- + + + {% if settings_saved %} + {{ _("Saved!") }} + {% endif %} + {% for name, value in feed_status_types_options %}