mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
OPDS pagination now works correctly
This commit is contained in:
parent
311d56f16d
commit
d697d4dfbc
@ -40,3 +40,6 @@ def server_config(defaults=None):
|
|||||||
'This affects Stanza, WordPlayer, etc. integration.'))
|
'This affects Stanza, WordPlayer, etc. integration.'))
|
||||||
return c
|
return c
|
||||||
|
|
||||||
|
def main():
|
||||||
|
from calibre.library.server.main import main
|
||||||
|
return main()
|
||||||
|
@ -80,7 +80,7 @@ START_LINK = partial(NAVLINK, rel='start')
|
|||||||
UP_LINK = partial(NAVLINK, rel='up')
|
UP_LINK = partial(NAVLINK, rel='up')
|
||||||
FIRST_LINK = partial(NAVLINK, rel='first')
|
FIRST_LINK = partial(NAVLINK, rel='first')
|
||||||
LAST_LINK = partial(NAVLINK, rel='last')
|
LAST_LINK = partial(NAVLINK, rel='last')
|
||||||
NEXT_LINK = partial(NAVLINK, rel='next')
|
NEXT_LINK = partial(NAVLINK, rel='next', title='Next')
|
||||||
PREVIOUS_LINK = partial(NAVLINK, rel='previous')
|
PREVIOUS_LINK = partial(NAVLINK, rel='previous')
|
||||||
|
|
||||||
def html_to_lxml(raw):
|
def html_to_lxml(raw):
|
||||||
@ -123,7 +123,7 @@ def ACQUISITION_ENTRY(item, version, FM, updated):
|
|||||||
id_ = 'urn:%s:%s'%(idm, item[FM['uuid']])
|
id_ = 'urn:%s:%s'%(idm, item[FM['uuid']])
|
||||||
ans = E.entry(TITLE(title), E.author(E.name(authors)), ID(id_),
|
ans = E.entry(TITLE(title), E.author(E.name(authors)), ID(id_),
|
||||||
UPDATED(updated))
|
UPDATED(updated))
|
||||||
if extra:
|
if len(extra):
|
||||||
ans.append(E.content(extra, type='xhtml'))
|
ans.append(E.content(extra, type='xhtml'))
|
||||||
formats = item[FM['formats']]
|
formats = item[FM['formats']]
|
||||||
if formats:
|
if formats:
|
||||||
@ -163,18 +163,18 @@ class Feed(object): # {{{
|
|||||||
ID(id_),
|
ID(id_),
|
||||||
UPDATED(updated),
|
UPDATED(updated),
|
||||||
SEARCH_LINK(self.base_href),
|
SEARCH_LINK(self.base_href),
|
||||||
START_LINK(self.base_href)
|
START_LINK(href=self.base_href)
|
||||||
)
|
)
|
||||||
if up_link:
|
if up_link:
|
||||||
self.root.append(UP_LINK(up_link))
|
self.root.append(UP_LINK(href=up_link))
|
||||||
if first_link:
|
if first_link:
|
||||||
self.root.append(FIRST_LINK(first_link))
|
self.root.append(FIRST_LINK(href=first_link))
|
||||||
if last_link:
|
if last_link:
|
||||||
self.root.append(LAST_LINK(last_link))
|
self.root.append(LAST_LINK(href=last_link))
|
||||||
if next_link:
|
if next_link:
|
||||||
self.root.append(NEXT_LINK(next_link))
|
self.root.append(NEXT_LINK(href=next_link))
|
||||||
if previous_link:
|
if previous_link:
|
||||||
self.root.append(PREVIOUS_LINK(previous_link))
|
self.root.append(PREVIOUS_LINK(href=previous_link))
|
||||||
if subtitle:
|
if subtitle:
|
||||||
self.root.insert(1, SUBTITLE(subtitle))
|
self.root.insert(1, SUBTITLE(subtitle))
|
||||||
|
|
||||||
@ -233,16 +233,16 @@ class OPDSOffsets(object):
|
|||||||
offset = 0
|
offset = 0
|
||||||
if offset >= total:
|
if offset >= total:
|
||||||
raise cherrypy.HTTPError(404, 'Invalid offset: %r'%offset)
|
raise cherrypy.HTTPError(404, 'Invalid offset: %r'%offset)
|
||||||
|
last_allowed_index = total - 1
|
||||||
|
last_current_index = offset + delta - 1
|
||||||
self.offset = offset
|
self.offset = offset
|
||||||
self.next_offset = offset + delta
|
self.next_offset = last_current_index + 1
|
||||||
if self.next_offset >= total:
|
if self.next_offset > last_allowed_index:
|
||||||
self.next_offset = -1
|
|
||||||
if self.next_offset >= total:
|
|
||||||
self.next_offset = -1
|
self.next_offset = -1
|
||||||
self.previous_offset = self.offset - delta
|
self.previous_offset = self.offset - delta
|
||||||
if self.previous_offset < 0:
|
if self.previous_offset < 0:
|
||||||
self.previous_offset = 0
|
self.previous_offset = 0
|
||||||
self.last_offset = total - delta
|
self.last_offset = last_allowed_index - delta
|
||||||
if self.last_offset < 0:
|
if self.last_offset < 0:
|
||||||
self.last_offset = 0
|
self.last_offset = 0
|
||||||
|
|
||||||
@ -273,7 +273,8 @@ class OPDSServer(object):
|
|||||||
self.sort(items, sort_by, ascending)
|
self.sort(items, sort_by, ascending)
|
||||||
max_items = self.opts.max_opds_items
|
max_items = self.opts.max_opds_items
|
||||||
offsets = OPDSOffsets(offset, max_items, len(items))
|
offsets = OPDSOffsets(offset, max_items, len(items))
|
||||||
items = items[offsets.offset:offsets.next_offset]
|
items = items[offsets.offset:offsets.offset+max_items]
|
||||||
|
print 111, (len(items))
|
||||||
return str(AcquisitionFeed(self.db.last_modified(), id_, items, offsets,
|
return str(AcquisitionFeed(self.db.last_modified(), id_, items, offsets,
|
||||||
page_url, up_url, version, self.db.FIELD_MAP))
|
page_url, up_url, version, self.db.FIELD_MAP))
|
||||||
|
|
||||||
@ -289,7 +290,8 @@ class OPDSServer(object):
|
|||||||
ids = self.search_cache(query)
|
ids = self.search_cache(query)
|
||||||
except:
|
except:
|
||||||
raise cherrypy.HTTPError(404, 'Search: %r not understood'%query)
|
raise cherrypy.HTTPError(404, 'Search: %r not understood'%query)
|
||||||
return self.get_opds_acquisition_feed(ids, offset, '/search/'+query,
|
page_url = url_for('opdssearch', version, query=query)
|
||||||
|
return self.get_opds_acquisition_feed(ids, offset, page_url,
|
||||||
url_for('opds', version), 'calibre-search:'+query,
|
url_for('opds', version), 'calibre-search:'+query,
|
||||||
version=version)
|
version=version)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user