Merge pull request #1740 from bookwyrm-social/shelf-dupes

Removes duplicates from all books view
This commit is contained in:
Mouse Reeve 2022-01-02 07:28:50 -08:00 committed by GitHub
commit 8c265b1857
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View file

@ -63,16 +63,18 @@
{% endfor %}
{% if shelf.identifier == 'all' %}
{% for shelved_in in book.shelves.all %}
{% for user_shelf in user_shelves %}
{% if user_shelf in book.shelves.all %}
<li class="navbar-divider m-0" role="separator" ></li>
<li role="menuitem" class="dropdown-item p-0">
<form name="shelve" action="/unshelve/" method="post">
{% csrf_token %}
<input type="hidden" name="book" value="{{ book.id }}">
<input type="hidden" name="shelf" value="{{ shelved_in.id }}">
<button class="button is-fullwidth is-small is-radiusless is-danger is-light" type="submit">{% trans "Remove from" %} {{ shelved_in.name }}</button>
<input type="hidden" name="shelf" value="{{ user_shelf.id }}">
<button class="button is-fullwidth is-small is-radiusless is-danger is-light" type="submit">{% trans "Remove from" %} {{ user_shelf.name }}</button>
</form>
</li>
{% endif %}
{% endfor %}
{% else %}
<li class="navbar-divider" role="separator" ></li>

View file

@ -72,9 +72,13 @@ class Shelf(View):
"start_date"
)
if shelf_identifier:
books = books.annotate(shelved_date=F("shelfbook__shelved_date"))
else:
# sorting by shelved date will cause duplicates in the "all books" view
books = books.annotate(shelved_date=F("updated_date"))
books = books.annotate(
rating=Subquery(reviews.values("rating")[:1]),
shelved_date=F("shelfbook__shelved_date"),
start_date=Subquery(reading.values("start_date")[:1]),
finish_date=Subquery(reading.values("finish_date")[:1]),
author=Subquery(