$def with (doc, work_key=None, listen=True, daisy=True, allow_expensive_availability_check=False, secondary_action=False, check_sponsorship=False, sponsorship_help=False, check_loan_status=False, user_lists=None, post='') $# Takes following parameters: $# * doc - Can be a Work, Edition, or solr dict. $# * listen whether to display listen button $# * daisy whether to display daisy print-disabled link $# * allow_expensive_availability_check whether to check the groundtruth availability if can't get availability from specified fields $# * secondary_action whether to display the preview/search inside button $# * check_sponsorship whether to check if the book is eligible for sponsorship $# * sponsorship_help whether to show the sponsorship help text $# * check_loan_status whether to check the user's loan status to determine read button $ loanstatus_start_time = time() $ availability = (doc.availability or {}) if hasattr(doc, 'availability') else {} $ ocaid = doc.get('ocaid') or availability.get('identifier') $ work_key = work_key or (doc.get('works') and doc.works[0].key) $ no_index = hasattr(doc, 'get_ia_meta_fields') and doc.get_ia_meta_fields().get('noindex', False) $ waiting_loan = check_loan_status and ocaid and ctx.user and ctx.user.get_waiting_loan_for(ocaid) $ my_turn_to_borrow = waiting_loan and waiting_loan['status'] == 'available' and waiting_loan['position'] == 1 $if not waiting_loan: $ book_provider = get_book_provider(doc) $else: $ book_provider = get_book_provider.ia $# Replace existing, possibly inaccurate, availability with results ground truth availability API call: $if allow_expensive_availability_check and ocaid: $ availability.update(get_cached_groundtruth_availability(ocaid)) $ borrow_link = '/borrow/ia/%s' % ocaid $ user_loan = check_loan_status and ocaid and ctx.user and ctx.user.get_loan_for(ocaid) $if user_loan: $:macros.ReadButton(ocaid, loan=user_loan, listen=listen) $ return_url = doc.url().rsplit('/', 1)[0] + '/do_return/borrow'
$if render_once('LoanStatus:return-book-js'): $elif book_provider and book_provider.short_name != 'ia': $:book_provider.render_read_button(doc) $elif availability.get('is_readable'): $:macros.ReadButton(ocaid, listen=listen) $if secondary_action: $:macros.BookSearchInside(ocaid) $elif ocaid and ctx.user and ctx.user.is_printdisabled(): $ std_borrow = availability and availability.get('is_lendable') $:macros.ReadButton(ocaid, borrow=std_borrow, printdisabled=not std_borrow, listen=listen) $elif availability.get('is_lendable'): $if availability.get("available_to_borrow") or availability.get("available_to_browse"): $:macros.ReadButton(ocaid, borrow=True, listen=listen) $elif availability.get('available_to_waitlist'): $ wlsize = availability.get('users_on_waitlist') or availability.get('num_waitlist') $if waiting_loan: $else: $# "JOIN-WAITLIST" button $else: $# Checked out $elif ('eligibility' in doc) or (check_sponsorship and not ocaid and not availability.get('is_lendable')): $ sponsorship = doc.get('eligibility') if 'eligibility' in doc else qualifies_for_sponsorship(doc, donate_only=True) $if sponsorship.get('is_eligible'): $_('Donate Book') $if sponsorship_help:$_("We don't have this book yet. Can you donate it to the Lending Library?") $_('Learn More')
$else: $else: $if ocaid and secondary_action and availability.get('is_printdisabled') and book_provider.short_name == 'ia': $:macros.BookPreview(ocaid, linkback=not no_index) $:macros.BookSearchInside(ocaid) $:post $if ocaid and daisy and book_provider.short_name == 'ia': $ url = doc.get('url') or doc.get('key') + '/-' $:macros.daisy('%s/daisy' % url, protected=availability.get('is_printdisabled')) $if query_param('debug'): $ loanstatus_end_time = time() - loanstatus_start_timeLoanStatus took $("%.2f" % loanstatus_end_time) seconds
$availability