-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
QueryCarousel.html
31 lines (26 loc) · 1.32 KB
/
QueryCarousel.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
$def with(query, title=None, sort='new', key='', limit=20, search=False, has_fulltext_only=True, url=None)
$# Takes following parameters
$# * query (str) -- Any arbitrary Open Library search query, e.g. subject:"Textbooks"
$# * title (str) -- A title to show above the carousel (links to /search?q=query)
$# * sort (str) -- optional sort param defined within work_search.py `work_search`
$# * key (str) -- unique name of the carousel in analytics
$# * limit (int) -- initial number of books to pull
$# * search (bool) -- whether to include search within collection
$# Enable search within this query
$if search:
<form action="/search" class="olform pagesearchbox">
<input type="hidden" name="q" value="$query"/>
$if has_fulltext_only:
<input type="hidden" name="has_fulltext" value="true"/>
<input type="text" placeholder="Search collection" name="q2"/>
<input type="submit"/>
</form>
$code:
params = { 'q': query }
url = url or "/search?" + urlencode(params)
if has_fulltext_only:
params['has_fulltext'] = 'true'
results = work_search(params, sort=sort, limit=limit)
books = [storage(b) for b in (results.get('docs', []))]
load_more = {"url": "/search.json?" + urlencode(params), "limit": limit }
$:render_template("books/custom_carousel", books=books, title=title, url=url, key=key, load_more=load_more)