Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Dec 5, 2023
1 parent d0c1ffc commit 00141c8
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions openlibrary/plugins/upstream/mybooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@ def render(
elif is_logged_in_user and self.key == "loan_history":
account = OpenLibraryAccount.get(username=logged_in_username)
s3_keys = web.ctx.site.store.get(account._key).get('s3_keys')
template_data = self.process_loan_history_data(page=page, s3_keys=s3_keys)
template_data = self.process_loan_history_data(
page=page, s3_keys=s3_keys
)

return render['account/books'](
docs=template_data.get('editions', []),
Expand All @@ -312,7 +314,7 @@ def render(
q=q,
results_per_page=template_data['limit'],
show_next=template_data['show_next'],
page=template_data.get('page', '')
page=template_data.get('page', ''),
)

else:
Expand Down Expand Up @@ -366,8 +368,7 @@ def process_loan_history_data(self, page: int, s3_keys: dict[str, str]):
ocaids = [loan_record['identifier'] for loan_record in loan_history]
availability = get_availability_of_ocaids(ocaids)
loan_history_map = {
loan_record['identifier']: loan_record
for loan_record in loan_history
loan_record['identifier']: loan_record for loan_record in loan_history
}
editions = web.ctx.site.get_many(
[
Expand All @@ -379,15 +380,14 @@ def process_loan_history_data(self, page: int, s3_keys: dict[str, str]):

# Handle case where no loaned books on this page are in OL and there are more pages.
if not editions and show_next:
return self.process_loan_history_data(page=page+1, s3_keys=s3_keys)
return self.process_loan_history_data(page=page + 1, s3_keys=s3_keys)

for i, ed in enumerate(editions):
if ed.ocaid in ocaids:
# attach availability and loan to edition
editions[i].availability = availability.get(ed.ocaid)
editions[i].loan = loan_history_map[ed.ocaid]


template_data = {
'editions': editions,
'doc_count': len(loan_history_map),
Expand All @@ -398,7 +398,6 @@ def process_loan_history_data(self, page: int, s3_keys: dict[str, str]):

return template_data


def _prepare_data(
self,
logged_in_user,
Expand Down

0 comments on commit 00141c8

Please sign in to comment.