Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions openlibrary/i18n/messages.pot
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,14 @@ msgstr ""
msgid "Read"
msgstr ""

#: LoanStatus.html
msgid "You have reached the maximum number of borrowed books."
msgstr ""

#: LoanStatus.html
msgid "Loan Limit Reached"
msgstr ""

#: LoanStatus.html
msgid "You are <strong>next</strong> on the waiting list"
msgstr ""
Expand Down
16 changes: 15 additions & 1 deletion openlibrary/macros/LoanStatus.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
$ waiting_loan = check_loan_status and ocaid and user and user.get_user_waiting_loans(ocaid, use_cache=True)
$ waiting_loan_total_time = time() - waiting_loan_start_time
$ my_turn_to_borrow = waiting_loan and waiting_loan['status'] == 'available' and waiting_loan['position'] == 1
$ user = ctx.user if ctx.user else None
$ loan_count = user.get_loan_count() if user else 0
$ has_reached_loan_limit = loan_count >= 5
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do not hard code max loans in the code.

This needs to be a variable in openlibrary.yml

Copy link
Copy Markdown
Author

@ayishaatwork ayishaatwork Apr 20, 2026

Choose a reason for hiding this comment

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

Hi @mekarpeles, I started implementing the fix and had a quick question about scope.

I noticed that max_loans is currently hardcoded as 5 in borrow.py, and I understand the instruction to move this to openlibrary.yml.

However, in LoanStatus.html, the template doesn’t seem to have access to config, so using config.get('max_loans') there raises a NameError.

Would you prefer that I:

  1. Keep the template logic simple (still using 5) and only make the backend configurable, or
  2. Pass max_loans (or a computed has_reached_loan_limit) from the backend into the template so it stays fully consistent?


$if not waiting_loan:
$ book_provider = get_book_provider(doc)
Expand Down Expand Up @@ -77,7 +80,18 @@
$if secondary_action:
$:macros.BookPreview(ocaid, analytics_attr, show_only=False)
$if availability.get("available_to_borrow") or availability.get("available_to_browse"):
$:macros.ReadButton(ocaid, analytics_attr, borrow=True, listen=listen, edition_key=edition_key)
$if has_reached_loan_limit:
<div class="cta-button-group">
<button
class="cta-btn cta-btn--available:disabled"
disabled
title="$_('You have reached the maximum number of borrowed books.')"
>
$_("Loan Limit Reached")
</button>
</div>
$else:
$:macros.ReadButton(ocaid, analytics_attr, borrow=True, listen=listen, edition_key=edition_key)
$elif availability.get('available_to_waitlist'):
$if waiting_loan:
$if secondary_action:
Expand Down