Skip to content

Commit 9582929

Browse files
update: fix return loan texts
1 parent 453e00d commit 9582929

2 files changed

Lines changed: 27 additions & 9 deletions

File tree

openlibrary/i18n/messages.pot

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1427,13 +1427,18 @@ msgstr ""
14271427
msgid "Loan History"
14281428
msgstr ""
14291429

1430+
#: openlibrary/plugins/upstream/borrow.py
1431+
#, python-format
1432+
msgid "Unable to return %s. Please try again later or contact info@archive.org."
1433+
msgstr ""
1434+
14301435
#: openlibrary/plugins/upstream/borrow.py
14311436
msgid "this book"
14321437
msgstr ""
14331438

14341439
#: openlibrary/plugins/upstream/borrow.py
14351440
#, python-format
1436-
msgid "You have successfully returned %s."
1441+
msgid "%s has been returned."
14371442
msgstr ""
14381443

14391444
#: openlibrary/plugins/upstream/borrow.py

openlibrary/plugins/upstream/borrow.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,31 @@ def POST(self, key): # noqa: PLR0915
193193
raise web.seeother(redirect_url)
194194

195195
if action == 'return':
196-
# Suppress PatronAccessException: the loan may have already expired
197-
# on the IA side. Either way, proceed with redirect and confirmation.
198-
with contextlib.suppress(lending.PatronAccessException):
196+
try:
199197
lending.s3_loan_api(s3_keys, ocaid=edition.ocaid, action='return_loan')
198+
except lending.PatronAccessException:
199+
# Loan may have already expired — check status before claiming success
200+
pass
200201
stats.increment('ol.loans.return')
201202
edition.update_loan_status()
202203
user.update_loan_status()
203-
title = edition.title or _('this book')
204-
add_flash_message(
205-
'success',
206-
_('You have successfully returned %s.') % title,
207-
)
204+
205+
if user.has_borrowed(edition):
206+
# The return failed and they still have the loan
207+
add_flash_message(
208+
'error',
209+
_(
210+
'Unable to return %s. Please try again later or contact info@archive.org.'
211+
)
212+
% (edition.title or _('this book')),
213+
)
214+
else:
215+
# The return succeeded or the loan was already expired/gone
216+
title = edition.title or _('this book')
217+
add_flash_message(
218+
'success',
219+
_('%s has been returned.') % title,
220+
)
208221
raise web.seeother(edition_redirect)
209222
elif action == 'join-waitinglist':
210223
lending.get_cached_user_waiting_loans.memcache_delete(

0 commit comments

Comments
 (0)