mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Merge branch 'master' of https://github.com/cbhaley/calibre
This commit is contained in:
commit
dd6bbb1bf1
@ -24,6 +24,7 @@ from calibre import force_unicode, isbytestring
|
|||||||
from calibre.library.field_metadata import category_icon_map
|
from calibre.library.field_metadata import category_icon_map
|
||||||
|
|
||||||
class Endpoint(object): # {{{
|
class Endpoint(object): # {{{
|
||||||
|
|
||||||
'Manage mime-type json serialization, etc.'
|
'Manage mime-type json serialization, etc.'
|
||||||
|
|
||||||
def __init__(self, mimetype='application/json; charset=utf-8',
|
def __init__(self, mimetype='application/json; charset=utf-8',
|
||||||
@ -119,7 +120,7 @@ class AjaxServer(object):
|
|||||||
|
|
||||||
# Get book metadata {{{
|
# Get book metadata {{{
|
||||||
def ajax_book_to_json(self, book_id, get_category_urls=True,
|
def ajax_book_to_json(self, book_id, get_category_urls=True,
|
||||||
device_compatible=False):
|
device_compatible=False, device_for_template=None):
|
||||||
mi = self.db.get_metadata(book_id, index_is_id=True)
|
mi = self.db.get_metadata(book_id, index_is_id=True)
|
||||||
|
|
||||||
if not device_compatible:
|
if not device_compatible:
|
||||||
@ -191,12 +192,24 @@ class AjaxServer(object):
|
|||||||
else:
|
else:
|
||||||
series = ''
|
series = ''
|
||||||
data['_series_sort_'] = series
|
data['_series_sort_'] = series
|
||||||
|
if device_for_template:
|
||||||
|
import posixpath
|
||||||
|
from calibre.devices.utils import create_upload_path
|
||||||
|
from calibre.utils.filenames import ascii_filename as sanitize
|
||||||
|
from calibre.customize.ui import device_plugins
|
||||||
|
|
||||||
|
for device_class in device_plugins():
|
||||||
|
if device_class.__class__.__name__ == device_for_template:
|
||||||
|
template = device_class.save_template()
|
||||||
|
data['_filename_'] = create_upload_path(mi, book_id,
|
||||||
|
template, sanitize, path_type=posixpath)
|
||||||
|
break
|
||||||
|
|
||||||
return data, mi.last_modified
|
return data, mi.last_modified
|
||||||
|
|
||||||
@Endpoint(set_last_modified=False)
|
@Endpoint(set_last_modified=False)
|
||||||
def ajax_book(self, book_id, category_urls='true', id_is_uuid='false',
|
def ajax_book(self, book_id, category_urls='true', id_is_uuid='false',
|
||||||
device_compatible='false'):
|
device_compatible='false', device_for_template=None):
|
||||||
'''
|
'''
|
||||||
Return the metadata of the book as a JSON dictionary.
|
Return the metadata of the book as a JSON dictionary.
|
||||||
|
|
||||||
@ -213,7 +226,8 @@ class AjaxServer(object):
|
|||||||
book_id = int(book_id)
|
book_id = int(book_id)
|
||||||
data, last_modified = self.ajax_book_to_json(book_id,
|
data, last_modified = self.ajax_book_to_json(book_id,
|
||||||
get_category_urls=category_urls.lower()=='true',
|
get_category_urls=category_urls.lower()=='true',
|
||||||
device_compatible=device_compatible.lower()=='true')
|
device_compatible=device_compatible.lower()=='true',
|
||||||
|
device_for_template=device_for_template)
|
||||||
except:
|
except:
|
||||||
raise cherrypy.HTTPError(404, 'No book with id: %r'%book_id)
|
raise cherrypy.HTTPError(404, 'No book with id: %r'%book_id)
|
||||||
|
|
||||||
@ -223,7 +237,7 @@ class AjaxServer(object):
|
|||||||
return data
|
return data
|
||||||
|
|
||||||
@Endpoint(set_last_modified=False)
|
@Endpoint(set_last_modified=False)
|
||||||
def ajax_books(self, ids=None, category_urls='true', id_is_uuid='false'):
|
def ajax_books(self, ids=None, category_urls='true', id_is_uuid='false', device_for_template=None):
|
||||||
'''
|
'''
|
||||||
Return the metadata for a list of books specified as a comma separated
|
Return the metadata for a list of books specified as a comma separated
|
||||||
list of ids. The metadata is returned as a dictionary mapping ids to
|
list of ids. The metadata is returned as a dictionary mapping ids to
|
||||||
@ -250,7 +264,7 @@ class AjaxServer(object):
|
|||||||
for book_id in ids:
|
for book_id in ids:
|
||||||
try:
|
try:
|
||||||
data, last_modified = self.ajax_book_to_json(book_id,
|
data, last_modified = self.ajax_book_to_json(book_id,
|
||||||
get_category_urls=gcu)
|
get_category_urls=gcu, device_for_template=device_for_template)
|
||||||
except:
|
except:
|
||||||
ans[book_id] = None
|
ans[book_id] = None
|
||||||
else:
|
else:
|
||||||
@ -617,5 +631,4 @@ class AjaxServer(object):
|
|||||||
'book_ids':ids
|
'book_ids':ids
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user