mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-01-26 14:05:11 +01: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
1 changed files with 13 additions and 0 deletions
|
|
@ -239,6 +239,8 @@ def add_routes(self, connect):
|
|||
self.browse_details)
|
||||
connect('browse_book', base_href+'/book/{id}',
|
||||
self.browse_book)
|
||||
connect('browse_random', base_href+'/random',
|
||||
self.browse_random)
|
||||
connect('browse_category_icon', base_href+'/icon/{name}',
|
||||
self.browse_icon)
|
||||
|
||||
|
|
@ -351,6 +353,7 @@ def browse_toplevel(self):
|
|||
cats = [
|
||||
(_('Newest'), 'newest', 'forward.png'),
|
||||
(_('All books'), 'allbooks', 'book.png'),
|
||||
(_('Random book'), 'randombook', 'random.png'),
|
||||
]
|
||||
|
||||
def getter(x):
|
||||
|
|
@ -599,6 +602,9 @@ def browse_catalog(self, category=None, category_sort=None):
|
|||
elif category == 'allbooks':
|
||||
raise cherrypy.InternalRedirect(prefix +
|
||||
'/browse/matches/allbooks/dummy')
|
||||
elif category == 'randombook':
|
||||
raise cherrypy.InternalRedirect(prefix +
|
||||
'/browse/random')
|
||||
else:
|
||||
ans = self.browse_category(category, category_sort)
|
||||
|
||||
|
|
@ -885,6 +891,13 @@ def browse_details(self, id=None):
|
|||
|
||||
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()
|
||||
def browse_book(self, id=None, category_sort=None):
|
||||
|
|
|
|||
Loading…
Reference in a new issue