mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #6549 (calibre content server fails when listing content of user categories)
Also fix a problem where publishers were not working in user-defined categories
This commit is contained in:
parent
a2e959c7c9
commit
8493206301
@ -21,7 +21,7 @@ class Item:
|
||||
return 'name=%s, label=%s, index=%s, exists='%(self.name, self.label, self.index, self.exists)
|
||||
|
||||
class TagCategories(QDialog, Ui_TagCategories):
|
||||
category_labels_orig = ['', 'authors', 'series', 'publishers', 'tags']
|
||||
category_labels_orig = ['', 'authors', 'series', 'publisher', 'tags']
|
||||
|
||||
def __init__(self, window, db, on_category=None):
|
||||
QDialog.__init__(self, window)
|
||||
|
@ -99,17 +99,19 @@ def html_to_lxml(raw):
|
||||
raw = etree.tostring(root, encoding=None)
|
||||
return etree.fromstring(raw)
|
||||
|
||||
def CATALOG_ENTRY(item, base_href, version, updated, ignore_count=False):
|
||||
def CATALOG_ENTRY(item, item_kind, base_href, version, updated,
|
||||
ignore_count=False, add_kind=False):
|
||||
id_ = 'calibre:category:'+item.name
|
||||
iid = 'N' + item.name
|
||||
if item.id is not None:
|
||||
iid = 'I' + str(item.id)
|
||||
iid += ':'+item_kind
|
||||
link = NAVLINK(href = base_href + '/' + hexlify(iid))
|
||||
count = _('%d books')%item.count
|
||||
count = (_('%d books') if item.count > 1 else _('%d book'))%item.count
|
||||
if ignore_count:
|
||||
count = ''
|
||||
return E.entry(
|
||||
TITLE(item.name),
|
||||
TITLE(item.name + ('' if not add_kind else ' (%s)'%item_kind)),
|
||||
ID(id_),
|
||||
UPDATED(updated),
|
||||
E.content(count, type='text'),
|
||||
@ -265,15 +267,30 @@ class AcquisitionFeed(NavFeed):
|
||||
|
||||
class CategoryFeed(NavFeed):
|
||||
|
||||
def __init__(self, items, which, id_, updated, version, offsets, page_url, up_url):
|
||||
def __init__(self, items, which, id_, updated, version, offsets, page_url, up_url, db):
|
||||
NavFeed.__init__(self, id_, updated, version, offsets, page_url, up_url)
|
||||
base_href = self.base_href + '/category/' + hexlify(which)
|
||||
ignore_count = False
|
||||
if which == 'search':
|
||||
ignore_count = True
|
||||
uc = None
|
||||
if which.endswith(':'):
|
||||
# We have a user category. Translate back to original categories
|
||||
uc = {}
|
||||
try:
|
||||
ucs = db.prefs['user_categories']
|
||||
ucs = ucs.get(which[:-1])
|
||||
for name, category, index in ucs:
|
||||
uc[name] = category
|
||||
except:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
uc = None
|
||||
for item in items:
|
||||
self.root.append(CATALOG_ENTRY(item, base_href, version, updated,
|
||||
ignore_count=ignore_count))
|
||||
if uc: which = uc.get(item.name, which)
|
||||
self.root.append(CATALOG_ENTRY(item, which, base_href, version,
|
||||
updated, ignore_count=ignore_count,
|
||||
add_kind=uc is not None))
|
||||
|
||||
class CategoryGroupFeed(NavFeed):
|
||||
|
||||
@ -418,7 +435,7 @@ class OPDSServer(object):
|
||||
cherrypy.response.headers['Content-Type'] = 'application/atom+xml'
|
||||
|
||||
return str(CategoryFeed(items, category, id_, updated, version, offsets,
|
||||
page_url, up_url))
|
||||
page_url, up_url, self.db))
|
||||
|
||||
|
||||
def opds_navcatalog(self, which=None, version=0, offset=0):
|
||||
@ -461,7 +478,7 @@ class OPDSServer(object):
|
||||
offsets = OPDSOffsets(offset, max_items, len(items))
|
||||
items = list(items)[offsets.offset:offsets.offset+max_items]
|
||||
ans = CategoryFeed(items, which, id_, updated, version, offsets,
|
||||
page_url, up_url)
|
||||
page_url, up_url, self.db)
|
||||
else:
|
||||
class Group:
|
||||
def __init__(self, text, count):
|
||||
@ -507,7 +524,9 @@ class OPDSServer(object):
|
||||
which = which[1:]
|
||||
if type_ == 'I':
|
||||
try:
|
||||
which = int(which)
|
||||
p = which.index(':')
|
||||
category = which[p+1:]
|
||||
which = int(which[:p])
|
||||
except:
|
||||
raise cherrypy.HTTPError(404, 'Tag %r not found'%which)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user