Max on books shown from shelves in suggestions bar

This commit is contained in:
Mouse Reeve 2020-11-07 11:54:32 -08:00
parent 1b50e83c95
commit 794aeb299c
2 changed files with 9 additions and 4 deletions

View file

@ -14,7 +14,9 @@
{% if shelf.books %}
{% with shelf_counter=forloop.counter %}
<li>
<p>{{ shelf.name }}</p>
<p>
{{ shelf.name }}
</p>
<div class="tabs is-small is-toggle">
<ul>
{% for book in shelf.books %}

View file

@ -87,10 +87,13 @@ def home_tab(request, tab):
def get_suggested_books(user, max_books=5):
''' helper to get a user's recent books '''
book_count = 0
preset_shelves = ['reading', 'read', 'to-read']
preset_shelves = [
('reading', max_books), ('read', 2), ('to-read', max_books)
]
suggested_books = []
for preset in preset_shelves:
limit = max_books - book_count
for (preset, shelf_max) in preset_shelves:
limit = shelf_max if shelf_max < (max_books - book_count) \
else max_books - book_count
shelf = user.shelf_set.get(identifier=preset)
shelf_books = shelf.shelfbook_set.order_by(