mirror of
https://github.com/janeczku/calibre-web
synced 2024-12-18 22:20:30 +00:00
On master: Order of language count in /language (fixes #2200)
This commit is contained in:
parent
7640ac1b3b
commit
5ed3b1cf53
27
cps/db.py
27
cps/db.py
@ -796,18 +796,27 @@ class CalibreDB():
|
|||||||
return result[offset:limit_all], result_count, pagination
|
return result[offset:limit_all], result_count, pagination
|
||||||
|
|
||||||
# Creates for all stored languages a translated speaking name in the array for the UI
|
# Creates for all stored languages a translated speaking name in the array for the UI
|
||||||
def speaking_language(self, languages=None, return_all_languages=False, reverse_order=False):
|
def speaking_language(self, languages=None, return_all_languages=False, with_count=False, reverse_order=False):
|
||||||
from . import get_locale
|
from . import get_locale
|
||||||
|
|
||||||
if not languages:
|
if not languages:
|
||||||
languages = self.session.query(Languages) \
|
if with_count:
|
||||||
.join(books_languages_link) \
|
languages = self.session.query(Languages, func.count('books_languages_link.book'))\
|
||||||
.join(Books) \
|
.join(books_languages_link).join(Books)\
|
||||||
.filter(self.common_filters(return_all_languages=return_all_languages)) \
|
.filter(self.common_filters(return_all_languages=return_all_languages)) \
|
||||||
.group_by(text('books_languages_link.lang_code')).all()
|
.group_by(text('books_languages_link.lang_code')).all()
|
||||||
for lang in languages:
|
for lang in languages:
|
||||||
lang.name = isoLanguages.get_language_name(get_locale(), lang.lang_code)
|
lang[0].name = isoLanguages.get_language_name(get_locale(), lang[0].lang_code)
|
||||||
return sorted(languages, key=lambda x: x.name, reverse=reverse_order)
|
return sorted(languages, key=lambda x: x[0].name, reverse=reverse_order)
|
||||||
|
else:
|
||||||
|
languages = self.session.query(Languages) \
|
||||||
|
.join(books_languages_link) \
|
||||||
|
.join(Books) \
|
||||||
|
.filter(self.common_filters(return_all_languages=return_all_languages)) \
|
||||||
|
.group_by(text('books_languages_link.lang_code')).all()
|
||||||
|
for lang in languages:
|
||||||
|
lang.name = isoLanguages.get_language_name(get_locale(), lang.lang_code)
|
||||||
|
return sorted(languages, key=lambda x: x.name, reverse=reverse_order)
|
||||||
|
|
||||||
|
|
||||||
def update_title_sort(self, config, conn=None):
|
def update_title_sort(self, config, conn=None):
|
||||||
|
@ -57,6 +57,7 @@ def get_language_name(locale, lang_code):
|
|||||||
return get_language_names(locale)[lang_code]
|
return get_language_names(locale)[lang_code]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
log.error('Missing translation for language name: {}'.format(lang_code))
|
log.error('Missing translation for language name: {}'.format(lang_code))
|
||||||
|
return "Unknown"
|
||||||
|
|
||||||
|
|
||||||
def get_language_codes(locale, language_names, remainder=None):
|
def get_language_codes(locale, language_names, remainder=None):
|
||||||
|
@ -21,9 +21,9 @@
|
|||||||
</div>
|
</div>
|
||||||
<div id="second" class="col-xs-12 col-sm-6">
|
<div id="second" class="col-xs-12 col-sm-6">
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<div class="row" data-id="{% if lang.name %}{{lang.name}}{% else %}{{lang[0].name}}{% endif %}">
|
<div class="row" data-id="{{lang[0].name}}">
|
||||||
<div class="col-xs-2 col-sm-2 col-md-1" align="left"><span class="badge">{{lang_counter[loop.index0].bookcount}}</span></div>
|
<div class="col-xs-2 col-sm-2 col-md-1" align="left"><span class="badge">{{lang[1]}}</span></div>
|
||||||
<div class="col-xs-10 col-sm-10 col-md-11"><a id="list_{{loop.index0}}" href="{{url_for('web.books_list', book_id=lang.lang_code, data=data, sort_param='new')}}">{{lang.name}}</a></div>
|
<div class="col-xs-10 col-sm-10 col-md-11"><a id="list_{{loop.index0}}" href="{{url_for('web.books_list', book_id=lang[0].lang_code, data=data, sort_param='new')}}">{{lang[0].name}}</a></div>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
16
cps/web.py
16
cps/web.py
@ -1016,22 +1016,14 @@ def formats_list():
|
|||||||
@login_required_if_no_ano
|
@login_required_if_no_ano
|
||||||
def language_overview():
|
def language_overview():
|
||||||
if current_user.check_visibility(constants.SIDEBAR_LANGUAGE) and current_user.filter_language() == u"all":
|
if current_user.check_visibility(constants.SIDEBAR_LANGUAGE) and current_user.filter_language() == u"all":
|
||||||
if current_user.get_view_property('language', 'dir') == 'desc':
|
order_no = 0 if current_user.get_view_property('language', 'dir') == 'desc' else 1
|
||||||
order = db.Languages.lang_code.desc()
|
|
||||||
order_no = 0
|
|
||||||
else:
|
|
||||||
order = db.Languages.lang_code.asc()
|
|
||||||
order_no = 1
|
|
||||||
charlist = list()
|
charlist = list()
|
||||||
languages = calibre_db.speaking_language(reverse_order=not order_no)
|
languages = calibre_db.speaking_language(reverse_order=not order_no, with_count=True)
|
||||||
for lang in languages:
|
for lang in languages:
|
||||||
upper_lang = lang.name[0].upper()
|
upper_lang = lang[0].name[0].upper()
|
||||||
if upper_lang not in charlist:
|
if upper_lang not in charlist:
|
||||||
charlist.append(upper_lang)
|
charlist.append(upper_lang)
|
||||||
lang_counter = calibre_db.session.query(db.books_languages_link,
|
return render_title_template('languages.html', languages=languages,
|
||||||
func.count('books_languages_link.book').label('bookcount')).group_by(
|
|
||||||
text('books_languages_link.lang_code')).all()
|
|
||||||
return render_title_template('languages.html', languages=languages, lang_counter=lang_counter,
|
|
||||||
charlist=charlist, title=_(u"Languages"), page="langlist",
|
charlist=charlist, title=_(u"Languages"), page="langlist",
|
||||||
data="language", order=order_no)
|
data="language", order=order_no)
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user