From 72eb94315a3636e88dddc825c1705c798cd7bc23 Mon Sep 17 00:00:00 2001 From: Mouse Reeve Date: Fri, 11 Dec 2020 16:39:58 -0800 Subject: [PATCH] Adds shelf info to book page - includes change shelf button - WIP button for switching to the current edition --- bookwyrm/templates/book.html | 97 ++++--------------- bookwyrm/templates/snippets/readthrough.html | 80 +++++++++++++++ .../snippets/switch_edition_button.html | 3 + bookwyrm/views.py | 21 ++-- 4 files changed, 116 insertions(+), 85 deletions(-) create mode 100644 bookwyrm/templates/snippets/readthrough.html create mode 100644 bookwyrm/templates/snippets/switch_edition_button.html diff --git a/bookwyrm/templates/book.html b/bookwyrm/templates/book.html index 51fbdafc..eee22898 100644 --- a/bookwyrm/templates/book.html +++ b/bookwyrm/templates/book.html @@ -91,87 +91,26 @@ {% endif %} - {% for readthrough in readthroughs %} -
- - -
- -
- - -
- + {# user's relationship to the book #}
- - + {% for shelf in user_shelves %} +

+ This edition is on your {{ shelf.shelf.name }} shelf. + {% include 'snippets/shelf_selector.html' with current=shelf.shelf %} +

+ {% endfor %} + + {% for shelf in other_edition_shelves %} +

+ A different edition of this book is on your {{ shelf.shelf.name }} shelf. + {% include 'snippets/switch_edition_button.html' with desired_edition=book %} +

+ {% endfor %} + + {% for readthrough in readthroughs %} + {% include 'snippets/readthrough.html' with readthrough=readthrough %} + {% endfor %}
- {% endfor %} {% if request.user.is_authenticated %}
diff --git a/bookwyrm/templates/snippets/readthrough.html b/bookwyrm/templates/snippets/readthrough.html new file mode 100644 index 00000000..4d6ca03a --- /dev/null +++ b/bookwyrm/templates/snippets/readthrough.html @@ -0,0 +1,80 @@ +{% load humanize %} +
+ + +
+ +
+ + +
+ +
+ + +
diff --git a/bookwyrm/templates/snippets/switch_edition_button.html b/bookwyrm/templates/snippets/switch_edition_button.html new file mode 100644 index 00000000..3fa09f4f --- /dev/null +++ b/bookwyrm/templates/snippets/switch_edition_button.html @@ -0,0 +1,3 @@ +
+ +
diff --git a/bookwyrm/views.py b/bookwyrm/views.py index e0feaee7..7c27eade 100644 --- a/bookwyrm/views.py +++ b/bookwyrm/views.py @@ -5,8 +5,7 @@ from django.contrib.auth.decorators import login_required, permission_required from django.contrib.postgres.search import TrigramSimilarity from django.core.paginator import Paginator from django.db.models import Avg, Q -from django.http import HttpResponseBadRequest, HttpResponseNotFound,\ - JsonResponse +from django.http import HttpResponseNotFound, JsonResponse from django.core.exceptions import PermissionDenied from django.shortcuts import get_object_or_404, redirect from django.template.response import TemplateResponse @@ -558,8 +557,7 @@ def book_page(request, book_id): prev_page = '/book/%s/?page=%d' % \ (book_id, reviews_page.previous_page_number()) - user_tags = [] - readthroughs = [] + user_tags = readthroughs = user_shelves = other_edition_shelves = [] if request.user.is_authenticated: user_tags = models.Tag.objects.filter( book=book, user=request.user @@ -570,6 +568,16 @@ def book_page(request, book_id): book=book, ).order_by('start_date') + user_shelves = models.ShelfBook.objects.filter( + added_by=request.user, book=book + ) + + other_edition_shelves = models.ShelfBook.objects.filter( + ~Q(book=book), + added_by=request.user, + book__parent_work=book.parent_work, + ) + rating = reviews.aggregate(Avg('rating')) tags = models.Tag.objects.filter( book=book @@ -585,6 +593,8 @@ def book_page(request, book_id): 'rating': rating['rating__avg'], 'tags': tags, 'user_tags': user_tags, + 'user_shelves': user_shelves, + 'other_edition_shelves': other_edition_shelves, 'readthroughs': readthroughs, 'path': '/book/%s' % book_id, 'info_fields': [ @@ -628,10 +638,9 @@ def editions_page(request, book_id): encoder=ActivityEncoder ) - editions = models.Edition.objects.filter(parent_work=work).all() data = { 'title': 'Editions of %s' % work.title, - 'editions': editions, + 'editions': work.edition_set.all(), 'work': work, } return TemplateResponse(request, 'editions.html', data)