mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
/browse: searching works
This commit is contained in:
parent
f7b3f6a442
commit
5d2fa2c5a4
@ -77,7 +77,7 @@
|
||||
</div>
|
||||
<div id="search_box">
|
||||
<form name="search_form" action="/browse/search" method="get" accept-charset="UTF-8">
|
||||
<input value="" type="text" title="Search"
|
||||
<input value="{initial_search}" type="text" title="Search" name="query"
|
||||
class="search_input" />
|
||||
<input type="submit" value="Search" title="Search" alt="Search" />
|
||||
</form>
|
||||
|
@ -18,7 +18,7 @@ from calibre.utils.filenames import ascii_filename
|
||||
from calibre.utils.config import prefs
|
||||
from calibre.library.comments import comments_to_html
|
||||
|
||||
def render_book_list(ids):
|
||||
def render_book_list(ids): # {{{
|
||||
pages = []
|
||||
num = len(ids)
|
||||
pos = 0
|
||||
@ -78,6 +78,8 @@ def render_book_list(ids):
|
||||
|
||||
return templ.format(_('Browsing %d books')%num, pages=rpages, navbar=navbar)
|
||||
|
||||
# }}}
|
||||
|
||||
def utf8(x): # {{{
|
||||
if isinstance(x, unicode):
|
||||
x = x.encode('utf-8')
|
||||
@ -184,10 +186,10 @@ class BrowseServer(object):
|
||||
base_href+'/booklist_page',
|
||||
self.browse_booklist_page)
|
||||
|
||||
connect('browse_search', base_href+'/search/{query}',
|
||||
connect('browse_search', base_href+'/search',
|
||||
self.browse_search)
|
||||
|
||||
def browse_template(self, sort, category=True):
|
||||
def browse_template(self, sort, category=True, initial_search=''):
|
||||
|
||||
def generate():
|
||||
scn = 'calibre_browse_server_sort_'
|
||||
@ -222,6 +224,7 @@ class BrowseServer(object):
|
||||
ans = ans.encode('utf-8')
|
||||
ans = ans.replace('{library_name}', xml(os.path.basename(lp)))
|
||||
ans = ans.replace('{library_path}', xml(lp, True))
|
||||
ans = ans.replace('{initial_search}', initial_search)
|
||||
return ans
|
||||
|
||||
if self.opts.develop:
|
||||
@ -495,8 +498,19 @@ class BrowseServer(object):
|
||||
# }}}
|
||||
|
||||
# Search {{{
|
||||
def browse_search(self, query=None):
|
||||
raise NotImplementedError()
|
||||
@Endpoint(sort_type='list')
|
||||
def browse_search(self, query='', list_sort=None):
|
||||
if isbytestring(query):
|
||||
query = query.decode('UTF-8')
|
||||
ids = self.db.search_getting_ids(query.strip(), self.search_restriction)
|
||||
items = [self.db.data._data[x] for x in ids]
|
||||
sort = self.browse_sort_book_list(items, list_sort)
|
||||
ids = [x[0] for x in items]
|
||||
html = render_book_list(ids)
|
||||
return self.browse_template(sort, category=False, initial_search=query).format(
|
||||
title=_('Matching books'),
|
||||
script='booklist();', main=html)
|
||||
|
||||
# }}}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user