$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) $ 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 availability and 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 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(): $:macros.ReadButton(ocaid, listen=listen, printdisabled=True) $elif availability.get('is_lendable'): $if availability.get('available_to_borrow'): $:macros.ReadButton(ocaid, borrow=True, listen=listen) $elif 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: $_('Not in Library') $else: $if ocaid and secondary_action and availability.get('is_printdisabled'): $:macros.BookPreview(ocaid) $:post $if ocaid and daisy: $:macros.daisy('/ia/%s/daisy' % ocaid, protected=availability.get('is_printdisabled')) $if query_param('debug'): $ loanstatus_end_time = time() - loanstatus_start_timeLoanStatus took $("%.2f" % loanstatus_end_time) seconds
$availability