From 1abbc674831fb7eb30112856377738c1975b820d Mon Sep 17 00:00:00 2001 From: Faiazov Dmitrii Date: Thu, 14 Oct 2021 13:39:15 +0300 Subject: [PATCH] Make requested changes. Signed-off-by: Faiazov Dmitrii --- bookwyrm/templates/shelf/shelf.html | 8 ++++++-- bookwyrm/views/shelf.py | 16 +++++++++------- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/bookwyrm/templates/shelf/shelf.html b/bookwyrm/templates/shelf/shelf.html index eb3b472a..fa1e91f9 100644 --- a/bookwyrm/templates/shelf/shelf.html +++ b/bookwyrm/templates/shelf/shelf.html @@ -127,10 +127,12 @@ {% trans "Cover"%} {% trans "Title" as text %}{% include 'snippets/table-sort-header.html' with field="title" sort=sort text=text %} {% trans "Author" as text %}{% include 'snippets/table-sort-header.html' with field="author" sort=sort text=text %} + {% if request.user.is_authenticated %} + {% if is_self %} {% trans "Shelved" as text %}{% include 'snippets/table-sort-header.html' with field="shelved_date" sort=sort text=text %} {% trans "Started" as text %}{% include 'snippets/table-sort-header.html' with field="start_date" sort=sort text=text %} {% trans "Finished" as text %}{% include 'snippets/table-sort-header.html' with field="finish_date" sort=sort text=text %} - {% if request.user.is_authenticated %} + {% endif %} {% trans "Rating" as text %}{% include 'snippets/table-sort-header.html' with field="rating" sort=sort text=text %} {% endif %} {% if shelf.user == request.user %} @@ -151,6 +153,8 @@ {% include 'snippets/authors.html' %} + {% if request.user.is_authenticated %} + {% if is_self %} {{ book.shelved_date|naturalday }} @@ -160,7 +164,7 @@ {{ book.finish_date|naturalday|default_if_none:""}} - {% if request.user.is_authenticated %} + {% endif %} {% include 'snippets/stars.html' with rating=book.rating %} diff --git a/bookwyrm/views/shelf.py b/bookwyrm/views/shelf.py index c1d3512f..0b830d90 100644 --- a/bookwyrm/views/shelf.py +++ b/bookwyrm/views/shelf.py @@ -69,20 +69,22 @@ class Shelf(View): ).order_by("-published_date") reading = models.ReadThrough.objects - if not is_self: - reading = models.ReadThrough.privacy_filter(request.user) reading = reading.filter(user=user, book__id=OuterRef("id")).order_by( - "-start_date" + "start_date" ) books = books.annotate( rating=Subquery(reviews.values("rating")[:1]), shelved_date=F("shelfbook__shelved_date"), - start_date=Subquery(reading.values("start_date")), - finish_date=Subquery(reading.values("finish_date")), - author=F("authors__name"), - ) + start_date=Subquery(reading.values("start_date")[:1]), + finish_date=Subquery(reading.values("finish_date")[:1]), + author=Subquery( + models.Book.objects.filter(id=OuterRef("id")).values("authors__name")[ + :1 + ] + ), + ).prefetch_related("authors") books = sort_books(books, request.GET.get("sort"))