diff --git a/bookwyrm/templates/author/author.html b/bookwyrm/templates/author/author.html index d342da47c..56e9ce548 100644 --- a/bookwyrm/templates/author/author.html +++ b/bookwyrm/templates/author/author.html @@ -1,6 +1,6 @@ {% extends 'layout.html' %} {% load i18n %} -{% load bookwyrm_tags %} +{% load markdown %} {% load humanize %} {% block title %}{{ author.name }}{% endblock %} @@ -66,7 +66,7 @@ {% endif %}
{{ site.registration_closed_text | safe}}
+{{ site.registration_closed_text|safe}}
{% if site.allow_invite_requests %} {% if request_received %} @@ -64,7 +64,7 @@ {% for error in request_form.email.errors %} -{{ error | escape }}
+{{ error|escape }}
{% endfor %} @@ -80,7 +80,7 @@ {% include 'user/user_preview.html' with user=request.user %} {% if request.user.summary %}{{ item.fail_reason }}. @@ -90,8 +89,8 @@
Line {{ item.index }}: - {{ item.data|dict_key:'Title' }} by - {{ item.data|dict_key:'Author' }} + {{ item.data.Title }} by + {{ item.data.Author }}
{{ item.fail_reason }}. @@ -130,10 +129,10 @@ {% endif %}
- {{ pending_count }} book{{ pending_count | pluralize }} awaiting your approval + {{ pending_count }} book{{ pending_count|pluralize }} awaiting your approval
hi
") - result = bookwyrm_tags.get_markdown("") + result = markdown.get_markdown("") self.assertEqual(result, "hi
") def test_get_mentions(self, _): """list of people mentioned""" status = models.Status.objects.create(content="hi", user=self.remote_user) - result = bookwyrm_tags.get_mentions(status, self.user) + result = status_display.get_mentions(status, self.user) self.assertEqual(result, "@rat@example.com ") - def test_get_status_preview_name(self, _): - """status context string""" - with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): - status = models.Status.objects.create(content="hi", user=self.user) - result = bookwyrm_tags.get_status_preview_name(status) - self.assertEqual(result, "status") - - status = models.Review.objects.create( - content="hi", user=self.user, book=self.book - ) - result = bookwyrm_tags.get_status_preview_name(status) - self.assertEqual(result, "review of Test Book") - - status = models.Comment.objects.create( - content="hi", user=self.user, book=self.book - ) - result = bookwyrm_tags.get_status_preview_name(status) - self.assertEqual(result, "comment on Test Book") - - status = models.Quotation.objects.create( - content="hi", user=self.user, book=self.book - ) - result = bookwyrm_tags.get_status_preview_name(status) - self.assertEqual(result, "quotation from Test Book") - def test_related_status(self, _): """gets the subclass model for a notification status""" with patch("bookwyrm.models.activitypub_mixin.broadcast_task.delay"): diff --git a/bookwyrm/views/shelf.py b/bookwyrm/views/shelf.py index 5312ac212..758e290ed 100644 --- a/bookwyrm/views/shelf.py +++ b/bookwyrm/views/shelf.py @@ -2,6 +2,7 @@ from collections import namedtuple from django.db import IntegrityError +from django.db.models import Count, OuterRef, Subquery, F, Q from django.contrib.auth.decorators import login_required from django.core.paginator import Paginator from django.http import HttpResponseBadRequest, HttpResponseNotFound @@ -37,30 +38,41 @@ class Shelf(View): return HttpResponseNotFound() if not shelf.visible_to_user(request.user): return HttpResponseNotFound() + books = shelf.books # this is a constructed "all books" view, with a fake "shelf" obj else: FakeShelf = namedtuple( "Shelf", ("identifier", "name", "user", "books", "privacy") ) books = models.Edition.objects.filter( + # privacy is ensured because the shelves are already filtered above shelfbook__shelf__in=shelves.all() ).distinct() shelf = FakeShelf("all", _("All books"), user, books, "public") - is_self = request.user == user - if is_api_request(request): return ActivitypubResponse(shelf.to_activity(**request.GET)) + reviews = privacy_filter( + request.user, + models.Review.objects.filter( + user=user, + rating__isnull=False, + book__id=OuterRef("id"), + ), + ).order_by("-published_date") + + books = books.annotate(rating=Subquery(reviews.values("rating")[:1])) + paginated = Paginator( - shelf.books.order_by("-updated_date"), + books.order_by("-updated_date"), PAGE_LENGTH, ) page = paginated.get_page(request.GET.get("page")) data = { "user": user, - "is_self": is_self, + "is_self": request.user == user, "shelves": shelves.all(), "shelf": shelf, "books": page,