From c40c8a2255803d86cfe58b4356729cac1566a995 Mon Sep 17 00:00:00 2001
From: Ozzie Isaacs
Date: Fri, 18 Oct 2024 20:24:49 +0200
Subject: [PATCH] Format seriesindex everywhere to 2 digits
---
cps/jinjia.py | 6 ++++--
cps/static/js/table.js | 12 ++++++++++++
cps/templates/author.html | 4 ++--
cps/templates/book_edit.html | 2 +-
cps/templates/book_table.html | 2 +-
cps/templates/detail.html | 2 +-
cps/templates/index.html | 4 ++--
cps/templates/listenmp3.html | 2 +-
cps/templates/search.html | 2 +-
cps/templates/shelf.html | 2 +-
cps/templates/shelf_order.html | 2 +-
cps/templates/shelfdown.html | 2 +-
12 files changed, 28 insertions(+), 14 deletions(-)
diff --git a/cps/jinjia.py b/cps/jinjia.py
index 39c7f20c..3db3e88a 100644
--- a/cps/jinjia.py
+++ b/cps/jinjia.py
@@ -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')
diff --git a/cps/static/js/table.js b/cps/static/js/table.js
index 36361c3c..7f210eb1 100644
--- a/cps/static/js/table.js
+++ b/cps/static/js/table.js
@@ -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");
}
diff --git a/cps/templates/author.html b/cps/templates/author.html
index 1e02597c..a01bb40b 100644
--- a/cps/templates/author.html
+++ b/cps/templates/author.html
@@ -71,7 +71,7 @@
{{entry.Books.series[0].name}}
- ({{entry.Books.series_index|formatseriesindex}})
+ ({{entry.Books.series_index|formatfloat(2)}})
{% endif %}
{% if entry.Books.ratings.__len__() > 0 %}
@@ -122,7 +122,7 @@
{{entry.series[0].name}}
- ({{entry.series_index|formatseriesindex}})
+ ({{entry.series_index|formatfloat(2)}})
{% endif %}
diff --git a/cps/templates/book_edit.html b/cps/templates/book_edit.html
index 94dbbb3b..1e4a1bc4 100644
--- a/cps/templates/book_edit.html
+++ b/cps/templates/book_edit.html
@@ -108,7 +108,7 @@
-
+
diff --git a/cps/templates/book_table.html b/cps/templates/book_table.html
index 16836b7b..1a0806b0 100644
--- a/cps/templates/book_table.html
+++ b/cps/templates/book_table.html
@@ -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) }}
-
{{_('Series Index')}} |
+ {{_('Series Index')}} |
{{ text_table_row('languages', _('Enter Languages'),_('Languages'), false, true) }}
{{ text_table_row('publishers', _('Enter Publishers'),_('Publishers'), false, true) }}
diff --git a/cps/templates/detail.html b/cps/templates/detail.html
index b52a231b..1eb81e30 100644
--- a/cps/templates/detail.html
+++ b/cps/templates/detail.html
@@ -147,7 +147,7 @@
{% endif %}
{% if entry.series|length > 0 %}
- {{ _("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) }}
+ {{ _("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) }}
{% endif %}
diff --git a/cps/templates/index.html b/cps/templates/index.html
index 38fbb284..8e1446c5 100644
--- a/cps/templates/index.html
+++ b/cps/templates/index.html
@@ -42,7 +42,7 @@
{{entry.Books.series[0].name}}
- ({{entry.Books.series_index|formatseriesindex}})
+ ({{entry.Books.series_index|formatfloat(2)}})
{% endif %}
{% if entry.Books.ratings.__len__() > 0 %}
@@ -132,7 +132,7 @@
{% else %}
{{entry.Books.series[0].name}}
{% endif %}
- ({{entry.Books.series_index|formatseriesindex}})
+ ({{entry.Books.series_index|formatfloat(2)}})
{% endif %}
{% if entry.Books.ratings.__len__() > 0 %}
diff --git a/cps/templates/listenmp3.html b/cps/templates/listenmp3.html
index 58466937..6cd8c607 100644
--- a/cps/templates/listenmp3.html
+++ b/cps/templates/listenmp3.html
@@ -59,7 +59,7 @@
{% endif %}
{% if entry.series|length > 0 %}
- {{_("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)}}
+ {{_("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)}}
{% endif %}
diff --git a/cps/templates/search.html b/cps/templates/search.html
index 9a7af2d8..b406ebe3 100644
--- a/cps/templates/search.html
+++ b/cps/templates/search.html
@@ -82,7 +82,7 @@
{{entry.Books.series[0].name}}
- ({{entry.Books.series_index|formatseriesindex}})
+ ({{entry.Books.series_index|formatfloat(2)}})
{% endif %}
diff --git a/cps/templates/shelf.html b/cps/templates/shelf.html
index d9c4ec27..0c25b2cd 100644
--- a/cps/templates/shelf.html
+++ b/cps/templates/shelf.html
@@ -70,7 +70,7 @@
{{entry.Books.series[0].name}}
- ({{entry.Books.series_index|formatseriesindex}})
+ ({{entry.Books.series_index|formatfloat(2)}})
{% endif %}
{% if entry.Books.ratings.__len__() > 0 %}
diff --git a/cps/templates/shelf_order.html b/cps/templates/shelf_order.html
index ee90fd47..5ec7a4b1 100644
--- a/cps/templates/shelf_order.html
+++ b/cps/templates/shelf_order.html
@@ -20,7 +20,7 @@
{{entry['Books']['title']}}
{% if entry['Books']['series']|length > 0 %}
- {{entry['Books']['series_index']}} - {{entry['Books']['series'][0].name}}
+ {{entry['Books']['series_index']|formatfloat(2)}} - {{entry['Books']['series'][0].name}}
{% endif %}
{% for author in entry['Books']['author'] %}
diff --git a/cps/templates/shelfdown.html b/cps/templates/shelfdown.html
index cb183a03..ecf5b252 100644
--- a/cps/templates/shelfdown.html
+++ b/cps/templates/shelfdown.html
@@ -45,7 +45,7 @@
{{entry.Books.series[0].name}}
- ({{entry.Books.series_index}})
+ ({{entry.Books.series_index|formatfloat(2)}})
{% endif %}