1
0
mirror of https://github.com/janeczku/calibre-web synced 2024-12-30 12:00:31 +00:00

Format seriesindex everywhere to 2 digits

This commit is contained in:
Ozzie Isaacs 2024-10-18 20:24:49 +02:00
parent 94df767c28
commit c40c8a2255
12 changed files with 28 additions and 14 deletions

View File

@ -111,14 +111,15 @@ def yesno(value, yes, no):
@jinjia.app_template_filter('formatfloat')
def formatfloat(value, decimals=1):
value = 0 if not value else value
if not value:
return value
formated_value = ('{0:.' + str(decimals) + 'f}').format(value)
if formated_value.endswith('.' + "0" * decimals):
formated_value = formated_value.rstrip('0').rstrip('.')
return formated_value
@jinjia.app_template_filter('formatseriesindex')
'''@jinjia.app_template_filter('formatseriesindex')
def formatseriesindex_filter(series_index):
if series_index:
try:
@ -129,6 +130,7 @@ def formatseriesindex_filter(series_index):
except (ValueError, TypeError):
return series_index
return 0
'''
@jinjia.app_template_filter('escapedlink')

View File

@ -685,6 +685,17 @@ function ratingFormatter(value, row) {
return (value/2);
}
function seriesIndexFormatter(value, row) {
if (!value) {
return value;
}
formated_value = Number(value).toFixed(2);
if (formated_value.endsWith(".00")) {
formated_value = parseInt(formated_value).toString();
}
return formated_value;
}
/* Do some hiding disabling after user list is loaded */
function loadSuccess() {
@ -849,6 +860,7 @@ function BookCheckboxChange(checkbox, userId, field) {
},
success: handleListServerResponse
});
console.log("test");
}

View File

@ -71,7 +71,7 @@
<a href="{{url_for('web.books_list', data='series', sort_param='stored', book_id=entry.Books.series[0].id )}}">
{{entry.Books.series[0].name}}
</a>
({{entry.Books.series_index|formatseriesindex}})
({{entry.Books.series_index|formatfloat(2)}})
</p>
{% endif %}
{% if entry.Books.ratings.__len__() > 0 %}
@ -122,7 +122,7 @@
<a href="{{url_for('web.books_list', data='series', sort_param='stored', book_id=entry.series[0].id )}}">
{{entry.series[0].name}}
</a>
({{entry.series_index|formatseriesindex}})
({{entry.series_index|formatfloat(2)}})
</p>
{% endif %}
<div class="rating">

View File

@ -108,7 +108,7 @@
</div>
<div class="form-group">
<label for="series_index">{{_('Series ID')}}</label>
<input type="number" step="0.01" min="0" placeholder="1" class="form-control" name="series_index" id="series_index" value="{{book.series_index}}">
<input type="number" step="0.01" min="0" placeholder="1" class="form-control" name="series_index" id="series_index" value="{{book.series_index|formatfloat(2)}}">
</div>
<div class="form-group">
<label for="rating">{{_('Rating')}}</label>

View File

@ -66,7 +66,7 @@
{{ text_table_row('authors', _('Enter Authors'),_('Authors'), true, true) }}
{{ text_table_row('tags', _('Enter Categories'),_('Categories'), false, true) }}
{{ text_table_row('series', _('Enter Series'),_('Series'), false, true) }}
<th data-field="series_index" id="series_index" data-visible="{{visiblility.get('series_index')}}" data-edit-validate="{{ _('This Field is Required') }}" data-sortable="true" {% if current_user.role_edit() %} data-editable-type="number" data-editable-placeholder="1" data-editable-step="0.01" data-editable-min="0" data-editable-url="{{ url_for('edit-book.edit_list_book', param='series_index')}}" data-edit="true" data-editable-title="{{_('Enter Title')}}"{% endif %}>{{_('Series Index')}}</th>
<th data-field="series_index" id="series_index" data-visible="{{visiblility.get('series_index')}}" data-formatter="seriesIndexFormatter" data-edit-validate="{{ _('This Field is Required') }}" data-sortable="true" {% if current_user.role_edit() %} data-editable-type="number" data-editable-placeholder="1" data-editable-step="0.01" data-editable-min="0" data-editable-url="{{ url_for('edit-book.edit_list_book', param='series_index')}}" data-edit="true" data-editable-title="{{_('Enter Title')}}"{% endif %}>{{_('Series Index')}}</th>
{{ text_table_row('languages', _('Enter Languages'),_('Languages'), false, true) }}
<!--th data-field="pubdate" data-type="date" data-visible="{{visiblility.get('pubdate')}}" data-viewformat="dd.mm.yyyy" id="pubdate" data-sortable="true">{{_('Publishing Date')}}</th-->
{{ text_table_row('publishers', _('Enter Publishers'),_('Publishers'), false, true) }}

View File

@ -147,7 +147,7 @@
</div>
{% endif %}
{% if entry.series|length > 0 %}
<p>{{ _("Book %(index)s of %(range)s", index=entry.series_index | formatfloat(2), range=(url_for('web.books_list', data='series', sort_param='stored', book_id=entry.series[0].id)|escapedlink(entry.series[0].name))|safe) }}</p>
<p>{{ _("Book %(index)s of %(range)s", index=entry.series_index|formatfloat(2), range=(url_for('web.books_list', data='series', sort_param='stored', book_id=entry.series[0].id)|escapedlink(entry.series[0].name))|safe) }}</p>
{% endif %}

View File

@ -42,7 +42,7 @@
<a href="{{url_for('web.books_list', data='series', sort_param='stored', book_id=entry.Books.series[0].id )}}">
{{entry.Books.series[0].name}}
</a>
({{entry.Books.series_index|formatseriesindex}})
({{entry.Books.series_index|formatfloat(2)}})
</p>
{% endif %}
{% if entry.Books.ratings.__len__() > 0 %}
@ -132,7 +132,7 @@
{% else %}
<span>{{entry.Books.series[0].name}}</span>
{% endif %}
({{entry.Books.series_index|formatseriesindex}})
({{entry.Books.series_index|formatfloat(2)}})
</p>
{% endif %}
{% if entry.Books.ratings.__len__() > 0 %}

View File

@ -59,7 +59,7 @@
</div>
{% endif %}
{% if entry.series|length > 0 %}
<p>{{_("Book %(index)s of %(range)s", index=entry.series_index | formatfloat(2), range=(url_for('web.books_list', data='series', sort_param='stored', book_id=entry.series[0].id)|escapedlink(entry.series[0].name))|safe)}}</p>
<p>{{_("Book %(index)s of %(range)s", index=entry.series_index|formatfloat(2), range=(url_for('web.books_list', data='series', sort_param='stored', book_id=entry.series[0].id)|escapedlink(entry.series[0].name))|safe)}}</p>
{% endif %}

View File

@ -82,7 +82,7 @@
<a href="{{url_for('web.books_list', data='series', sort_param='stored', book_id=entry.Books.series[0].id )}}">
{{entry.Books.series[0].name}}
</a>
({{entry.Books.series_index|formatseriesindex}})
({{entry.Books.series_index|formatfloat(2)}})
</p>
{% endif %}

View File

@ -70,7 +70,7 @@
<a href="{{url_for('web.books_list', data='series', sort_param='stored', book_id=entry.Books.series[0].id )}}">
{{entry.Books.series[0].name}}
</a>
({{entry.Books.series_index|formatseriesindex}})
({{entry.Books.series_index|formatfloat(2)}})
</p>
{% endif %}
{% if entry.Books.ratings.__len__() > 0 %}

View File

@ -20,7 +20,7 @@
{{entry['Books']['title']}}
{% if entry['Books']['series']|length > 0 %}
<br>
{{entry['Books']['series_index']}} - {{entry['Books']['series'][0].name}}
{{entry['Books']['series_index']|formatfloat(2)}} - {{entry['Books']['series'][0].name}}
{% endif %}
<br>
{% for author in entry['Books']['author'] %}

View File

@ -45,7 +45,7 @@
<a href="{{url_for('web.books_list', data='series', sort_param='stored', book_id=entry.Books.series[0].id )}}">
{{entry.Books.series[0].name}}
</a>
({{entry.Books.series_index}})
({{entry.Books.series_index|formatfloat(2)}})
</p>
{% endif %}
</div>