Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add shelves column in shelf table #2562

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions bookwyrm/templates/shelf/shelf.html
Expand Up @@ -155,6 +155,9 @@ <h2 class="title is-3">
{% endif %}
<th>{% trans "Rating" as text %}{% include 'snippets/table-sort-header.html' with field="rating" sort=sort text=text %}</th>
{% endif %}
{% if shelves|length > 0 %}
<th>{% trans "Shelves" %}</th>
{% endif %}
{% if shelf.user == request.user %}
<th aria-hidden="true"></th>
{% endif %}
Expand Down Expand Up @@ -189,6 +192,19 @@ <h2 class="title is-3">
{% include 'snippets/stars.html' with rating=book.rating %}
</td>
{% endif %}
{% if shelves|length > 0 %}
<td data-title="{% trans "Shelves" %}">
{% spaceless %}
{% for shelf in shelves %}
{% if shelf in book.shelves.all %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think book.shelves will produce all shelves for all users, rather than the shelf related to the current user

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that it only displays the shelves for the user (see screenshot below: same book on different shelves for different users). Is there another way to test what book.shelves produces?

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, we're actually both sort of right -- book.shelves.all does produce all shelves for all users, but because it's checking if a Shelf object is present, and a Shelf is tied to a user, it still displays correctly, so this does work exactly how you intended.

My new qualm is that on a large instance, that's going to be a costly lookup, since there are a lot of shelves. It may be that assigning book.shelves.all to a variable using {% set ... %}, so that the query is only called once rather than once per shelf, will be enough mitigation?

<a href="{{ shelf.local_path }}">
{% include "snippets/translated_shelf_name.html" with shelf=shelf %}
</a>{% if not forloop.last %}<br>{% endif %}
{% endif %}
{% endfor %}
{% endspaceless %}
</td>
{% endif %}
{% if shelf.user == request.user %}
<td class="book-preview-top-row has-text-right">
{% with right=True %}
Expand Down