Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'locate' endpoint to borrow API #9842

Merged
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
2 changes: 2 additions & 0 deletions openlibrary/plugins/upstream/borrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,8 @@ def POST(self, key): # noqa: PLR0915
lending.s3_loan_api(s3_keys, ocaid=edition.ocaid, action='leave_waitlist')
stats.increment('ol.loans.leaveWaitlist')
raise web.redirect(edition_redirect)
elif action == 'locate':
raise web.seeother(edition.get_worldcat_url())

elif action in ('borrow', 'browse') and not user.has_borrowed(edition):
borrow_access = user_can_borrow_edition(user, edition)
Expand Down
9 changes: 9 additions & 0 deletions openlibrary/plugins/upstream/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ def get_isbn13(self):
return isbn_10 and isbn_10_to_isbn_13(isbn_10)
return isbn_13

def get_worldcat_url(self):
url = 'https://search.worldcat.org/'
if self.get('oclc_numbers'):
return f'{url}/title/{self.oclc_numbers[0]}'
elif self.get_isbn13():
# Handles both isbn13 & 10
return f'{url}/isbn/{self.get_isbn13()}'
return f'{url}/search?q={self.title}'

def get_isbnmask(self):
"""Returns a masked (hyphenated) ISBN if possible."""
isbns = self.get('isbn_13', []) + self.get('isbn_10', [None])
Expand Down
Loading