+ {# almost every view needs to know the user shelves #}
+ {% with request.user.shelf_set.all as user_shelves %}
{% block content %}
{% endblock %}
+ {% endwith %}
diff --git a/bookwyrm/templates/snippets/shelf_selector.html b/bookwyrm/templates/snippets/shelf_selector.html
index 0036a4e90..ca5a39f6e 100644
--- a/bookwyrm/templates/snippets/shelf_selector.html
+++ b/bookwyrm/templates/snippets/shelf_selector.html
@@ -6,7 +6,7 @@
{% endblock %}
{% block dropdown-list %}
-{% for shelf in request.user.shelf_set.all %}
+{% for shelf in user_shelves %}
{% else %}
- {% include 'snippets/shelve_button/shelve_button_options.html' with class="shelf-option is-small" shelves=request.user.shelf_set.all active_shelf=active_shelf button_uuid=uuid %}
+ {% include 'snippets/shelve_button/shelve_button_options.html' with class="shelf-option is-small" shelves=user_shelves active_shelf=active_shelf button_uuid=uuid %}
{% include 'snippets/shelve_button/shelve_button_dropdown.html' with class="is-small" button_uuid=uuid%}
{% endif %}
@@ -25,7 +25,7 @@
{% include 'snippets/shelve_button/finish_reading_modal.html' with book=active_shelf.book controls_text="finish-reading" controls_uid=uuid readthrough=readthrough %}
-{% include 'snippets/shelve_button/progress_update_modal.html' with book=shelf_book.book controls_text="progress-update" controls_uid=uuid readthrough=readthrough %}
+{% include 'snippets/shelve_button/progress_update_modal.html' with book=active_shelf_book.book controls_text="progress-update" controls_uid=uuid readthrough=readthrough %}
{% endwith %}
{% endif %}
diff --git a/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown.html b/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown.html
index 4439bfc28..353a37a1c 100644
--- a/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown.html
+++ b/bookwyrm/templates/snippets/shelve_button/shelve_button_dropdown.html
@@ -7,5 +7,5 @@
{% endblock %}
{% block dropdown-list %}
-{% include 'snippets/shelve_button/shelve_button_options.html' with active_shelf=active_shelf shelves=request.user.shelf_set.all dropdown=True class="shelf-option is-fullwidth is-small is-radiusless is-white" %}
+{% include 'snippets/shelve_button/shelve_button_options.html' with active_shelf=active_shelf shelves=user_shelves dropdown=True class="shelf-option is-fullwidth is-small is-radiusless is-white" %}
{% endblock %}
diff --git a/bookwyrm/templatetags/bookwyrm_tags.py b/bookwyrm/templatetags/bookwyrm_tags.py
index 70228799f..072ff6634 100644
--- a/bookwyrm/templatetags/bookwyrm_tags.py
+++ b/bookwyrm/templatetags/bookwyrm_tags.py
@@ -3,8 +3,6 @@ from django import template
from django.db.models import Avg
from bookwyrm import models, views
-from bookwyrm.views.status import to_markdown
-from bookwyrm.templatetags.utilities import get_user_identifier
register = template.Library()
@@ -73,7 +71,7 @@ def active_shelf(context, book):
"""check what shelf a user has a book on, if any"""
shelf = models.ShelfBook.objects.filter(
shelf__user=context["request"].user, book__in=book.parent_work.editions.all()
- ).first()
+ ).select_related("book", "shelf").first()
return shelf if shelf else {"book": book}