Skip to content

Commit

Permalink
Add Worldcat URL to dropper
Browse files Browse the repository at this point in the history
Add a Check Nearby Libraries option to the read button dropper if an OCLC or ISBN identifier exists for an edition. Not satisfied with this solution as it adds another argument to LoanStatus.html calls, will probably be changed
  • Loading branch information
SivanC committed Aug 20, 2024
1 parent cdea89b commit d98df44
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
19 changes: 14 additions & 5 deletions openlibrary/macros/LoanStatus.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$def with (doc, work_key=None, listen=True, allow_expensive_availability_check=False, secondary_action=False, check_sponsorship=False, sponsorship_help=False, check_loan_status=False, user_lists=None, post='', is_book_page=False, analytics_override=None)
$def with (doc, work_key=None, listen=True, allow_expensive_availability_check=False, secondary_action=False, check_sponsorship=False, sponsorship_help=False, check_loan_status=False, user_lists=None, post='', is_book_page=False, analytics_override=None, edition=None)
$# Takes following parameters:
$# * doc - Can be a Work, Edition, or solr dict.
$# * listen - whether to display listen button
Expand Down Expand Up @@ -45,8 +45,17 @@
$else:
data-ol-link-track="CTAClick|$action"

$# Get ISBN and/or OCLC to for WorldCat url in read button dropdown
$ oclc_numbers = ""
$ isbn_13 = None
$ isbn_10 = None
$if edition:
$ oclc_numbers = (edition.oclc_numbers and edition.oclc_numbers[0]) or ""
$ isbn_13 = edition.get_isbn13() or None
$ isbn_10 = edition.get_isbn10() or None

$if user_loan:
$:macros.ReadButton(ocaid, analytics_attr, loan=user_loan, listen=listen)
$:macros.ReadButton(ocaid, analytics_attr, loan=user_loan, listen=listen, oclc_numbers=oclc_numbers, isbn=isbn_13 or isbn_10)
$if secondary_action:
$:macros.ReturnForm(ocaid)
$:macros.FormatExpiry(user_loan['expiry'])
Expand All @@ -57,7 +66,7 @@

$elif availability.get('is_readable') or availability.get('status') == 'open':
$# Open / Publicly Readable (Unrestricted)
$:macros.ReadButton(ocaid, analytics_attr, listen=listen)
$:macros.ReadButton(ocaid, analytics_attr, listen=listen, oclc_numbers=oclc_numbers, isbn=isbn_13 or isbn_10)
$if secondary_action:
$:macros.BookSearchInside(ocaid)

Expand All @@ -67,13 +76,13 @@
$ std_borrow = availability.get("available_to_borrow") or availability.get("available_to_browse")
$if secondary_action and (availability.get('is_printdisabled') or availability.get('is_lendable')):
$:macros.BookPreview(ocaid, analytics_attr, show_only=False)
$:macros.ReadButton(ocaid, analytics_attr, borrow=pd_eligible, printdisabled=not std_borrow, listen=listen)
$:macros.ReadButton(ocaid, analytics_attr, borrow=pd_eligible, printdisabled=not std_borrow, listen=listen, oclc_numbers=oclc_numbers, isbn=isbn_13 or isbn_10)

$elif availability.get('is_lendable'):
$if secondary_action:
$:macros.BookPreview(ocaid, analytics_attr, show_only=False)
$if availability.get("available_to_borrow") or availability.get("available_to_browse"):
$:macros.ReadButton(ocaid, analytics_attr, borrow=True, listen=listen)
$:macros.ReadButton(ocaid, analytics_attr, borrow=True, listen=listen, oclc_numbers=oclc_numbers, isbn=isbn_13 or isbn_10)
$elif availability.get('available_to_waitlist'):
$if waiting_loan:
$if secondary_action:
Expand Down
16 changes: 9 additions & 7 deletions openlibrary/macros/ReadButton.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$def with(ocaid, analytics_attr, borrow=False, listen=False, loan=None, label='', printdisabled=False)
$def with(ocaid, analytics_attr, borrow=False, listen=False, loan=None, label='', printdisabled=False, oclc_numbers=None, isbn=None)

$ stream_url = "/borrow/ia/%s?ref=ol" % ocaid

Expand Down Expand Up @@ -53,12 +53,14 @@
<span class="btn-label">Download</span>
</a>
</li>
<li>
<a class="cta-btn cta-btn--available cta-btn--w-icon">
<span class="btn-icon map"></span>
<span class="btn-label">Check Nearby Libraries</span>
</a>
</li>
$if oclc_numbers or isbn:
<li>
<a class="cta-btn cta-btn--available cta-btn--w-icon"
href="$macros.WorldcatUrl(isbn=isbn, oclc_numbers=oclc_numbers)">
<span class="btn-icon map"></span>
<span class="btn-label">Check Nearby Libraries</span>
</a>
</li>
</ul>
</div>
</details>
Expand Down
2 changes: 1 addition & 1 deletion openlibrary/macros/databarWork.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ <h3 class="header">
$# if edition availability status is error
$ render_times['databarWork: LoanStatus'] = time()
$ expensive_check = page.get('availability', {}).get('status') in ['error']
$:macros.LoanStatus(page, allow_expensive_availability_check=expensive_check, secondary_action=editions_page, check_sponsorship=editions_page, sponsorship_help=editions_page, check_loan_status=editions_page, post=lists_widget)
$:macros.LoanStatus(page, allow_expensive_availability_check=expensive_check, secondary_action=editions_page, check_sponsorship=editions_page, sponsorship_help=editions_page, check_loan_status=editions_page, post=lists_widget, edition=edition)
$ render_times['databarWork: LoanStatus'] = time() - render_times['databarWork: LoanStatus']

<hr>
Expand Down
2 changes: 1 addition & 1 deletion openlibrary/templates/books/edition-sort.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
<div class="links">
<ul class="read">
$# render_first is only true on the book page for an edition.
<li class="read-option">$:macros.LoanStatus(book, is_book_page=render_first)</li>
<li class="read-option">$:macros.LoanStatus(book, is_book_page=render_first, edition=book)</li>
</ul>
$if oclc_numbers or isbn:
<div class="editions-table__links">
Expand Down

0 comments on commit d98df44

Please sign in to comment.