mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
/browse: Fix sorting in book list views when server is run without --develop
This commit is contained in:
parent
a06618d4b1
commit
36c0079061
@ -200,46 +200,45 @@ class BrowseServer(object):
|
|||||||
# Templates {{{
|
# Templates {{{
|
||||||
def browse_template(self, sort, category=True, initial_search=''):
|
def browse_template(self, sort, category=True, initial_search=''):
|
||||||
|
|
||||||
def generate():
|
if not hasattr(self, '__browse_template__') or \
|
||||||
scn = 'calibre_browse_server_sort_'
|
self.opts.develop:
|
||||||
|
self.__browse_template__ = \
|
||||||
|
P('content_server/browse/browse.html', data=True).decode('utf-8')
|
||||||
|
|
||||||
if category:
|
ans = self.__browse_template__
|
||||||
sort_opts = [('rating', _('Average rating')), ('name',
|
scn = 'calibre_browse_server_sort_'
|
||||||
_('Name')), ('popularity', _('Popularity'))]
|
|
||||||
scn += 'category'
|
|
||||||
else:
|
|
||||||
scn += 'list'
|
|
||||||
fm = self.db.field_metadata
|
|
||||||
sort_opts, added = [], set([])
|
|
||||||
for x in fm.sortable_field_keys():
|
|
||||||
n = fm[x]['name']
|
|
||||||
if n not in added:
|
|
||||||
added.add(n)
|
|
||||||
sort_opts.append((x, n))
|
|
||||||
|
|
||||||
ans = P('content_server/browse/browse.html',
|
if category:
|
||||||
data=True).decode('utf-8')
|
sort_opts = [('rating', _('Average rating')), ('name',
|
||||||
ans = ans.replace('{sort_select_label}', xml(_('Sort by')+':'))
|
_('Name')), ('popularity', _('Popularity'))]
|
||||||
ans = ans.replace('{sort_cookie_name}', scn)
|
scn += 'category'
|
||||||
opts = ['<option %svalue="%s">%s</option>' % (
|
else:
|
||||||
'selected="selected" ' if k==sort else '',
|
scn += 'list'
|
||||||
xml(k), xml(n), ) for k, n in
|
fm = self.db.field_metadata
|
||||||
sorted(sort_opts, key=operator.itemgetter(1)) if k and n]
|
sort_opts, added = [], set([])
|
||||||
ans = ans.replace('{sort_select_options}', ('\n'+' '*20).join(opts))
|
for x in fm.sortable_field_keys():
|
||||||
lp = self.db.library_path
|
n = fm[x]['name']
|
||||||
if isbytestring(lp):
|
if n not in added:
|
||||||
lp = force_unicode(lp, filesystem_encoding)
|
added.add(n)
|
||||||
if isinstance(ans, unicode):
|
sort_opts.append((x, n))
|
||||||
ans = ans.encode('utf-8')
|
|
||||||
ans = ans.replace('{library_name}', xml(os.path.basename(lp)))
|
ans = ans.replace('{sort_select_label}', xml(_('Sort by')+':'))
|
||||||
ans = ans.replace('{library_path}', xml(lp, True))
|
ans = ans.replace('{sort_cookie_name}', scn)
|
||||||
ans = ans.replace('{initial_search}', initial_search)
|
opts = ['<option %svalue="%s">%s</option>' % (
|
||||||
return ans
|
'selected="selected" ' if k==sort else '',
|
||||||
|
xml(k), xml(n), ) for k, n in
|
||||||
|
sorted(sort_opts, key=operator.itemgetter(1)) if k and n]
|
||||||
|
ans = ans.replace('{sort_select_options}', ('\n'+' '*20).join(opts))
|
||||||
|
lp = self.db.library_path
|
||||||
|
if isbytestring(lp):
|
||||||
|
lp = force_unicode(lp, filesystem_encoding)
|
||||||
|
if isinstance(ans, unicode):
|
||||||
|
ans = ans.encode('utf-8')
|
||||||
|
ans = ans.replace('{library_name}', xml(os.path.basename(lp)))
|
||||||
|
ans = ans.replace('{library_path}', xml(lp, True))
|
||||||
|
ans = ans.replace('{initial_search}', initial_search)
|
||||||
|
return ans
|
||||||
|
|
||||||
if self.opts.develop:
|
|
||||||
return generate()
|
|
||||||
if not hasattr(self, '__browse_template__'):
|
|
||||||
self.__browse_template__ = generate()
|
|
||||||
return self.__browse_template__
|
return self.__browse_template__
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
Loading…
x
Reference in New Issue
Block a user