Skip to content

Disable borrow button when user reaches max loan limit#12349

Open
ayishaatwork wants to merge 2 commits intointernetarchive:masterfrom
ayishaatwork:fix-loan-limit-ui
Open

Disable borrow button when user reaches max loan limit#12349
ayishaatwork wants to merge 2 commits intointernetarchive:masterfrom
ayishaatwork:fix-loan-limit-ui

Conversation

@ayishaatwork
Copy link
Copy Markdown

Closes #

What does this PR achieve?

Disable borrow button when user reaches max loan limit


Technical

  • Added a check for user's loan count in LoanStatus.html
  • If loan_count >= 5, the "Borrow" button is replaced with a disabled button
  • Disabled button displays "Loan Limit Reached"
  • Uses existing user.get_loan_count() logic (no backend changes)

Testing

Testing

  1. Log in as a user
  2. Ensure the user has reached the maximum loan limit (5 books)
  3. Verify:
    • Borrow button is replaced with a disabled "Loan Limit Reached" button
  4. Ensure user with fewer than 5 loans sees normal "Borrow" button

Screenshot

not borrowed - Normal borrowed - Disabled "Loan Limit Reached" button

Stakeholders

@mekarpeles

@mekarpeles
Copy link
Copy Markdown
Member

What issue does this close? #439?

$ 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?

@mekarpeles mekarpeles added the Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed] label Apr 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs: Submitter Input Waiting on input from the creator of the issue/pr [managed]

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants