Server: Add an option to control the number of books displayed per page in the browser (Preferences->Sharing over the net->Advanced). Fixes #1715283 [[Enhancement] Control # of Books Output to Browser](https://bugs.launchpad.net/calibre/+bug/1715283)

This commit is contained in:
Kovid Goyal 2017-09-19 10:17:30 +05:30
parent 545443190e
commit 2b92691c68
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 10 additions and 7 deletions

View File

@ -115,9 +115,6 @@ def get_translations():
return _cached_translations
DEFAULT_NUMBER_OF_BOOKS = 50
def custom_list_template():
ans = getattr(custom_list_template, 'ans', None)
if ans is None:
@ -152,6 +149,7 @@ def basic_interface_data(ctx, rd):
'icon_map': icon_map(),
'icon_path': ctx.url_for('/icon', which=''),
'custom_list_template': getattr(ctx, 'custom_list_template', None) or custom_list_template(),
'num_per_page': rd.opts.num_per_page,
}
ans['library_map'], ans['default_library_id'] = ctx.library_info(rd)
return ans
@ -224,7 +222,7 @@ def books(ctx, rd):
'''
ans = {}
try:
num = int(rd.query.get('num', DEFAULT_NUMBER_OF_BOOKS))
num = int(rd.query.get('num', rd.opts.num_per_page))
except Exception:
raise HTTPNotFound('Invalid number of books: %r' % rd.query.get('num'))
library_id, db, sorts, orders, vl = get_basic_query_data(ctx, rd)
@ -256,7 +254,7 @@ def interface_data(ctx, rd):
ans['library_id'], db, sorts, orders, vl = get_basic_query_data(ctx, rd)
ans['user_session_data'] = ud
try:
num = int(rd.query.get('num', DEFAULT_NUMBER_OF_BOOKS))
num = int(rd.query.get('num', rd.opts.num_per_page))
except Exception:
raise HTTPNotFound('Invalid number of books: %r' % rd.query.get('num'))
ans.update(get_library_init_data(ctx, rd, db, num, sorts, orders, vl))
@ -274,7 +272,7 @@ def more_books(ctx, rd):
db, library_id = get_library_data(ctx, rd)[:2]
try:
num = int(rd.query.get('num', DEFAULT_NUMBER_OF_BOOKS))
num = int(rd.query.get('num', rd.opts.num_per_page))
except Exception:
raise HTTPNotFound('Invalid number of books: %r' % rd.query.get('num'))
try:
@ -327,7 +325,7 @@ def get_books(ctx, rd):
'''
library_id, db, sorts, orders, vl = get_basic_query_data(ctx, rd)
try:
num = int(rd.query.get('num', DEFAULT_NUMBER_OF_BOOKS))
num = int(rd.query.get('num', rd.opts.num_per_page))
except Exception:
raise HTTPNotFound('Invalid number of books: %r' % rd.query.get('num'))
searchq = rd.query.get('search', '')

View File

@ -84,6 +84,10 @@ raw_options = (
'url_prefix', None,
_('Useful if you wish to run this server behind a reverse proxy. For example use, /calibre as the URL prefix.'),
_('Number of books to show in a single page'),
'num_per_page', 50,
_('The number of books to show in a single page in the browser.'),
_('Advertise OPDS feeds via BonJour'),
'use_bonjour', True,
_('Advertise the OPDS feeds via the BonJour service, so that OPDS based'

View File

@ -166,6 +166,7 @@ default_interface_data = {
'icon_map': {},
'icon_path': '',
'custom_list_template': None,
'num_per_page': 50,
}
def get_interface_data():