Skip to content

Commit

Permalink
Merge pull request #8104 from cdrini/7903/fix/loans-return-broken
Browse files Browse the repository at this point in the history
Fix return button not working from loans page
  • Loading branch information
mekarpeles authored Jul 20, 2023
2 parents 63d7ce9 + b52a2fc commit f78e0a8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
11 changes: 3 additions & 8 deletions openlibrary/macros/LoanStatus.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,12 @@
$if user_loan:
$:macros.ReadButton(ocaid, loan=user_loan, listen=listen)
$if secondary_action:
$ return_url = doc.url().rsplit('/', 1)[0] + '/do_return/borrow'
<form action="$return_url" method="post"
class="waitinglist-form return-book" style="margin-bottom: 10px;">
<input type="hidden" name="action" value="return" />
<input type="submit" value="$_('Return eBook')" class="cta-btn cta-btn--shell" id="return_ebook" style="margin-bottom: 0px;" />
$:macros.FormatExpiry(user_loan['expiry'])
</form>
$:macros.ReturnForm(ocaid)
$:macros.FormatExpiry(user_loan['expiry'])
$if render_once('LoanStatus:return-book-js'):
<script type="text/javascript">
window.q.push(function() {
\$('.return-book').on('submit', function(event) {
\$('.return-form').on('submit', function(event) {
if (!confirm("$_('Really return this book?')")) {
event.preventDefault();
}
Expand Down
7 changes: 6 additions & 1 deletion openlibrary/macros/ReturnForm.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
$def with (ocaid)

<form action="/borrow/ia/$ocaid" method="post">
<form
action="/borrow/ia/$ocaid"
method="post"
class="return-form"
>
<input class="cta-btn cta-btn--vanilla" type="submit" value="$_('Return book')" />
<input type="hidden" name="action" value="return" />
<input type="hidden" name="redirect" value="$request.fullpath" />
</form>
11 changes: 8 additions & 3 deletions openlibrary/plugins/upstream/borrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ def POST(self, key):
"""Called when the user wants to borrow the edition"""

i = web.input(
action='borrow', format=None, ol_host=None, _autoReadAloud=None, q=""
action='borrow',
format=None,
ol_host=None,
_autoReadAloud=None,
q="",
redirect="",
)

ol_host = i.ol_host or 'openlibrary.org'
Expand All @@ -137,7 +142,7 @@ def POST(self, key):
raise web.seeother(archive_url)

error_redirect = archive_url
edition_redirect = urllib.parse.quote(edition.url())
edition_redirect = urllib.parse.quote(i.redirect or edition.url())
user = accounts.get_current_user()

if user:
Expand All @@ -158,7 +163,7 @@ def POST(self, key):
stats.increment('ol.loans.return')
edition.update_loan_status()
user.update_loan_status()
raise web.seeother(web.ctx.path)
raise web.seeother(edition_redirect)
elif action == 'join-waitinglist':
lending.s3_loan_api(edition.ocaid, s3_keys, action='join_waitlist')
stats.increment('ol.loans.joinWaitlist')
Expand Down

0 comments on commit f78e0a8

Please sign in to comment.