Skip to content

Commit 03b7664

Browse files
committed
simplify params
1 parent 347f72a commit 03b7664

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

openlibrary/fastapi/partials.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,8 @@ async def partials_endpoint(
6464
return AffiliateLinksPartial(data=parsed_data).generate()
6565

6666
elif _component == "BPListsSection":
67-
# Use separate query parameters
68-
return BookPageListsPartial(
69-
data={"workId": workId, "editionId": editionId}
70-
).generate()
67+
# Pass parameters directly - much simpler!
68+
return BookPageListsPartial(workId=workId, editionId=editionId).generate()
7169

7270
elif _component == "FulltextSearchSuggestion":
7371
# data is just a string, not JSON

openlibrary/plugins/openlibrary/partials.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -303,21 +303,19 @@ def generate(self) -> dict:
303303
class BookPageListsPartial(PartialDataHandler):
304304
"""Handler for rendering the book page "Lists" section"""
305305

306-
def __init__(self, data: dict | None = None):
307-
if data is None:
308-
self.i = web.input(workId="", editionId="")
309-
self.data = {
310-
"workId": self.i.workId,
311-
"editionId": self.i.editionId,
312-
}
306+
def __init__(self, workId: str = "", editionId: str = ""):
307+
if not workId and not editionId:
308+
# Only read from web.input if no params provided
309+
i = web.input(workId="", editionId="")
310+
self.workId = i.workId
311+
self.editionId = i.editionId
313312
else:
314-
self.data = data
313+
self.workId = workId
314+
self.editionId = editionId
315315

316316
def generate(self) -> dict:
317317
results: dict = {"partials": []}
318-
work_key = self.data.get("workId", "")
319-
edition_key = self.data.get("editionId", "")
320-
keys = [k for k in (work_key, edition_key) if k]
318+
keys = [k for k in (self.workId, self.editionId) if k]
321319

322320
# Do checks and render
323321
lists = get_lists(keys)

0 commit comments

Comments
 (0)