mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix various minor issues with the new API in the content server
This commit is contained in:
parent
4a423ddaae
commit
fa02915eb9
@ -1483,7 +1483,7 @@ class Cache(object):
|
|||||||
if hasattr(f, 'get_books_for_val'):
|
if hasattr(f, 'get_books_for_val'):
|
||||||
# Composite field
|
# Composite field
|
||||||
return f.get_books_for_val(item_id_or_composite_value, self._get_metadata, self._all_book_ids())
|
return f.get_books_for_val(item_id_or_composite_value, self._get_metadata, self._all_book_ids())
|
||||||
return self._books_for_field(f.name, item_id_or_composite_value)
|
return self._books_for_field(f.name, int(item_id_or_composite_value))
|
||||||
|
|
||||||
@read_api
|
@read_api
|
||||||
def find_identical_books(self, mi, search_restriction='', book_ids=None):
|
def find_identical_books(self, mi, search_restriction='', book_ids=None):
|
||||||
|
@ -127,6 +127,9 @@ class View(object):
|
|||||||
book_id = id_or_index if index_is_id else self._map_filtered[id_or_index]
|
book_id = id_or_index if index_is_id else self._map_filtered[id_or_index]
|
||||||
return self._field_getters[loc](book_id)
|
return self._field_getters[loc](book_id)
|
||||||
|
|
||||||
|
def sanitize_sort_field_name(self, field):
|
||||||
|
return sanitize_sort_field_name(self.field_metadata, field)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def field_metadata(self):
|
def field_metadata(self):
|
||||||
return self.cache.field_metadata
|
return self.cache.field_metadata
|
||||||
@ -154,6 +157,9 @@ class View(object):
|
|||||||
for book_id in sorted(self._map):
|
for book_id in sorted(self._map):
|
||||||
yield book_id
|
yield book_id
|
||||||
|
|
||||||
|
def tablerow_for_id(self, book_id):
|
||||||
|
return TableRow(book_id, self)
|
||||||
|
|
||||||
def get_field_map_field(self, row, col, index_is_id=True):
|
def get_field_map_field(self, row, col, index_is_id=True):
|
||||||
'''
|
'''
|
||||||
Supports the legacy FIELD_MAP interface for getting metadata. Do not use
|
Supports the legacy FIELD_MAP interface for getting metadata. Do not use
|
||||||
|
@ -194,7 +194,7 @@ class Endpoint(object): # {{{
|
|||||||
if 'json' not in eself.mimetype:
|
if 'json' not in eself.mimetype:
|
||||||
sort_val = None
|
sort_val = None
|
||||||
cookie = cherrypy.request.cookie
|
cookie = cherrypy.request.cookie
|
||||||
if cookie.has_key(eself.sort_cookie_name):
|
if eself.sort_cookie_name in cookie:
|
||||||
sort_val = cookie[eself.sort_cookie_name].value
|
sort_val = cookie[eself.sort_cookie_name].value
|
||||||
kwargs[eself.sort_kwarg] = sort_val
|
kwargs[eself.sort_kwarg] = sort_val
|
||||||
|
|
||||||
@ -523,8 +523,6 @@ class BrowseServer(object):
|
|||||||
items = '\n\n'.join(items)
|
items = '\n\n'.join(items)
|
||||||
items = u'<div id="groups">\n{0}</div>'.format(items)
|
items = u'<div id="groups">\n{0}</div>'.format(items)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if cats:
|
if cats:
|
||||||
script = 'toplevel();category(%s);'%script
|
script = 'toplevel();category(%s);'%script
|
||||||
else:
|
else:
|
||||||
@ -586,12 +584,11 @@ class BrowseServer(object):
|
|||||||
datatype, self.opts.url_prefix)
|
datatype, self.opts.url_prefix)
|
||||||
return json.dumps(entries, ensure_ascii=True)
|
return json.dumps(entries, ensure_ascii=True)
|
||||||
|
|
||||||
|
|
||||||
@Endpoint()
|
@Endpoint()
|
||||||
def browse_catalog(self, category=None, category_sort=None):
|
def browse_catalog(self, category=None, category_sort=None):
|
||||||
'Entry point for top-level, categories and sub-categories'
|
'Entry point for top-level, categories and sub-categories'
|
||||||
prefix = '' if self.is_wsgi else self.opts.url_prefix
|
prefix = '' if self.is_wsgi else self.opts.url_prefix
|
||||||
if category == None:
|
if category is None:
|
||||||
ans = self.browse_toplevel()
|
ans = self.browse_toplevel()
|
||||||
elif category == 'newest':
|
elif category == 'newest':
|
||||||
raise cherrypy.InternalRedirect(prefix +
|
raise cherrypy.InternalRedirect(prefix +
|
||||||
@ -670,6 +667,9 @@ class BrowseServer(object):
|
|||||||
ids = self.db.get_books_for_category(q, cid)
|
ids = self.db.get_books_for_category(q, cid)
|
||||||
ids = [x for x in ids if x in all_ids]
|
ids = [x for x in ids if x in all_ids]
|
||||||
|
|
||||||
|
if hasattr(self.db, 'new_api'):
|
||||||
|
items = [self.db.data.tablerow_for_id(x) for x in ids]
|
||||||
|
else:
|
||||||
items = [self.db.data._data[x] for x in ids]
|
items = [self.db.data._data[x] for x in ids]
|
||||||
if category == 'newest':
|
if category == 'newest':
|
||||||
list_sort = 'timestamp'
|
list_sort = 'timestamp'
|
||||||
@ -770,7 +770,7 @@ class BrowseServer(object):
|
|||||||
if fmts and fmt:
|
if fmts and fmt:
|
||||||
other_fmts = [x for x in fmts if x.lower() != fmt.lower()]
|
other_fmts = [x for x in fmts if x.lower() != fmt.lower()]
|
||||||
if other_fmts:
|
if other_fmts:
|
||||||
ofmts = [u'<a href="{4}/get/{0}/{1}_{2}.{0}" title="{3}">{3}</a>'\
|
ofmts = [u'<a href="{4}/get/{0}/{1}_{2}.{0}" title="{3}">{3}</a>'
|
||||||
.format(f, fname, id_, f.upper(),
|
.format(f, fname, id_, f.upper(),
|
||||||
self.opts.url_prefix) for f in
|
self.opts.url_prefix) for f in
|
||||||
other_fmts]
|
other_fmts]
|
||||||
@ -783,7 +783,7 @@ class BrowseServer(object):
|
|||||||
if fmt:
|
if fmt:
|
||||||
href = self.opts.url_prefix + '/get/%s/%s_%d.%s'%(
|
href = self.opts.url_prefix + '/get/%s/%s_%d.%s'%(
|
||||||
fmt, fname, id_, fmt)
|
fmt, fname, id_, fmt)
|
||||||
rt = xml(_('Read %(title)s in the %(fmt)s format')% \
|
rt = xml(_('Read %(title)s in the %(fmt)s format')%
|
||||||
{'title':args['title'], 'fmt':fmt.upper()}, True)
|
{'title':args['title'], 'fmt':fmt.upper()}, True)
|
||||||
|
|
||||||
args['get_button'] = \
|
args['get_button'] = \
|
||||||
@ -809,7 +809,6 @@ class BrowseServer(object):
|
|||||||
|
|
||||||
summs.append(self.browse_summary_template.format(**args))
|
summs.append(self.browse_summary_template.format(**args))
|
||||||
|
|
||||||
|
|
||||||
raw = json.dumps('\n'.join(summs), ensure_ascii=True)
|
raw = json.dumps('\n'.join(summs), ensure_ascii=True)
|
||||||
return raw
|
return raw
|
||||||
|
|
||||||
@ -829,7 +828,7 @@ class BrowseServer(object):
|
|||||||
args['get_url'] = ''
|
args['get_url'] = ''
|
||||||
args['formats'] = ''
|
args['formats'] = ''
|
||||||
if fmts:
|
if fmts:
|
||||||
ofmts = [u'<a href="{4}/get/{0}/{1}_{2}.{0}" title="{3}">{3}</a>'\
|
ofmts = [u'<a href="{4}/get/{0}/{1}_{2}.{0}" title="{3}">{3}</a>'
|
||||||
.format(xfmt, fname, id_, xfmt.upper(),
|
.format(xfmt, fname, id_, xfmt.upper(),
|
||||||
self.opts.url_prefix) for xfmt in fmts]
|
self.opts.url_prefix) for xfmt in fmts]
|
||||||
ofmts = ', '.join(ofmts)
|
ofmts = ', '.join(ofmts)
|
||||||
@ -842,7 +841,7 @@ class BrowseServer(object):
|
|||||||
field not in displayed_custom_fields:
|
field not in displayed_custom_fields:
|
||||||
continue
|
continue
|
||||||
if m['datatype'] == 'comments' or field == 'comments' or (
|
if m['datatype'] == 'comments' or field == 'comments' or (
|
||||||
m['datatype'] == 'composite' and \
|
m['datatype'] == 'composite' and
|
||||||
m['display'].get('contains_html', False)):
|
m['display'].get('contains_html', False)):
|
||||||
val = mi.get(field, '')
|
val = mi.get(field, '')
|
||||||
if val and val.strip():
|
if val and val.strip():
|
||||||
@ -924,15 +923,16 @@ class BrowseServer(object):
|
|||||||
return self.browse_template('').format(
|
return self.browse_template('').format(
|
||||||
title='', script='book();', main=ans)
|
title='', script='book();', main=ans)
|
||||||
|
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
# Search {{{
|
# Search {{{
|
||||||
@Endpoint(sort_type='list')
|
@Endpoint(sort_type='list')
|
||||||
def browse_search(self, query='', list_sort=None):
|
def browse_search(self, query='', list_sort=None):
|
||||||
if isbytestring(query):
|
if isbytestring(query):
|
||||||
query = query.decode('UTF-8')
|
query = query.decode('UTF-8')
|
||||||
ids = self.db.search_getting_ids(query.strip(), self.search_restriction)
|
ids = self.db.search_getting_ids(query.strip(), self.search_restriction)
|
||||||
|
if hasattr(self.db, 'new_api'):
|
||||||
|
items = [self.db.data.tablerow_for_id(x) for x in ids]
|
||||||
|
else:
|
||||||
items = [self.db.data._data[x] for x in ids]
|
items = [self.db.data._data[x] for x in ids]
|
||||||
sort = self.browse_sort_book_list(items, list_sort)
|
sort = self.browse_sort_book_list(items, list_sort)
|
||||||
ids = [x[0] for x in items]
|
ids = [x[0] for x in items]
|
||||||
@ -945,3 +945,4 @@ class BrowseServer(object):
|
|||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user