Skip to content

fix: redirect to book page with flash message after returning a book#11947

Merged
lokesh merged 7 commits intointernetarchive:masterfrom
bhardwajparth51:issue-9115-flash-message
Mar 25, 2026
Merged

fix: redirect to book page with flash message after returning a book#11947
lokesh merged 7 commits intointernetarchive:masterfrom
bhardwajparth51:issue-9115-flash-message

Conversation

@bhardwajparth51
Copy link
Copy Markdown
Contributor

@bhardwajparth51 bhardwajparth51 commented Feb 27, 2026

Closes #9115

Technical

This PR updates the book return flow to show a flash message confirmation upon successful return, providing much-needed feedback to the patron instead of a silent reload.

Implementation Details:
Used add_flash_message from vendor/infogami/infogami/utils/flash.py in the return block inside openlibrary/plugins/upstream/borrow.py to show a green success notification.

Note on Commits:
I initially experimented with removing the hidden redirect input and hardcoding a redirect to edition.url(). However, I realized the original edition_redirect approach is actually better UX. It ensures the user is cleanly redirected back to whichever specific page they initiated the return from (e.g., if they were on the Loans page, they stay there; if they were on the Book page, they stay there). My final commit restores edition_redirect and the hidden form input to preserve this behavior while adding the flash message.

Testing

  1. Log in and borrow an available book.
  2. Navigate to your Loans page (/account/loans) or the book's specific canonical page.
  3. Click "Return book".
  4. Verify you remain on the correct context page (Redirect works).
  5. Verify a green flash message appears reading: "You have successfully returned [Book Title]."
Screenshot from 2026-02-27 10-30-32 Screenshot from 2026-02-27 10-33-11 Screenshot from 2026-02-27 10-33-01

Stakeholders

@mekarpeles @RayBB

@bhardwajparth51 bhardwajparth51 force-pushed the issue-9115-flash-message branch 2 times, most recently from bbf4047 to 133084a Compare March 1, 2026 08:57
@bhardwajparth51 bhardwajparth51 force-pushed the issue-9115-flash-message branch from 133084a to 453e00d Compare March 1, 2026 09:26
@bhardwajparth51
Copy link
Copy Markdown
Contributor Author

@lokesh would appreciate a review when you get a chance. Happy to make any adjustments!

@github-actions github-actions bot added the Needs: Response Issues which require feedback from lead label Mar 12, 2026
@bhardwajparth51 bhardwajparth51 force-pushed the issue-9115-flash-message branch 2 times, most recently from 0efedeb to 41a18f6 Compare March 13, 2026 18:41
@bhardwajparth51 bhardwajparth51 force-pushed the issue-9115-flash-message branch from 41a18f6 to 9582929 Compare March 13, 2026 18:44
@bhardwajparth51 bhardwajparth51 requested a review from lokesh March 13, 2026 18:57
@bhardwajparth51
Copy link
Copy Markdown
Contributor Author

@lokesh I've updated the PR to address your feedback.

lokesh and others added 3 commits March 13, 2026 12:23
- Replace contextlib.suppress with explicit try/except for clearer intent
- Consolidate redirect URL encoding into a single urllib.parse.quote call
- Use urlunsplit for redirect sanitization (preserves fragment, simpler code)
- Move stats.increment into success branch so failed returns aren't counted

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add noqa for PLR0912 (too many branches) alongside existing PLR0915
suppression, and use contextlib.suppress for the PatronAccessException
catch-and-pass pattern.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Collaborator

@lokesh lokesh left a comment

Choose a reason for hiding this comment

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

A few changes I added to the PR to bullet proof things and improve readability:

  • Replace contextlib.suppress with explicit try/except for clearer intent
  • Consolidate redirect URL encoding into a single urllib.parse.quote call
  • Use urlunsplit for redirect sanitization (preserves fragment, simpler code)

We'll need to verify on testing server before merging.

@lokesh lokesh added Needs: Testing and removed Needs: Response Issues which require feedback from lead labels Mar 13, 2026
@github-actions github-actions bot added the Needs: Response Issues which require feedback from lead label Mar 14, 2026
@bhardwajparth51
Copy link
Copy Markdown
Contributor Author

Hey @lokesh @mekarpeles, just checking in — has this been verified on the testing server yet?

@lokesh
Copy link
Copy Markdown
Collaborator

lokesh commented Mar 23, 2026

Screenshot 2026-03-23 at 2 19 13 PM Screenshot 2026-03-23 at 2 19 27 PM

I was able to test successfully. Note: There is an issue on the testing server with icon rendering, thus the garbled background on the flash message.

@lokesh lokesh merged commit 2b46c91 into internetarchive:master Mar 25, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs: Response Issues which require feedback from lead Needs: Testing On Testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

When you borrow a book and then return it, it should take you back to the page of the book

4 participants