From 856737e19c45af1225e17e8acf4415bd71114411 Mon Sep 17 00:00:00 2001 From: mattkatz Date: Thu, 28 Sep 2023 21:49:05 -0400 Subject: [PATCH 01/22] working rss feed for shelves --- bookwyrm/templates/rss/edition.html | 4 ++ bookwyrm/urls.py | 10 +++++ bookwyrm/views/rss_feed.py | 63 +++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 bookwyrm/templates/rss/edition.html diff --git a/bookwyrm/templates/rss/edition.html b/bookwyrm/templates/rss/edition.html new file mode 100644 index 000000000..4b964298d --- /dev/null +++ b/bookwyrm/templates/rss/edition.html @@ -0,0 +1,4 @@ +{{obj.title}} by {{obj.author_text}} +{{obj.description|default:""}} +{% if obj.description %}ISBN: {{item.isbn_10|default:""}}{% endif %} +{% if obj.description %}ISBN13: {{item.isbn_13}}{% endif %} diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 05972ee73..5c137b662 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -540,11 +540,21 @@ urlpatterns = [ views.Shelf.as_view(), name="shelf", ), + re_path( + rf"^{USER_PATH}/(shelf|books)/(?P[\w-]+)(/rss)?/?$", + views.rss_feed.RssShelfFeed(), + name="shelf-rss", + ), re_path( rf"^{LOCAL_USER_PATH}/(books|shelf)/(?P[\w-]+)(.json)?/?$", views.Shelf.as_view(), name="shelf", ), + re_path( + rf"^{LOCAL_USER_PATH}/(books|shelf)/(?P[\w-]+)(/rss)?/?$", + views.rss_feed.RssShelfFeed(), + name="shelf-rss", + ), re_path(r"^create-shelf/?$", views.create_shelf, name="shelf-create"), re_path(r"^delete-shelf/(?P\d+)/?$", views.delete_shelf), re_path(r"^shelve/?$", views.shelve), diff --git a/bookwyrm/views/rss_feed.py b/bookwyrm/views/rss_feed.py index ae1f6ae2d..833bf5ada 100644 --- a/bookwyrm/views/rss_feed.py +++ b/bookwyrm/views/rss_feed.py @@ -3,6 +3,7 @@ from django.contrib.syndication.views import Feed from django.template.loader import get_template from django.utils.translation import gettext_lazy as _ +from django.shortcuts import get_object_or_404 from ..models import Review, Quotation, Comment from .helpers import get_user_from_username @@ -177,3 +178,65 @@ class RssCommentsOnlyFeed(Feed): def item_pubdate(self, item): """publication date of the item""" return item.published_date + + +class RssShelfFeed(Feed): + """serialize a shelf activity in rss""" + + description_template = "rss/edition.html" + + def item_title(self, item): + """render the item title""" + if hasattr(item, "pure_name") and item.pure_name: + return item.pure_name + authors = item.authors + authors.display_name = f"{item.author_text}:" + template = get_template("rss/title.html") + return template.render({"user": authors, "item_title": item.title}).strip() + + def get_object( + self, request, shelf_identifier, username + ): # pylint: disable=arguments-differ + """the user who's posts get serialized""" + user = get_user_from_username(request.user, username) + # always get privacy, don't support rss over anything private + # Shelf.privacy_filter(request.user).filter(user=user).all() + + # TODO: get the SHELF of the object + shelf = get_object_or_404(user.shelf_set, identifier=shelf_identifier) + shelf.raise_visible_to_user(request.user) + return shelf + + def link(self, obj): + """link to the shelf""" + return obj.local_path + + def title(self, obj): + """title of the rss feed entry""" + return _(f"Books added to {obj.name}") + + def items(self, obj): + """the user's activity feed""" + return obj.books.order_by("-published_date")[:10] + + def item_link(self, item): + """link to the status""" + return item.local_path + + def item_pubdate(self, item): + """publication date of the item""" + return item.published_date + + def description(self, obj): + # if there's a description, lets add it. Not everyone puts a description in. + desc = "" + if obj.description: + desc = f" {obj.description}" + return f"Books added to the '{obj.name}' shelf for {obj.user.name}.{desc}" + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + # TODO: gotta check that this is the SHELF user! + context["user"] = kwargs["request"].user + context["shelf"] = kwargs["obj"] + return context From 4ae0dbde92389badc8f6032fa6b1f6efc4c9b1fb Mon Sep 17 00:00:00 2001 From: mattkatz Date: Thu, 28 Sep 2023 21:50:09 -0400 Subject: [PATCH 02/22] add a failing test for rss feeds for shelves Currently can't get the test to succeed - it fails in an unrelated redis error, so pushing this so I can open a draft PR to get advice on a better test. --- bookwyrm/tests/views/test_rss_feed.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/bookwyrm/tests/views/test_rss_feed.py b/bookwyrm/tests/views/test_rss_feed.py index cfbec3360..2b643cbdd 100644 --- a/bookwyrm/tests/views/test_rss_feed.py +++ b/bookwyrm/tests/views/test_rss_feed.py @@ -127,3 +127,26 @@ class RssFeedView(TestCase): self.assertEqual(result.status_code, 200) self.assertIn(b"a sickening sense", result.content) + + def test_rss_shelf(self, *_): + """load the rss feed of a shelf""" + with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"): + # make the shelf + self.shelf = models.Shelf.objects.create( + name="Test Shelf", identifier="test-shelf", user=self.local_user + ) + # put the shelf on the book + models.ShelfBook.objects.create( + book=self.book, + shelf=self.shelf, + user=self.local_user, + ) + models.SiteSettings.objects.create() + view = rss_feed.RssShelfFeed() + request = self.factory.get("/user/books/test-shelf/rss") + request.user = self.local_user + result = view( + request, username=self.local_user.username, shelf_identifier="test-shelf" + ) + self.assertEqual(result.status_code, 200) + self.assertIn(b"Example Edition", result.content) From c142e383c9db11c938b10293a5538c2c14dd1e08 Mon Sep 17 00:00:00 2001 From: mattkatz Date: Sun, 1 Oct 2023 06:04:52 -0400 Subject: [PATCH 03/22] fix linting issue didn't really need to add the shelf to self and the linter doesn't like seeing it outside of an init or setup. --- bookwyrm/tests/views/test_rss_feed.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bookwyrm/tests/views/test_rss_feed.py b/bookwyrm/tests/views/test_rss_feed.py index 2b643cbdd..a4e473637 100644 --- a/bookwyrm/tests/views/test_rss_feed.py +++ b/bookwyrm/tests/views/test_rss_feed.py @@ -132,13 +132,13 @@ class RssFeedView(TestCase): """load the rss feed of a shelf""" with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"): # make the shelf - self.shelf = models.Shelf.objects.create( + shelf = models.Shelf.objects.create( name="Test Shelf", identifier="test-shelf", user=self.local_user ) # put the shelf on the book models.ShelfBook.objects.create( book=self.book, - shelf=self.shelf, + shelf=shelf, user=self.local_user, ) models.SiteSettings.objects.create() From f665aea665f619a1481c079e75fb4b5789c98863 Mon Sep 17 00:00:00 2001 From: mattkatz Date: Sun, 1 Oct 2023 06:05:54 -0400 Subject: [PATCH 04/22] fixed method without docstring --- bookwyrm/views/rss_feed.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bookwyrm/views/rss_feed.py b/bookwyrm/views/rss_feed.py index 833bf5ada..f6d1ce241 100644 --- a/bookwyrm/views/rss_feed.py +++ b/bookwyrm/views/rss_feed.py @@ -228,6 +228,7 @@ class RssShelfFeed(Feed): return item.published_date def description(self, obj): + """description of the shelf including the shelf name and user.""" # if there's a description, lets add it. Not everyone puts a description in. desc = "" if obj.description: From 339298cb3d319f561fe8f6ea10f5f36c8f73ab3b Mon Sep 17 00:00:00 2001 From: mattkatz Date: Sat, 4 Nov 2023 21:41:29 -0400 Subject: [PATCH 05/22] Mock activitystreams add_book_statuses_task --- bookwyrm/tests/views/test_rss_feed.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/bookwyrm/tests/views/test_rss_feed.py b/bookwyrm/tests/views/test_rss_feed.py index a4e473637..714445461 100644 --- a/bookwyrm/tests/views/test_rss_feed.py +++ b/bookwyrm/tests/views/test_rss_feed.py @@ -130,7 +130,9 @@ class RssFeedView(TestCase): def test_rss_shelf(self, *_): """load the rss feed of a shelf""" - with patch("bookwyrm.models.activitypub_mixin.broadcast_task.apply_async"): + with patch( + "bookwyrm.models.activitypub_mixin.broadcast_task.apply_async" + ), patch("bookwyrm.activitystreams.add_book_statuses_task.delay"): # make the shelf shelf = models.Shelf.objects.create( name="Test Shelf", identifier="test-shelf", user=self.local_user From d3d5f1bec678c8443ba6b2b2838fe5d8b6531683 Mon Sep 17 00:00:00 2001 From: mattkatz Date: Sat, 4 Nov 2023 21:43:33 -0400 Subject: [PATCH 06/22] remove duplicate sitesettings error --- bookwyrm/tests/views/test_rss_feed.py | 1 - 1 file changed, 1 deletion(-) diff --git a/bookwyrm/tests/views/test_rss_feed.py b/bookwyrm/tests/views/test_rss_feed.py index 714445461..2e10f5377 100644 --- a/bookwyrm/tests/views/test_rss_feed.py +++ b/bookwyrm/tests/views/test_rss_feed.py @@ -143,7 +143,6 @@ class RssFeedView(TestCase): shelf=shelf, user=self.local_user, ) - models.SiteSettings.objects.create() view = rss_feed.RssShelfFeed() request = self.factory.get("/user/books/test-shelf/rss") request.user = self.local_user From 7b388ae972b3a6add309e4b15a2e23ad00665633 Mon Sep 17 00:00:00 2001 From: Matt Katz Date: Tue, 12 Mar 2024 21:43:08 -0400 Subject: [PATCH 07/22] Sort RSS Feed by Shelved date MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will make sure that users see books as they are shelved, which is what would be expected. Co-authored-by: Adeodato Simó <73768+dato@users.noreply.github.com> --- bookwyrm/views/rss_feed.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/views/rss_feed.py b/bookwyrm/views/rss_feed.py index f6d1ce241..731d6f03e 100644 --- a/bookwyrm/views/rss_feed.py +++ b/bookwyrm/views/rss_feed.py @@ -217,7 +217,7 @@ class RssShelfFeed(Feed): def items(self, obj): """the user's activity feed""" - return obj.books.order_by("-published_date")[:10] + return obj.books.order_by("-shelfbook__shelved_date")[:10] def item_link(self, item): """link to the status""" From 3754af7bc577091525c035f6c606a395d25e4939 Mon Sep 17 00:00:00 2001 From: Matt Katz Date: Tue, 12 Mar 2024 21:55:49 -0400 Subject: [PATCH 08/22] /rss shouldn't be optional in the rss route MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Adeodato Simó <73768+dato@users.noreply.github.com> --- bookwyrm/urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index fa347150e..5f1f3fda4 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -573,7 +573,7 @@ urlpatterns = [ name="shelf", ), re_path( - rf"^{USER_PATH}/(shelf|books)/(?P[\w-]+)(/rss)?/?$", + rf"^{USER_PATH}/(shelf|books)/(?P[\w-]+)/rss/?$", views.rss_feed.RssShelfFeed(), name="shelf-rss", ), From a2e41faf692ba466fa2e81776649795be5b76ae8 Mon Sep 17 00:00:00 2001 From: Matt Katz Date: Tue, 12 Mar 2024 21:56:14 -0400 Subject: [PATCH 09/22] /rss shouldn't be optional in the rss route MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Adeodato Simó <73768+dato@users.noreply.github.com> --- bookwyrm/urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/urls.py b/bookwyrm/urls.py index 5f1f3fda4..b1bfa6fec 100644 --- a/bookwyrm/urls.py +++ b/bookwyrm/urls.py @@ -583,7 +583,7 @@ urlpatterns = [ name="shelf", ), re_path( - rf"^{LOCAL_USER_PATH}/(books|shelf)/(?P[\w-]+)(/rss)?/?$", + rf"^{LOCAL_USER_PATH}/(books|shelf)/(?P[\w-]+)/rss/?$", views.rss_feed.RssShelfFeed(), name="shelf-rss", ), From 975c3ba9aa55c87f9c2a33c59540f0668dbcb6eb Mon Sep 17 00:00:00 2001 From: Matt Katz Date: Tue, 12 Mar 2024 21:57:28 -0400 Subject: [PATCH 10/22] Correct docstring on rss feed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Adeodato Simó <73768+dato@users.noreply.github.com> --- bookwyrm/views/rss_feed.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/views/rss_feed.py b/bookwyrm/views/rss_feed.py index 731d6f03e..6f81ab2b3 100644 --- a/bookwyrm/views/rss_feed.py +++ b/bookwyrm/views/rss_feed.py @@ -197,7 +197,7 @@ class RssShelfFeed(Feed): def get_object( self, request, shelf_identifier, username ): # pylint: disable=arguments-differ - """the user who's posts get serialized""" + """the shelf that gets serialized""" user = get_user_from_username(request.user, username) # always get privacy, don't support rss over anything private # Shelf.privacy_filter(request.user).filter(user=user).all() From e3ca543f8e9a70fa6f63cab366bf830e0b8522fa Mon Sep 17 00:00:00 2001 From: mattkatz Date: Tue, 12 Mar 2024 22:04:48 -0400 Subject: [PATCH 11/22] Remove extraneous function getting context data no longer seems needed, if it ever was. --- bookwyrm/views/rss_feed.py | 7 ------- 1 file changed, 7 deletions(-) diff --git a/bookwyrm/views/rss_feed.py b/bookwyrm/views/rss_feed.py index 6f81ab2b3..daca6efa0 100644 --- a/bookwyrm/views/rss_feed.py +++ b/bookwyrm/views/rss_feed.py @@ -234,10 +234,3 @@ class RssShelfFeed(Feed): if obj.description: desc = f" {obj.description}" return f"Books added to the '{obj.name}' shelf for {obj.user.name}.{desc}" - - def get_context_data(self, **kwargs): - context = super().get_context_data(**kwargs) - # TODO: gotta check that this is the SHELF user! - context["user"] = kwargs["request"].user - context["shelf"] = kwargs["obj"] - return context From 5b8e083bcdcb2b1493855a60a39f6824571d41e2 Mon Sep 17 00:00:00 2001 From: mattkatz Date: Tue, 12 Mar 2024 22:10:18 -0400 Subject: [PATCH 12/22] use privacy__in to respect shelf privacy settings --- bookwyrm/views/rss_feed.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/bookwyrm/views/rss_feed.py b/bookwyrm/views/rss_feed.py index daca6efa0..cd7604b71 100644 --- a/bookwyrm/views/rss_feed.py +++ b/bookwyrm/views/rss_feed.py @@ -200,10 +200,12 @@ class RssShelfFeed(Feed): """the shelf that gets serialized""" user = get_user_from_username(request.user, username) # always get privacy, don't support rss over anything private - # Shelf.privacy_filter(request.user).filter(user=user).all() - - # TODO: get the SHELF of the object - shelf = get_object_or_404(user.shelf_set, identifier=shelf_identifier) + # get the SHELF of the object + shelf = get_object_or_404( + user.shelf_set, + identifier=shelf_identifier, + privacy__in=["public", "unlisted"], + ) shelf.raise_visible_to_user(request.user) return shelf From 6976cb487699abc7cd8dcb3d09e0846b1378ee50 Mon Sep 17 00:00:00 2001 From: Matt Katz Date: Mon, 18 Mar 2024 21:29:16 -0400 Subject: [PATCH 13/22] add user name to shelf rss feed title MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Adeodato Simó <73768+dato@users.noreply.github.com> --- bookwyrm/views/rss_feed.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/views/rss_feed.py b/bookwyrm/views/rss_feed.py index cd7604b71..de2d2f104 100644 --- a/bookwyrm/views/rss_feed.py +++ b/bookwyrm/views/rss_feed.py @@ -215,7 +215,7 @@ class RssShelfFeed(Feed): def title(self, obj): """title of the rss feed entry""" - return _(f"Books added to {obj.name}") + return _(f"{obj.user.name}’s {obj.name} shelf") def items(self, obj): """the user's activity feed""" From cd29b448071a3d4d2344f954180cc05e4b249a65 Mon Sep 17 00:00:00 2001 From: Matt Katz Date: Mon, 18 Mar 2024 21:33:30 -0400 Subject: [PATCH 14/22] improve shelf rss description MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Adeodato Simó <73768+dato@users.noreply.github.com> --- bookwyrm/views/rss_feed.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/bookwyrm/views/rss_feed.py b/bookwyrm/views/rss_feed.py index de2d2f104..5731ea91c 100644 --- a/bookwyrm/views/rss_feed.py +++ b/bookwyrm/views/rss_feed.py @@ -232,7 +232,6 @@ class RssShelfFeed(Feed): def description(self, obj): """description of the shelf including the shelf name and user.""" # if there's a description, lets add it. Not everyone puts a description in. - desc = "" - if obj.description: - desc = f" {obj.description}" - return f"Books added to the '{obj.name}' shelf for {obj.user.name}.{desc}" + if desc := obj.description: + return _(f"{obj.user.name}’s {obj.name} shelf: {desc}" + return _(f"Books added to {obj.user.name}’s {obj.name} shelf" From 1d8bd2be892dde3079915a6397e28edeba1c545f Mon Sep 17 00:00:00 2001 From: mattkatz Date: Mon, 18 Mar 2024 21:37:47 -0400 Subject: [PATCH 15/22] add translation usage --- bookwyrm/templates/rss/edition.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/templates/rss/edition.html b/bookwyrm/templates/rss/edition.html index 4b964298d..edf408340 100644 --- a/bookwyrm/templates/rss/edition.html +++ b/bookwyrm/templates/rss/edition.html @@ -1,4 +1,4 @@ -{{obj.title}} by {{obj.author_text}} +{% blocktrans %}{{{obj.title}} by {{obj.author_text}}{% endblocktrans %} {{obj.description|default:""}} {% if obj.description %}ISBN: {{item.isbn_10|default:""}}{% endif %} {% if obj.description %}ISBN13: {{item.isbn_13}}{% endif %} From 09d857e6fbf731283d4568f1ac4354e0120722ca Mon Sep 17 00:00:00 2001 From: mattkatz Date: Mon, 18 Mar 2024 22:33:47 -0400 Subject: [PATCH 16/22] support same identifiers as book page in rss in book_identifiers.html template we support multiple identifiers in order. This commit adopts the same logic and order --- bookwyrm/templates/rss/edition.html | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bookwyrm/templates/rss/edition.html b/bookwyrm/templates/rss/edition.html index edf408340..f3bfe8c26 100644 --- a/bookwyrm/templates/rss/edition.html +++ b/bookwyrm/templates/rss/edition.html @@ -1,4 +1,8 @@ {% blocktrans %}{{{obj.title}} by {{obj.author_text}}{% endblocktrans %} {{obj.description|default:""}} -{% if obj.description %}ISBN: {{item.isbn_10|default:""}}{% endif %} -{% if obj.description %}ISBN13: {{item.isbn_13}}{% endif %} +{% if obj.description %}{% trans "ISBN13:" %} {{item.isbn_13|default: ""}}{% endif %} +{% if obj.description %}{% trans "OCLC Number:" %} {{item.oclc_number|default: ""}}{% endif %} +{% if obj.description %}{% trans "ASIN:" %} {{item.asin|default: ""}}{% endif %} +{% if obj.description %}{% trans "Audible ASIN:" %} {{item.aasin|default: ""}}{% endif %} +{% if obj.description %}{% trans "ISFDB ID:" %} {{item.isfdb|default: ""}}{% endif %} +{% if obj.description %}{% trans "Goodreads:" %} {{item.goodreads_key|default: ""}}{% endif %} From 1e14d635bceee74dce1084075f9cf6f10aa52e40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adeodato=20Sim=C3=B3?= <73768+dato@users.noreply.github.com> Date: Tue, 19 Mar 2024 01:07:52 -0300 Subject: [PATCH 17/22] Missing brackets and correct blocktrans usage --- bookwyrm/templates/rss/edition.html | 5 ++++- bookwyrm/views/rss_feed.py | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/bookwyrm/templates/rss/edition.html b/bookwyrm/templates/rss/edition.html index f3bfe8c26..a8036f4bb 100644 --- a/bookwyrm/templates/rss/edition.html +++ b/bookwyrm/templates/rss/edition.html @@ -1,4 +1,7 @@ -{% blocktrans %}{{{obj.title}} by {{obj.author_text}}{% endblocktrans %} +{% load i18n %} +{% blocktrans trimmed with book_title=obj.title book_author=obj.author_text %} + ‘{{ book_title }}’ by {{ book_author }} +{% endblocktrans %} {{obj.description|default:""}} {% if obj.description %}{% trans "ISBN13:" %} {{item.isbn_13|default: ""}}{% endif %} {% if obj.description %}{% trans "OCLC Number:" %} {{item.oclc_number|default: ""}}{% endif %} diff --git a/bookwyrm/views/rss_feed.py b/bookwyrm/views/rss_feed.py index 5731ea91c..31523a3d6 100644 --- a/bookwyrm/views/rss_feed.py +++ b/bookwyrm/views/rss_feed.py @@ -233,5 +233,5 @@ class RssShelfFeed(Feed): """description of the shelf including the shelf name and user.""" # if there's a description, lets add it. Not everyone puts a description in. if desc := obj.description: - return _(f"{obj.user.name}’s {obj.name} shelf: {desc}" - return _(f"Books added to {obj.user.name}’s {obj.name} shelf" + return _(f"{obj.user.name}’s {obj.name} shelf: {desc}") + return _(f"Books added to {obj.user.name}’s {obj.name} shelf") From 5340ed35de6718e72bd8586f3857ea84105e69b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adeodato=20Sim=C3=B3?= <73768+dato@users.noreply.github.com> Date: Tue, 19 Mar 2024 01:08:29 -0300 Subject: [PATCH 18/22] Drop `default` filter in favor of per-metadata item conditionals --- bookwyrm/templates/rss/edition.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bookwyrm/templates/rss/edition.html b/bookwyrm/templates/rss/edition.html index a8036f4bb..d7a783eae 100644 --- a/bookwyrm/templates/rss/edition.html +++ b/bookwyrm/templates/rss/edition.html @@ -3,9 +3,9 @@ ‘{{ book_title }}’ by {{ book_author }} {% endblocktrans %} {{obj.description|default:""}} -{% if obj.description %}{% trans "ISBN13:" %} {{item.isbn_13|default: ""}}{% endif %} -{% if obj.description %}{% trans "OCLC Number:" %} {{item.oclc_number|default: ""}}{% endif %} -{% if obj.description %}{% trans "ASIN:" %} {{item.asin|default: ""}}{% endif %} -{% if obj.description %}{% trans "Audible ASIN:" %} {{item.aasin|default: ""}}{% endif %} -{% if obj.description %}{% trans "ISFDB ID:" %} {{item.isfdb|default: ""}}{% endif %} -{% if obj.description %}{% trans "Goodreads:" %} {{item.goodreads_key|default: ""}}{% endif %} +{% if obj.isbn_13 %}{% trans "ISBN 13:" %} {{ obj.isbn_13 }}{% endif %} +{% if obj.oclc_number %}{% trans "OCLC Number:" %} {{ obj.oclc_number }}{% endif %} +{% if obj.asin %}{% trans "ASIN:" %} {{ obj.asin }}{% endif %} +{% if obj.aasin %}{% trans "Audible ASIN:" %} {{ obj.aasin }}{% endif %} +{% if obj.isfdb %}{% trans "ISFDB ID:" %} {{ obj.isfdb }}{% endif %} +{% if obj.goodreads_key %}{% trans "Goodreads:" %} {{ obj.goodreads_key }}{% endif %} From 8dc412c4cbbb3596b1bb6c59d11e6c191050cbe4 Mon Sep 17 00:00:00 2001 From: mattkatz Date: Sun, 14 Apr 2024 04:48:28 -0400 Subject: [PATCH 19/22] remove pure_name since it only applies to statuses --- bookwyrm/views/rss_feed.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/bookwyrm/views/rss_feed.py b/bookwyrm/views/rss_feed.py index 31523a3d6..b1487c9d5 100644 --- a/bookwyrm/views/rss_feed.py +++ b/bookwyrm/views/rss_feed.py @@ -187,8 +187,6 @@ class RssShelfFeed(Feed): def item_title(self, item): """render the item title""" - if hasattr(item, "pure_name") and item.pure_name: - return item.pure_name authors = item.authors authors.display_name = f"{item.author_text}:" template = get_template("rss/title.html") From a0d15ccec0608555dcdb03c29bd18d60d5869948 Mon Sep 17 00:00:00 2001 From: mattkatz Date: Sun, 14 Apr 2024 04:55:45 -0400 Subject: [PATCH 20/22] Don't show a colon if there is no author_text If there is no author for a book, render just the title of the book. --- bookwyrm/views/rss_feed.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bookwyrm/views/rss_feed.py b/bookwyrm/views/rss_feed.py index b1487c9d5..e5be10b1c 100644 --- a/bookwyrm/views/rss_feed.py +++ b/bookwyrm/views/rss_feed.py @@ -188,7 +188,10 @@ class RssShelfFeed(Feed): def item_title(self, item): """render the item title""" authors = item.authors - authors.display_name = f"{item.author_text}:" + if item.author_text: + authors.display_name = f"{item.author_text}:" + else: + authors.description = "" template = get_template("rss/title.html") return template.render({"user": authors, "item_title": item.title}).strip() From 74e2103e3a80b6b835959bef422ddaea68dce98b Mon Sep 17 00:00:00 2001 From: mattkatz Date: Sun, 14 Apr 2024 04:58:03 -0400 Subject: [PATCH 21/22] handle cases where edition has no author --- bookwyrm/templates/rss/edition.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bookwyrm/templates/rss/edition.html b/bookwyrm/templates/rss/edition.html index d7a783eae..54496bbe4 100644 --- a/bookwyrm/templates/rss/edition.html +++ b/bookwyrm/templates/rss/edition.html @@ -1,6 +1,6 @@ {% load i18n %} {% blocktrans trimmed with book_title=obj.title book_author=obj.author_text %} - ‘{{ book_title }}’ by {{ book_author }} +‘{{ book_title }}’{% if book_author %} by {{ book_author }}{% endif %} {% endblocktrans %} {{obj.description|default:""}} {% if obj.isbn_13 %}{% trans "ISBN 13:" %} {{ obj.isbn_13 }}{% endif %} From 98724dfa474089aa3d4a402889199cc023bf183d Mon Sep 17 00:00:00 2001 From: mattkatz Date: Sun, 14 Apr 2024 04:59:10 -0400 Subject: [PATCH 22/22] use display_name to avoid name rendering as None --- bookwyrm/views/rss_feed.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bookwyrm/views/rss_feed.py b/bookwyrm/views/rss_feed.py index e5be10b1c..28da6b325 100644 --- a/bookwyrm/views/rss_feed.py +++ b/bookwyrm/views/rss_feed.py @@ -216,7 +216,7 @@ class RssShelfFeed(Feed): def title(self, obj): """title of the rss feed entry""" - return _(f"{obj.user.name}’s {obj.name} shelf") + return _(f"{obj.user.display_name}’s {obj.name} shelf") def items(self, obj): """the user's activity feed""" @@ -234,5 +234,5 @@ class RssShelfFeed(Feed): """description of the shelf including the shelf name and user.""" # if there's a description, lets add it. Not everyone puts a description in. if desc := obj.description: - return _(f"{obj.user.name}’s {obj.name} shelf: {desc}") + return _(f"{obj.user.display_name}’s {obj.name} shelf: {desc}") return _(f"Books added to {obj.user.name}’s {obj.name} shelf")