Merge pull request #302 from mouse-reeve/shelf-preview-max

Max for books shown from shelves in suggestions bar
This commit is contained in:
Mouse Reeve 2020-11-07 11:55:34 -08:00 committed by GitHub
commit 7663bd620a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
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(