Skip to content

Commit c70aac7

Browse files
committed
Pass published_in along with carousel partials request
1 parent 0983954 commit c70aac7

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

openlibrary/plugins/openlibrary/js/carousel/Carousel.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ export class Carousel {
154154
pageMode: loadMore.pageMode,
155155
hasFulltextOnly: loadMore.hasFulltextOnly,
156156
secondaryAction: loadMore.secondaryAction,
157-
key: loadMore.key
157+
key: loadMore.key,
158+
...loadMore.extraParams
158159
});
159160
this.appendLoadingSlide();
160161
$.ajax({url: url, type: 'GET'})

openlibrary/plugins/openlibrary/partials.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from openlibrary.plugins.openlibrary.lists import get_user_lists
1515
from openlibrary.plugins.upstream.checkins import get_reading_goals
1616
from openlibrary.plugins.worksearch.code import do_search, work_search
17-
from openlibrary.plugins.worksearch.subjects import get_subject
17+
from openlibrary.plugins.worksearch.subjects import date_range_to_publish_year_filter, get_subject
1818
from openlibrary.views.loanstats import get_trending_books
1919

2020

@@ -189,8 +189,10 @@ def _do_subjects_query(self, params: dict) -> list:
189189
pseudoKey = params.get("q", "")
190190
offset = int(params.get("page", 1))
191191
limit = int(params.get("limit", 18))
192+
published_in = params.get("published_in", "")
193+
publish_year = date_range_to_publish_year_filter(published_in)
192194

193-
subject = get_subject(pseudoKey, offset=offset, limit=limit)
195+
subject = get_subject(pseudoKey, offset=offset, limit=limit, publish_year=publish_year)
194196
return subject.get("works", [])
195197

196198

openlibrary/plugins/worksearch/subjects.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,8 @@ def GET(self, key):
112112
if i.get('has_fulltext') == 'true':
113113
filters['has_fulltext'] = 'true'
114114

115-
if i.get('published_in'):
116-
if '-' in i.published_in:
117-
begin, end = i.published_in.split('-', 1)
118-
119-
if safeint(begin, None) is not None and safeint(end, None) is not None:
120-
filters['publish_year'] = f'[{begin} TO {end}]'
121-
else:
122-
y = safeint(i.published_in, None)
123-
if y is not None:
124-
filters['publish_year'] = i.published_in
115+
if publish_year_filter := date_range_to_publish_year_filter(i.get('published_in')):
116+
filters['publish_year'] = publish_year_filter
125117

126118
subject_results = get_subject(
127119
key,
@@ -142,6 +134,19 @@ def process_key(self, key):
142134
return key
143135

144136

137+
def date_range_to_publish_year_filter(published_in: str) -> str:
138+
if published_in:
139+
if '-' in published_in:
140+
begin, end = published_in.split('-', 1)
141+
if safeint(begin, None) is not None and safeint(end, None) is not None:
142+
return f'[{begin} TO {end}]'
143+
else:
144+
year = safeint(published_in, None)
145+
if year is not None:
146+
return published_in
147+
return ''
148+
149+
145150
SubjectType = Literal["subject", "place", "person", "time"]
146151

147152
SubjectPseudoKey = str

0 commit comments

Comments
 (0)