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

Draft: Prototype for printdisabled fulfillment #7061

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 10 additions & 29 deletions openlibrary/macros/LoanStatus.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,16 @@

$ is_edition = doc.key.split('/')[1] == 'books'

$if secondary_action and ocaid and ctx.user and ctx.user.is_printdisabled():
<h3>$_('You qualify for special print-disabled access:')</h3>
<ul>
<li><a href="/borrow/ia/$(ocaid)?ref=ol">$_('Read Now in Browser')</a></li>
<li><a href="/borrow/ia/$(ocaid)?ref=ol&action=request&format=epub">$_('Request epub')</a></li>
<li><a href="/borrow/ia/$(ocaid)?ref=ol&action=request&format=pdf">$_('Request pdf')</a></li>
<li><a href="/borrow/ia/$(ocaid)?ref=ol&action=request&format=daisy">$_('Request daisy')</a></li>
</ul>
<br>

$if user_loan:
$:macros.ReadButton(ocaid, loan=user_loan, listen=listen)
$ return_url = doc.url().rsplit('/', 1)[0] + '/do_return/borrow'
Expand Down Expand Up @@ -122,35 +132,6 @@
$if secondary_action:
$:macros.BookPreview(ocaid, linkback=not no_index)

$elif is_edition and (('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'):
$ btn_count = ctx.get('donate_count', 1)
$ modal_id = "donate-modal-%d" % btn_count
<a href="$(sponsorship['sponsor_url'])"
class="cta-btn cta-btn--sponsor dialog--open"
aria-controls="$modal_id"
data-id-num="$btn_count"
data-ol-link-track="CTAClick|Sponsor">$_('Donate Book')</a>
$ isbn_13 = doc.get_isbn13()
$ asin = None
$if doc.get('identifiers'):
$if doc.identifiers.get('amazon'):
$ asin = doc.identifiers.amazon[0]

$if not asin:
$ asin = doc.get_isbn10()

$:macros.DonateModal(doc, modal_id, ids={'isbn': isbn_13, 'asin': asin, 'prices': True})
$putctx('donate_count', btn_count + 1)
$if sponsorship_help:
<p>
$_("We don't have this book yet. Can you donate it to the Lending Library?")
<a href="https://openlibrary.org/bookdrive" target="_blank">$_('Learn More')</a>
</p>
$else:
$:macros.NotInLibrary(work_key)

$elif ocaid and availability.get('is_previewable') and book_provider.short_name == 'ia':
$:macros.BookPreview(ocaid, linkback=not no_index)
$if secondary_action:
Expand Down
13 changes: 12 additions & 1 deletion openlibrary/plugins/upstream/borrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,18 @@ def POST(self, key):
redirect_url += '&_autoReadAloud=' + i._autoReadAloud
raise web.seeother(redirect_url)

if action == 'return':
if action == "request":
try:
return requests.post(
config.get('pd_slack'),
headers={"Content-type": "application/json"},
json={
"text": f"{user.email} requested https://archive.org/details/{edition.ocaid} in {i.format}"
},
)
except Exception as e:
return e
elif action == 'return':
lending.s3_loan_api(edition.ocaid, s3_keys, action='return_loan')
stats.increment('ol.loans.return')
edition.update_loan_status()
Expand Down