mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Attempt at content server with subcategories.
This commit is contained in:
parent
0ace21eb7e
commit
976acd25a7
@ -342,6 +342,7 @@ class BrowseServer(object):
|
|||||||
return category_meta[x]['name'].lower()
|
return category_meta[x]['name'].lower()
|
||||||
|
|
||||||
displayed_custom_fields = custom_fields_to_display(self.db)
|
displayed_custom_fields = custom_fields_to_display(self.db)
|
||||||
|
uc_displayed = set()
|
||||||
for category in sorted(categories, key=lambda x: sort_key(getter(x))):
|
for category in sorted(categories, key=lambda x: sort_key(getter(x))):
|
||||||
if len(categories[category]) == 0:
|
if len(categories[category]) == 0:
|
||||||
continue
|
continue
|
||||||
@ -361,7 +362,19 @@ class BrowseServer(object):
|
|||||||
icon = category_icon_map['user:']
|
icon = category_icon_map['user:']
|
||||||
else:
|
else:
|
||||||
icon = 'blank.png'
|
icon = 'blank.png'
|
||||||
cats.append((meta['name'], category, icon))
|
|
||||||
|
if meta['kind'] == 'user':
|
||||||
|
dot = category.find('.')
|
||||||
|
if dot > 0:
|
||||||
|
cat = category[:dot]
|
||||||
|
if cat not in uc_displayed:
|
||||||
|
cats.append((meta['name'][:dot-1], cat, icon))
|
||||||
|
uc_displayed.add(cat)
|
||||||
|
else:
|
||||||
|
cats.append((meta['name'], category, icon))
|
||||||
|
uc_displayed.add(category)
|
||||||
|
else:
|
||||||
|
cats.append((meta['name'], category, icon))
|
||||||
|
|
||||||
cats = [(u'<li><a title="{2} {0}" href="{3}/browse/category/{1}"> </a>'
|
cats = [(u'<li><a title="{2} {0}" href="{3}/browse/category/{1}"> </a>'
|
||||||
u'<img src="{3}{src}" alt="{0}" />'
|
u'<img src="{3}{src}" alt="{0}" />'
|
||||||
@ -394,12 +407,51 @@ class BrowseServer(object):
|
|||||||
category_name = category_meta[category]['name']
|
category_name = category_meta[category]['name']
|
||||||
datatype = category_meta[category]['datatype']
|
datatype = category_meta[category]['datatype']
|
||||||
|
|
||||||
|
uc_displayed = set()
|
||||||
|
cats = []
|
||||||
|
for ucat in sorted(categories.keys(), key=sort_key):
|
||||||
|
if len(categories[ucat]) == 0:
|
||||||
|
continue
|
||||||
|
if category == 'formats':
|
||||||
|
continue
|
||||||
|
meta = category_meta.get(ucat, None)
|
||||||
|
if meta is None:
|
||||||
|
continue
|
||||||
|
if meta['kind'] != 'user':
|
||||||
|
continue
|
||||||
|
cat_len = len(category)
|
||||||
|
if not (len(ucat) > cat_len and ucat.startswith(category+'.')):
|
||||||
|
continue
|
||||||
|
cat_len += 1
|
||||||
|
icon = category_icon_map['user:']
|
||||||
|
dot = ucat[cat_len:].find('.')
|
||||||
|
if dot > 0:
|
||||||
|
cat = ucat[cat_len:][:dot]
|
||||||
|
if cat not in uc_displayed:
|
||||||
|
cats.append((cat, ucat[:cat_len+dot], icon))
|
||||||
|
uc_displayed.add(cat)
|
||||||
|
else:
|
||||||
|
cats.append((meta['name'], ucat, icon))
|
||||||
|
uc_displayed.add(ucat)
|
||||||
|
|
||||||
|
cats = u'\n\n'.join(
|
||||||
|
[(u'<li><a title="{2} {0}" href="{3}/browse/category/{1}"> </a>'
|
||||||
|
u'<img src="{3}{src}" alt="{0}" />'
|
||||||
|
u'<span class="label">{0}</span>'
|
||||||
|
u'</li>')
|
||||||
|
.format(xml(x, True), xml(quote(y)), xml(_('Browse books by')),
|
||||||
|
self.opts.url_prefix, src='/browse/icon/'+z)
|
||||||
|
for x, y, z in cats])
|
||||||
|
if cats:
|
||||||
|
cats = (u'\n<div class="toplevel">\n'
|
||||||
|
'{0}</div>').format(cats)
|
||||||
|
script = 'toplevel();'
|
||||||
|
else:
|
||||||
|
script = 'true'
|
||||||
|
|
||||||
items = categories[category]
|
items = categories[category]
|
||||||
sort = self.browse_sort_categories(items, sort)
|
sort = self.browse_sort_categories(items, sort)
|
||||||
|
|
||||||
script = 'true'
|
|
||||||
|
|
||||||
if len(items) == 1:
|
if len(items) == 1:
|
||||||
# Only one item in category, go directly to book list
|
# Only one item in category, go directly to book list
|
||||||
prefix = '' if self.is_wsgi else self.opts.url_prefix
|
prefix = '' if self.is_wsgi else self.opts.url_prefix
|
||||||
@ -443,7 +495,10 @@ class BrowseServer(object):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
script = 'category(%s);'%script
|
if cats:
|
||||||
|
script = 'toplevel();category(%s);'%script
|
||||||
|
else:
|
||||||
|
script = 'category(%s);'%script
|
||||||
|
|
||||||
main = u'''
|
main = u'''
|
||||||
<div class="category">
|
<div class="category">
|
||||||
@ -453,7 +508,7 @@ class BrowseServer(object):
|
|||||||
{1}
|
{1}
|
||||||
</div>
|
</div>
|
||||||
'''.format(
|
'''.format(
|
||||||
xml(_('Browsing by')+': ' + category_name), items,
|
xml(_('Browsing by')+': ' + category_name), cats + items,
|
||||||
xml(_('Up'), True), self.opts.url_prefix)
|
xml(_('Up'), True), self.opts.url_prefix)
|
||||||
|
|
||||||
return self.browse_template(sort).format(title=category_name,
|
return self.browse_template(sort).format(title=category_name,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user