Compare commits

...

25 commits

Author SHA1 Message Date
Matt Katz bae28ac425
Merge 98724dfa47 into 70f803a1f6 2024-04-16 00:48:31 -04:00
mattkatz 98724dfa47 use display_name to avoid name rendering as None 2024-04-14 05:00:38 -04:00
mattkatz 74e2103e3a handle cases where edition has no author 2024-04-14 04:58:03 -04:00
mattkatz a0d15ccec0 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.
2024-04-14 04:55:45 -04:00
mattkatz 8dc412c4cb remove pure_name since it only applies to statuses 2024-04-14 04:48:28 -04:00
Adeodato Simó 5340ed35de
Drop default filter in favor of per-metadata item conditionals 2024-03-19 01:08:29 -03:00
Adeodato Simó 1e14d635bc
Missing brackets and correct blocktrans usage 2024-03-19 01:07:52 -03:00
mattkatz 09d857e6fb 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
2024-03-18 22:33:47 -04:00
mattkatz 1d8bd2be89 add translation usage 2024-03-18 21:38:55 -04:00
Matt Katz cd29b44807
improve shelf rss description
Co-authored-by: Adeodato Simó <73768+dato@users.noreply.github.com>
2024-03-18 21:33:30 -04:00
Matt Katz 6976cb4876
add user name to shelf rss feed title
Co-authored-by: Adeodato Simó <73768+dato@users.noreply.github.com>
2024-03-18 21:29:16 -04:00
Matt Katz 63d6486fc9
Merge branch 'main' into rss-for-shelves 2024-03-18 21:26:05 -04:00
mattkatz 5b8e083bcd use privacy__in to respect shelf privacy settings 2024-03-12 22:10:18 -04:00
mattkatz e3ca543f8e Remove extraneous function
getting context data no longer seems needed, if it ever was.
2024-03-12 22:06:31 -04:00
Matt Katz 975c3ba9aa
Correct docstring on rss feed
Co-authored-by: Adeodato Simó <73768+dato@users.noreply.github.com>
2024-03-12 21:57:28 -04:00
Matt Katz a2e41faf69
/rss shouldn't be optional in the rss route
Co-authored-by: Adeodato Simó <73768+dato@users.noreply.github.com>
2024-03-12 21:56:14 -04:00
Matt Katz 3754af7bc5
/rss shouldn't be optional in the rss route
Co-authored-by: Adeodato Simó <73768+dato@users.noreply.github.com>
2024-03-12 21:55:49 -04:00
Matt Katz 7b388ae972
Sort RSS Feed by Shelved date
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>
2024-03-12 21:43:08 -04:00
Jascha Ezra Urbach 7a25869e3f
Merge branch 'main' into rss-for-shelves 2024-01-20 12:29:02 +01:00
mattkatz d3d5f1bec6 remove duplicate sitesettings error 2023-11-04 21:43:33 -04:00
mattkatz 339298cb3d Mock activitystreams add_book_statuses_task 2023-11-04 21:41:29 -04:00
mattkatz f665aea665 fixed method without docstring 2023-10-01 06:05:54 -04:00
mattkatz c142e383c9 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.
2023-10-01 06:04:52 -04:00
mattkatz 4ae0dbde92 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.
2023-09-28 21:50:09 -04:00
mattkatz 856737e19c working rss feed for shelves 2023-09-28 21:49:05 -04:00
4 changed files with 104 additions and 0 deletions

View file

@ -0,0 +1,11 @@
{% load i18n %}
{% blocktrans trimmed with book_title=obj.title book_author=obj.author_text %}
{{ book_title }}{% if book_author %} by {{ book_author }}{% endif %}
{% endblocktrans %}
{{obj.description|default:""}}
{% 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 %}

View file

@ -132,3 +132,27 @@ 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"
), 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
)
# put the shelf on the book
models.ShelfBook.objects.create(
book=self.book,
shelf=shelf,
user=self.local_user,
)
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)

View file

@ -577,11 +577,21 @@ urlpatterns = [
views.Shelf.as_view(),
name="shelf",
),
re_path(
rf"^{USER_PATH}/(shelf|books)/(?P<shelf_identifier>[\w-]+)/rss/?$",
views.rss_feed.RssShelfFeed(),
name="shelf-rss",
),
re_path(
rf"^{LOCAL_USER_PATH}/(books|shelf)/(?P<shelf_identifier>[\w-]+)(.json)?/?$",
views.Shelf.as_view(),
name="shelf",
),
re_path(
rf"^{LOCAL_USER_PATH}/(books|shelf)/(?P<shelf_identifier>[\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<shelf_id>\d+)/?$", views.delete_shelf),
re_path(r"^shelve/?$", views.shelve),

View file

@ -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,61 @@ 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"""
authors = item.authors
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()
def get_object(
self, request, shelf_identifier, username
): # pylint: disable=arguments-differ
"""the shelf that gets serialized"""
user = get_user_from_username(request.user, username)
# always get privacy, don't support rss over anything private
# 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
def link(self, obj):
"""link to the shelf"""
return obj.local_path
def title(self, obj):
"""title of the rss feed entry"""
return _(f"{obj.user.display_name}s {obj.name} shelf")
def items(self, obj):
"""the user's activity feed"""
return obj.books.order_by("-shelfbook__shelved_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):
"""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.display_name}s {obj.name} shelf: {desc}")
return _(f"Books added to {obj.user.name}s {obj.name} shelf")