From a1a1292b41b364bdbe2fa2bce34f62972b1367a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Wed, 11 Jul 2018 08:50:11 -0400 Subject: [PATCH] Implementing page size selection in settings #67 --- bazarr.py | 66 +++++++++++++++++++++++------------------ get_general_settings.py | 6 ++-- update_db.py | 7 +++++ views/historymovies.tpl | 2 ++ views/historyseries.tpl | 2 ++ views/movies.tpl | 2 ++ views/series.tpl | 2 ++ views/settings.tpl | 26 ++++++++++++++++ views/system.tpl | 6 ++-- views/wantedmovies.tpl | 2 ++ views/wantedseries.tpl | 2 ++ 11 files changed, 90 insertions(+), 33 deletions(-) diff --git a/bazarr.py b/bazarr.py index 5eaa3db6c..c764993a0 100644 --- a/bazarr.py +++ b/bazarr.py @@ -1,4 +1,4 @@ -bazarr_version = '0.5.4' +bazarr_version = '0.5.5' import gc gc.enable() @@ -190,10 +190,11 @@ def series(): page = request.GET.page if page == "": page = "1" - offset = (int(page) - 1) * 15 - max_page = int(math.ceil(missing_count / 15.0)) + page_size = int(get_general_settings()[21]) + offset = (int(page) - 1) * page_size + max_page = int(math.ceil(missing_count / (page_size + 0.0))) - c.execute("SELECT tvdbId, title, path_substitution(path), languages, hearing_impaired, sonarrSeriesId, poster, audio_language FROM table_shows ORDER BY sortTitle ASC LIMIT 15 OFFSET ?", (offset,)) + c.execute("SELECT tvdbId, title, path_substitution(path), languages, hearing_impaired, sonarrSeriesId, poster, audio_language FROM table_shows ORDER BY sortTitle ASC LIMIT ? OFFSET ?", (page_size, offset,)) data = c.fetchall() c.execute("SELECT code2, name FROM table_settings_languages WHERE enabled = 1") languages = c.fetchall() @@ -202,7 +203,7 @@ def series(): c.execute("SELECT table_shows.sonarrSeriesId, COUNT(table_episodes.missing_subtitles) FROM table_shows LEFT JOIN table_episodes ON table_shows.sonarrSeriesId=table_episodes.sonarrSeriesId WHERE table_shows.languages IS NOT 'None' GROUP BY table_shows.sonarrSeriesId") total_subtitles_list = c.fetchall() c.close() - output = template('series', __file__=__file__, bazarr_version=bazarr_version, rows=data, missing_subtitles_list=missing_subtitles_list, total_subtitles_list=total_subtitles_list, languages=languages, missing_count=missing_count, page=page, max_page=max_page, base_url=base_url, single_language=single_language) + output = template('series', __file__=__file__, bazarr_version=bazarr_version, rows=data, missing_subtitles_list=missing_subtitles_list, total_subtitles_list=total_subtitles_list, languages=languages, missing_count=missing_count, page=page, max_page=max_page, base_url=base_url, single_language=single_language, page_size=page_size) return output @route(base_url + 'serieseditor') @@ -353,15 +354,16 @@ def movies(): page = request.GET.page if page == "": page = "1" - offset = (int(page) - 1) * 15 - max_page = int(math.ceil(missing_count / 15.0)) + page_size = int(get_general_settings()[21]) + offset = (int(page) - 1) * page_size + max_page = int(math.ceil(missing_count / (page_size + 0.0))) - c.execute("SELECT tmdbId, title, path_substitution(path), languages, hearing_impaired, radarrId, poster, audio_language FROM table_movies ORDER BY title ASC LIMIT 15 OFFSET ?", (offset,)) + c.execute("SELECT tmdbId, title, path_substitution(path), languages, hearing_impaired, radarrId, poster, audio_language FROM table_movies ORDER BY title ASC LIMIT ? OFFSET ?", (page_size, offset,)) data = c.fetchall() c.execute("SELECT code2, name FROM table_settings_languages WHERE enabled = 1") languages = c.fetchall() c.close() - output = template('movies', __file__=__file__, bazarr_version=bazarr_version, rows=data, languages=languages, missing_count=missing_count, page=page, max_page=max_page, base_url=base_url, single_language=single_language) + output = template('movies', __file__=__file__, bazarr_version=bazarr_version, rows=data, languages=languages, missing_count=missing_count, page=page, max_page=max_page, base_url=base_url, single_language=single_language, page_size=page_size) return output @route(base_url + 'movieseditor') @@ -510,8 +512,9 @@ def historyseries(): page = request.GET.page if page == "": page = "1" - offset = (int(page) - 1) * 15 - max_page = int(math.ceil(row_count / 15.0)) + page_size = int(get_general_settings()[21]) + offset = (int(page) - 1) * page_size + max_page = int(math.ceil(row_count / (page_size + 0.0))) now = datetime.now() today = [] @@ -528,11 +531,11 @@ def historyseries(): thisyear.append(datetime.fromtimestamp(stat[0]).date()) stats = [len(today), len(thisweek), len(thisyear), total] - c.execute("SELECT table_history.action, table_shows.title, table_episodes.season || 'x' || table_episodes.episode, table_episodes.title, table_history.timestamp, table_history.description, table_history.sonarrSeriesId FROM table_history LEFT JOIN table_shows on table_shows.sonarrSeriesId = table_history.sonarrSeriesId LEFT JOIN table_episodes on table_episodes.sonarrEpisodeId = table_history.sonarrEpisodeId ORDER BY id DESC LIMIT 15 OFFSET ?", (offset,)) + c.execute("SELECT table_history.action, table_shows.title, table_episodes.season || 'x' || table_episodes.episode, table_episodes.title, table_history.timestamp, table_history.description, table_history.sonarrSeriesId FROM table_history LEFT JOIN table_shows on table_shows.sonarrSeriesId = table_history.sonarrSeriesId LEFT JOIN table_episodes on table_episodes.sonarrEpisodeId = table_history.sonarrEpisodeId ORDER BY id DESC LIMIT ? OFFSET ?", (page_size, offset,)) data = c.fetchall() c.close() data = reversed(sorted(data, key=operator.itemgetter(4))) - return template('historyseries', __file__=__file__, bazarr_version=bazarr_version, rows=data, row_count=row_count, page=page, max_page=max_page, stats=stats, base_url=base_url) + return template('historyseries', __file__=__file__, bazarr_version=bazarr_version, rows=data, row_count=row_count, page=page, max_page=max_page, stats=stats, base_url=base_url, page_size=page_size) @route(base_url + 'historymovies') def historymovies(): @@ -545,8 +548,9 @@ def historymovies(): page = request.GET.page if page == "": page = "1" - offset = (int(page) - 1) * 15 - max_page = int(math.ceil(row_count / 15.0)) + page_size = int(get_general_settings()[21]) + offset = (int(page) - 1) * page_size + max_page = int(math.ceil(row_count / (page_size + 0.0))) now = datetime.now() today = [] @@ -563,11 +567,11 @@ def historymovies(): thisyear.append(datetime.fromtimestamp(stat[0]).date()) stats = [len(today), len(thisweek), len(thisyear), total] - c.execute("SELECT table_history_movie.action, table_movies.title, table_history_movie.timestamp, table_history_movie.description, table_history_movie.radarrId FROM table_history_movie LEFT JOIN table_movies on table_movies.radarrId = table_history_movie.radarrId ORDER BY id DESC LIMIT 15 OFFSET ?", (offset,)) + c.execute("SELECT table_history_movie.action, table_movies.title, table_history_movie.timestamp, table_history_movie.description, table_history_movie.radarrId FROM table_history_movie LEFT JOIN table_movies on table_movies.radarrId = table_history_movie.radarrId ORDER BY id DESC LIMIT ? OFFSET ?", (page_size, offset,)) data = c.fetchall() c.close() data = reversed(sorted(data, key=operator.itemgetter(2))) - return template('historymovies', __file__=__file__, bazarr_version=bazarr_version, rows=data, row_count=row_count, page=page, max_page=max_page, stats=stats, base_url=base_url) + return template('historymovies', __file__=__file__, bazarr_version=bazarr_version, rows=data, row_count=row_count, page=page, max_page=max_page, stats=stats, base_url=base_url, page_size=page_size) @route(base_url + 'wanted') def wanted(): @@ -585,13 +589,14 @@ def wantedseries(): page = request.GET.page if page == "": page = "1" - offset = (int(page) - 1) * 15 - max_page = int(math.ceil(missing_count / 15.0)) + page_size = int(get_general_settings()[21]) + offset = (int(page) - 1) * page_size + max_page = int(math.ceil(missing_count / (page_size + 0.0))) - c.execute("SELECT table_shows.title, table_episodes.season || 'x' || table_episodes.episode, table_episodes.title, table_episodes.missing_subtitles, table_episodes.sonarrSeriesId, path_substitution(table_episodes.path), table_shows.hearing_impaired, table_episodes.sonarrEpisodeId, table_episodes.scene_name FROM table_episodes INNER JOIN table_shows on table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId WHERE table_episodes.missing_subtitles != '[]' ORDER BY table_episodes._rowid_ DESC LIMIT 15 OFFSET ?", (offset,)) + c.execute("SELECT table_shows.title, table_episodes.season || 'x' || table_episodes.episode, table_episodes.title, table_episodes.missing_subtitles, table_episodes.sonarrSeriesId, path_substitution(table_episodes.path), table_shows.hearing_impaired, table_episodes.sonarrEpisodeId, table_episodes.scene_name FROM table_episodes INNER JOIN table_shows on table_shows.sonarrSeriesId = table_episodes.sonarrSeriesId WHERE table_episodes.missing_subtitles != '[]' ORDER BY table_episodes._rowid_ DESC LIMIT ? OFFSET ?", (page_size, offset,)) data = c.fetchall() c.close() - return template('wantedseries', __file__=__file__, bazarr_version=bazarr_version, rows=data, missing_count=missing_count, page=page, max_page=max_page, base_url=base_url) + return template('wantedseries', __file__=__file__, bazarr_version=bazarr_version, rows=data, missing_count=missing_count, page=page, max_page=max_page, base_url=base_url, page_size=page_size) @route(base_url + 'wantedmovies') def wantedmovies(): @@ -605,13 +610,14 @@ def wantedmovies(): page = request.GET.page if page == "": page = "1" - offset = (int(page) - 1) * 15 - max_page = int(math.ceil(missing_count / 15.0)) + page_size = int(get_general_settings()[21]) + offset = (int(page) - 1) * page_size + max_page = int(math.ceil(missing_count / (page_size + 0.0))) - c.execute("SELECT title, missing_subtitles, radarrId, path_substitution(path), hearing_impaired, sceneName FROM table_movies WHERE missing_subtitles != '[]' ORDER BY _rowid_ DESC LIMIT 15 OFFSET ?", (offset,)) + c.execute("SELECT title, missing_subtitles, radarrId, path_substitution(path), hearing_impaired, sceneName FROM table_movies WHERE missing_subtitles != '[]' ORDER BY _rowid_ DESC LIMIT ? OFFSET ?", (page_size, offset,)) data = c.fetchall() c.close() - return template('wantedmovies', __file__=__file__, bazarr_version=bazarr_version, rows=data, missing_count=missing_count, page=page, max_page=max_page, base_url=base_url) + return template('wantedmovies', __file__=__file__, bazarr_version=bazarr_version, rows=data, missing_count=missing_count, page=page, max_page=max_page, base_url=base_url, page_size=page_size) @route(base_url + 'wanted_search_missing_subtitles') def wanted_search_missing_subtitles_list(): @@ -692,10 +698,11 @@ def save_settings(): settings_general_use_radarr = 'False' else: settings_general_use_radarr = 'True' + settings_page_size = request.forms.get('settings_page_size') before = c.execute("SELECT ip, port, base_url, log_level, path_mapping, use_sonarr, use_radarr, path_mapping_movie FROM table_settings_general").fetchone() after = (unicode(settings_general_ip), int(settings_general_port), unicode(settings_general_baseurl), unicode(settings_general_loglevel), unicode(settings_general_pathmapping), unicode(settings_general_use_sonarr), unicode(settings_general_use_radarr), unicode(settings_general_pathmapping_movie)) - c.execute("UPDATE table_settings_general SET ip = ?, port = ?, base_url = ?, path_mapping = ?, log_level = ?, branch=?, auto_update=?, single_language=?, minimum_score=?, use_scenename=?, use_postprocessing=?, postprocessing_cmd=?, use_sonarr=?, use_radarr=?, path_mapping_movie=?", (unicode(settings_general_ip), int(settings_general_port), unicode(settings_general_baseurl), unicode(settings_general_pathmapping), unicode(settings_general_loglevel), unicode(settings_general_branch), unicode(settings_general_automatic), unicode(settings_general_single_language), unicode(settings_general_minimum_score), unicode(settings_general_scenename), unicode(settings_general_use_postprocessing), unicode(settings_general_postprocessing_cmd), unicode(settings_general_use_sonarr), unicode(settings_general_use_radarr), unicode(settings_general_pathmapping_movie))) + c.execute("UPDATE table_settings_general SET ip = ?, port = ?, base_url = ?, path_mapping = ?, log_level = ?, branch=?, auto_update=?, single_language=?, minimum_score=?, use_scenename=?, use_postprocessing=?, postprocessing_cmd=?, use_sonarr=?, use_radarr=?, path_mapping_movie=?, page_size=?", (unicode(settings_general_ip), int(settings_general_port), unicode(settings_general_baseurl), unicode(settings_general_pathmapping), unicode(settings_general_loglevel), unicode(settings_general_branch), unicode(settings_general_automatic), unicode(settings_general_single_language), unicode(settings_general_minimum_score), unicode(settings_general_scenename), unicode(settings_general_use_postprocessing), unicode(settings_general_postprocessing_cmd), unicode(settings_general_use_sonarr), unicode(settings_general_use_radarr), unicode(settings_general_pathmapping_movie), unicode(settings_page_size))) conn.commit() if after != before: configured() @@ -1047,13 +1054,14 @@ def system(): for i, l in enumerate(f, 1): pass row_count = i - max_page = int(math.ceil(row_count / 50.0)) + page_size = int(get_general_settings()[21]) + max_page = int(math.ceil(row_count / (page_size + 0.0))) - return template('system', __file__=__file__, bazarr_version=bazarr_version, base_url=base_url, task_list=task_list, row_count=row_count, max_page=max_page) + return template('system', __file__=__file__, bazarr_version=bazarr_version, base_url=base_url, task_list=task_list, row_count=row_count, max_page=max_page, page_size=page_size) @route(base_url + 'logs/') def get_logs(page): - page_size = 50 + page_size = int(get_general_settings()[21]) begin = (page * page_size) - page_size end = (page * page_size) - 1 logs_complete = [] diff --git a/get_general_settings.py b/get_general_settings.py index d7a563829..219cb1646 100644 --- a/get_general_settings.py +++ b/get_general_settings.py @@ -49,8 +49,9 @@ def get_general_settings(): movie_default_enabled = general_settings[20] movie_default_language = general_settings[21] movie_default_hi = general_settings[22] + page_size = general_settings[23] - return [ip, port, base_url, path_mappings, log_level, branch, automatic, single_language, minimum_score, use_scenename, use_postprocessing, postprocessing_cmd, use_sonarr, use_radarr, path_mappings_movie, serie_default_enabled, serie_default_language, serie_default_hi, movie_default_enabled,movie_default_language, movie_default_hi] + return [ip, port, base_url, path_mappings, log_level, branch, automatic, single_language, minimum_score, use_scenename, use_postprocessing, postprocessing_cmd, use_sonarr, use_radarr, path_mappings_movie, serie_default_enabled, serie_default_language, serie_default_hi, movie_default_enabled,movie_default_language, movie_default_hi, page_size] def path_replace(path): for path_mapping in path_mappings: @@ -127,4 +128,5 @@ serie_default_language = result[16] serie_default_hi = result[17] movie_default_enabled = result[18] movie_default_language = result[19] -movie_default_hi = result[20] \ No newline at end of file +movie_default_hi = result[20] +page_size = result[21] \ No newline at end of file diff --git a/update_db.py b/update_db.py index 0ee023387..d07a315a0 100644 --- a/update_db.py +++ b/update_db.py @@ -157,6 +157,13 @@ if os.path.exists(os.path.join(os.path.dirname(__file__), 'data/db/bazarr.db')) except: pass + try: + c.execute('alter table table_settings_general add column "page_size" "text"') + except: + pass + else: + c.execute('UPDATE table_settings_general SET page_size="25"') + # Commit change to db db.commit() diff --git a/views/historymovies.tpl b/views/historymovies.tpl index f92cba9ce..0f170a141 100644 --- a/views/historymovies.tpl +++ b/views/historymovies.tpl @@ -89,6 +89,7 @@ %end + %if page_size != -1:
@@ -118,6 +119,7 @@
Total records: {{row_count}}
+ %end + +
+
+ +
+
+ +
+ + +
@@ -1278,6 +1302,8 @@ $('#settings_loglevel').dropdown('clear'); $('#settings_loglevel').dropdown('set selected','{{!settings_general[4]}}'); + $('#settings_page_size').dropdown('clear'); + $('#settings_page_size').dropdown('set selected','{{!settings_general[23]}}'); $('#settings_providers').dropdown('clear'); $('#settings_providers').dropdown('set selected',{{!enabled_providers}}); $('#settings_languages').dropdown('clear'); diff --git a/views/system.tpl b/views/system.tpl index c82b2a904..66787b226 100644 --- a/views/system.tpl +++ b/views/system.tpl @@ -91,7 +91,8 @@
-
+ %if page_size != -1: +
@@ -104,6 +105,7 @@
Total records: {{row_count}}
+ %end
@@ -131,7 +133,7 @@ }); current_page = page; - + $("#page").text(current_page); if (current_page == 1) { $(".backward, .fast.backward").addClass("disabled"); diff --git a/views/wantedmovies.tpl b/views/wantedmovies.tpl index 9631405a2..5a4815d4a 100644 --- a/views/wantedmovies.tpl +++ b/views/wantedmovies.tpl @@ -83,6 +83,7 @@ %end + %if page_size != -1:
@@ -112,6 +113,7 @@
Total records: {{missing_count}}
+ %end
diff --git a/views/wantedseries.tpl b/views/wantedseries.tpl index c2e9183a7..a48b86ba1 100644 --- a/views/wantedseries.tpl +++ b/views/wantedseries.tpl @@ -90,6 +90,7 @@ %end + %if page_size != -1:
@@ -119,6 +120,7 @@
Total records: {{missing_count}}
+ %end