Implementing page size selection in settings #67

This commit is contained in:
Louis Vézina 2018-07-11 08:50:11 -04:00
parent ad4203fb8e
commit a1a1292b41
11 changed files with 90 additions and 33 deletions

View File

@ -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/<page:int>')
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 = []

View File

@ -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]
movie_default_hi = result[20]
page_size = result[21]

View File

@ -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()

View File

@ -89,6 +89,7 @@
%end
</tbody>
</table>
%if page_size != -1:
<div class="ui grid">
<div class="three column row">
<div class="column"></div>
@ -118,6 +119,7 @@
<div class="right floated right aligned column">Total records: {{row_count}}</div>
</div>
</div>
%end
</div>
<div id='bottommenu' class="ui fluid inverted bottom fixed five item menu">
<div class="ui small statistics">

View File

@ -104,6 +104,7 @@
%end
</tbody>
</table>
%if page_size != -1:
<div class="ui grid">
<div class="three column row">
<div class="column"></div>
@ -133,6 +134,7 @@
<div class="right floated right aligned column">Total records: {{row_count}}</div>
</div>
</div>
%end
</div>
<div id='bottommenu' class="ui fluid inverted bottom fixed five item menu">
<div class="ui small statistics">

View File

@ -104,6 +104,7 @@
%end
</tbody>
</table>
%if page_size != -1:
<div class="ui grid">
<div class="three column row">
<div class="column"></div>
@ -133,6 +134,7 @@
<div class="right floated right aligned column">Total records: {{missing_count}}</div>
</div>
</div>
%end
</div>
<div class="ui small modal">

View File

@ -128,6 +128,7 @@
%end
</tbody>
</table>
%if page_size != -1:
<div class="ui grid">
<div class="three column row">
<div class="column"></div>
@ -157,6 +158,7 @@
<div class="right floated right aligned column">Total records: {{missing_count}}</div>
</div>
</div>
%end
</div>
<div class="ui small modal">

View File

@ -159,6 +159,30 @@
</div>
</div>
</div>
<div class="middle aligned row">
<div class="right aligned four wide column">
<label>Page size</label>
</div>
<div class="five wide column">
<select name="settings_page_size" id="settings_page_size" class="ui fluid selection dropdown">
<option value="">Page Size</option>
<option value="-1">Unlimited</option>
<option value="25">25</option>
<option value="50">50</option>
<option value="100">100</option>
<option value="250">250</option>
<option value="500">500</option>
<option value="1000">1000</option>
</select>
</div>
<div class="collapsed center aligned column">
<div class="ui basic icon" data-tooltip="How many items to show in a list." data-inverted="">
<i class="help circle large icon"></i>
</div>
</div>
</div>
</div>
</div>
@ -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');

View File

@ -91,7 +91,8 @@
<div class="content">
<div id="logs"></div>
<div class="ui grid">
%if page_size != -1:
<div class="ui grid">
<div class="three column row">
<div class="column"></div>
<div class="center aligned column">
@ -104,6 +105,7 @@
<div class="right floated right aligned column">Total records: {{row_count}}</div>
</div>
</div>
%end
</div>
</div>
<div class="ui bottom attached tab segment" data-tab="about">
@ -131,7 +133,7 @@
});
current_page = page;
$("#page").text(current_page);
if (current_page == 1) {
$(".backward, .fast.backward").addClass("disabled");

View File

@ -83,6 +83,7 @@
%end
</tbody>
</table>
%if page_size != -1:
<div class="ui grid">
<div class="three column row">
<div class="column"></div>
@ -112,6 +113,7 @@
<div class="right floated right aligned column">Total records: {{missing_count}}</div>
</div>
</div>
%end
</div>
</body>
</html>

View File

@ -90,6 +90,7 @@
%end
</tbody>
</table>
%if page_size != -1:
<div class="ui grid">
<div class="three column row">
<div class="column"></div>
@ -119,6 +120,7 @@
<div class="right floated right aligned column">Total records: {{missing_count}}</div>
</div>
</div>
%end
</div>
</body>
</html>