From 885bb023a3e882e2449cf0e2afbdb5d4faf50302 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Wed, 30 Dec 2020 16:07:29 -0800 Subject: [PATCH] Sort shelves by shelfbook updated date --- bookwyrm/templates/shelf.html | 2 +- bookwyrm/templates/snippets/shelf.html | 4 ++-- bookwyrm/views.py | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bookwyrm/templates/shelf.html b/bookwyrm/templates/shelf.html index 390b9fc6..4b27e3a4 100644 --- a/bookwyrm/templates/shelf.html +++ b/bookwyrm/templates/shelf.html @@ -122,7 +122,7 @@
- {% include 'snippets/shelf.html' with shelf=shelf ratings=ratings %} + {% include 'snippets/shelf.html' with shelf=shelf books=books ratings=ratings %}
{% endblock %} diff --git a/bookwyrm/templates/snippets/shelf.html b/bookwyrm/templates/snippets/shelf.html index 0d05e661..d5cdd003 100644 --- a/bookwyrm/templates/snippets/shelf.html +++ b/bookwyrm/templates/snippets/shelf.html @@ -1,6 +1,6 @@ {% load humanize %} {% load bookwyrm_tags %} -{% if shelf.books.all|length > 0 %} +{% if books|length > 0 %} @@ -34,7 +34,7 @@ {% endif %} -{% for book in shelf.books.all %} +{% for book in books %}
{% include 'snippets/book_cover.html' with book=book size="small" %} diff --git a/bookwyrm/views.py b/bookwyrm/views.py index df08ab18..0d7726b6 100644 --- a/bookwyrm/views.py +++ b/bookwyrm/views.py @@ -765,12 +765,17 @@ def shelf_page(request, username, shelf_identifier): if is_api_request(request): return ActivitypubResponse(shelf.to_activity(**request.GET)) + books = models.ShelfBook.objects.filter( + added_by=user, shelf=shelf + ).order_by('-updated_date').all() + data = { 'title': '%s\'s %s shelf' % (user.display_name, shelf.name), 'user': user, 'is_self': is_self, 'shelves': shelves.all(), 'shelf': shelf, + 'books': [b.book for b in books], } return TemplateResponse(request, 'shelf.html', data)