mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Content server: Allow picking a random book by clicking the 'Random book' link on the start page. You can also refresh the random book page to get a new random book
This commit is contained in:
parent
e25cb884fa
commit
1bc7ddfdbf
@ -239,6 +239,8 @@ class BrowseServer(object):
|
|||||||
self.browse_details)
|
self.browse_details)
|
||||||
connect('browse_book', base_href+'/book/{id}',
|
connect('browse_book', base_href+'/book/{id}',
|
||||||
self.browse_book)
|
self.browse_book)
|
||||||
|
connect('browse_random', base_href+'/random',
|
||||||
|
self.browse_random)
|
||||||
connect('browse_category_icon', base_href+'/icon/{name}',
|
connect('browse_category_icon', base_href+'/icon/{name}',
|
||||||
self.browse_icon)
|
self.browse_icon)
|
||||||
|
|
||||||
@ -351,6 +353,7 @@ class BrowseServer(object):
|
|||||||
cats = [
|
cats = [
|
||||||
(_('Newest'), 'newest', 'forward.png'),
|
(_('Newest'), 'newest', 'forward.png'),
|
||||||
(_('All books'), 'allbooks', 'book.png'),
|
(_('All books'), 'allbooks', 'book.png'),
|
||||||
|
(_('Random book'), 'randombook', 'random.png'),
|
||||||
]
|
]
|
||||||
|
|
||||||
def getter(x):
|
def getter(x):
|
||||||
@ -599,6 +602,9 @@ class BrowseServer(object):
|
|||||||
elif category == 'allbooks':
|
elif category == 'allbooks':
|
||||||
raise cherrypy.InternalRedirect(prefix +
|
raise cherrypy.InternalRedirect(prefix +
|
||||||
'/browse/matches/allbooks/dummy')
|
'/browse/matches/allbooks/dummy')
|
||||||
|
elif category == 'randombook':
|
||||||
|
raise cherrypy.InternalRedirect(prefix +
|
||||||
|
'/browse/random')
|
||||||
else:
|
else:
|
||||||
ans = self.browse_category(category, category_sort)
|
ans = self.browse_category(category, category_sort)
|
||||||
|
|
||||||
@ -885,6 +891,13 @@ class BrowseServer(object):
|
|||||||
|
|
||||||
return json.dumps(ans, ensure_ascii=False)
|
return json.dumps(ans, ensure_ascii=False)
|
||||||
|
|
||||||
|
@Endpoint()
|
||||||
|
def browse_random(self, *args, **kwargs):
|
||||||
|
import random
|
||||||
|
book_id = random.choice(tuple(self.db.all_ids()))
|
||||||
|
ans = self.browse_render_details(book_id)
|
||||||
|
return self.browse_template('').format(
|
||||||
|
title='', script='book();', main=ans)
|
||||||
|
|
||||||
@Endpoint()
|
@Endpoint()
|
||||||
def browse_book(self, id=None, category_sort=None):
|
def browse_book(self, id=None, category_sort=None):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user