On master: Order of language count in /language (fixes #2200)
This commit is contained in:
parent
7640ac1b3b
commit
5ed3b1cf53
11
cps/db.py
11
cps/db.py
|
@ -796,10 +796,19 @@ 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:
|
||||||
|
if with_count:
|
||||||
|
languages = self.session.query(Languages, func.count('books_languages_link.book'))\
|
||||||
|
.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[0].name = isoLanguages.get_language_name(get_locale(), lang[0].lang_code)
|
||||||
|
return sorted(languages, key=lambda x: x[0].name, reverse=reverse_order)
|
||||||
|
else:
|
||||||
languages = self.session.query(Languages) \
|
languages = self.session.query(Languages) \
|
||||||
.join(books_languages_link) \
|
.join(books_languages_link) \
|
||||||
.join(Books) \
|
.join(Books) \
|
||||||
|
|
|
@ -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