This commit is contained in:
Kovid Goyal 2013-09-03 11:17:44 +05:30
parent 0fd842dd9a
commit b1f17de41c
4 changed files with 11 additions and 16 deletions

View File

@ -23,7 +23,7 @@ from calibre.library.server import custom_fields_to_display
from calibre import force_unicode, isbytestring 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',
@ -55,7 +55,7 @@ class Endpoint(object): # {{{
return wrapper return wrapper
# }}} # }}}
def category_icon(category, meta): # {{{ def category_icon(category, meta): # {{{
if category in category_icon_map: if category in category_icon_map:
icon = category_icon_map[category] icon = category_icon_map[category]
elif meta['is_custom']: elif meta['is_custom']:
@ -117,7 +117,6 @@ class AjaxServer(object):
# Search # Search
connect('ajax_search', base_href+'/search', self.ajax_search) connect('ajax_search', base_href+'/search', self.ajax_search)
# 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):
@ -214,7 +213,7 @@ 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')
except: except:
raise cherrypy.HTTPError(404, 'No book with id: %r'%book_id) raise cherrypy.HTTPError(404, 'No book with id: %r'%book_id)
@ -291,7 +290,6 @@ class AjaxServer(object):
displayed_custom_fields = custom_fields_to_display(self.db) displayed_custom_fields = custom_fields_to_display(self.db)
for category in sorted(categories, key=lambda x: sort_key(getter(x))): for category in sorted(categories, key=lambda x: sort_key(getter(x))):
if len(categories[category]) == 0: if len(categories[category]) == 0:
continue continue
@ -314,7 +312,7 @@ class AjaxServer(object):
ans = [{'url':k, 'name':v[0], 'icon':v[1], 'is_category':True} ans = [{'url':k, 'name':v[0], 'icon':v[1], 'is_category':True}
for k, v in ans.iteritems()] for k, v in ans.iteritems()]
ans.sort(key=lambda x: sort_key(x['name'])) ans.sort(key=lambda x: sort_key(x['name']))
for name, url, icon in [ for name, url, icon in [
(_('All books'), 'allbooks', 'book.png'), (_('All books'), 'allbooks', 'book.png'),
(_('Newest'), 'newest', 'forward.png'), (_('Newest'), 'newest', 'forward.png'),
]: ]:
@ -505,7 +503,6 @@ class AjaxServer(object):
'items':items, 'items':items,
} }
# }}} # }}}
# Books in the specified category {{{ # Books in the specified category {{{
@ -569,7 +566,6 @@ class AjaxServer(object):
'book_ids':ids 'book_ids':ids
} }
# }}} # }}}
# Search {{{ # Search {{{

View File

@ -31,7 +31,6 @@ class Cache(object):
self._search_cache[search] = old self._search_cache[search] = old
return self._search_cache[search][1] return self._search_cache[search][1]
def categories_cache(self, restrict_to=frozenset([])): def categories_cache(self, restrict_to=frozenset([])):
base_restriction = self.search_cache('') base_restriction = self.search_cache('')
if restrict_to: if restrict_to:

View File

@ -23,12 +23,12 @@ from calibre.utils.date import utcfromtimestamp, as_local_time
from calibre.utils.filenames import ascii_filename from calibre.utils.filenames import ascii_filename
from calibre.utils.icu import sort_key from calibre.utils.icu import sort_key
def CLASS(*args, **kwargs): # class is a reserved word in Python def CLASS(*args, **kwargs): # class is a reserved word in Python
kwargs['class'] = ' '.join(args) kwargs['class'] = ' '.join(args)
return kwargs return kwargs
def build_search_box(num, search, sort, order, prefix): # {{{ def build_search_box(num, search, sort, order, prefix): # {{{
div = DIV(id='search_box') div = DIV(id='search_box')
form = FORM('Show ', method='get', action=prefix+'/mobile') form = FORM('Show ', method='get', action=prefix+'/mobile')
form.set('accept-charset', 'UTF-8') form.set('accept-charset', 'UTF-8')
@ -69,7 +69,7 @@ def build_search_box(num, search, sort, order, prefix): # {{{
return div return div
# }}} # }}}
def build_navigation(start, num, total, url_base): # {{{ def build_navigation(start, num, total, url_base): # {{{
end = min((start+num-1), total) end = min((start+num-1), total)
tagline = SPAN('Books %d to %d of %d'%(start, end, total), tagline = SPAN('Books %d to %d of %d'%(start, end, total),
style='display: block; text-align: center;') style='display: block; text-align: center;')
@ -150,7 +150,7 @@ def build_index(books, num, search, sort, order, start, total, url_base, CKEYS,
first = SPAN(u'\u202f%s %s by %s' % (book['title'], series, first = SPAN(u'\u202f%s %s by %s' % (book['title'], series,
book['authors']), CLASS('first-line')) book['authors']), CLASS('first-line'))
div.append(first) div.append(first)
second = SPAN(u'%s - %s %s %s' % ( book['size'], second = SPAN(u'%s - %s %s %s' % (book['size'],
book['timestamp'], book['timestamp'],
tags, ctext), CLASS('second-line')) tags, ctext), CLASS('second-line'))
div.append(second) div.append(second)
@ -173,9 +173,9 @@ def build_index(books, num, search, sort, order, start, total, url_base, CKEYS,
LINK(rel='stylesheet', type='text/css', LINK(rel='stylesheet', type='text/css',
href=prefix+'/mobile/style.css'), href=prefix+'/mobile/style.css'),
LINK(rel='apple-touch-icon', href="/static/calibre.png") LINK(rel='apple-touch-icon', href="/static/calibre.png")
), # End head ), # End head
body body
) # End html ) # End html
class MobileServer(object): class MobileServer(object):

View File

@ -134,7 +134,7 @@ class XMLServer(object):
updated = self.db.last_modified() updated = self.db.last_modified()
kwargs = dict( kwargs = dict(
start = str(start), start=str(start),
updated=updated.strftime('%Y-%m-%dT%H:%M:%S+00:00'), updated=updated.strftime('%Y-%m-%dT%H:%M:%S+00:00'),
total=str(len(ids)), total=str(len(ids)),
num=str(len(books))) num=str(len(books)))