From e47aed64907529cc7b97c1930f22ffa54a86de54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Thu, 23 Jul 2020 18:20:58 -0400 Subject: [PATCH] Fix for #1031. Improvement to previous commit. --- bazarr/api.py | 81 +++++++++++++++++++++++++++++----------- bazarr/list_subtitles.py | 10 +++-- views/movieseditor.html | 34 +++++------------ views/serieseditor.html | 34 +++++------------ 4 files changed, 85 insertions(+), 74 deletions(-) diff --git a/bazarr/api.py b/bazarr/api.py index 7d7fcf5f6..196d2946d 100644 --- a/bazarr/api.py +++ b/bazarr/api.py @@ -377,19 +377,38 @@ class SeriesEditSave(Resource): if lang == ['None']: lang = 'None' + seriesIdList = [] + seriesidLangList = [] + seriesidHiList = [] + seriesidForcedList = [] for item in request.form.getlist('seriesid[]'): seriesid = item.lstrip('row_') - try: - if len(lang): - database.execute("UPDATE table_shows SET languages=? WHERE sonarrSeriesId=?", (str(lang), seriesid)) - if len(hi): - database.execute("UPDATE table_shows SET hearing_impaired=? WHERE sonarrSeriesId=?", (hi[0], seriesid)) - if len(forced): - database.execute("UPDATE table_shows SET forced=? WHERE sonarrSeriesId=?", (forced[0], seriesid)) - except: - pass - else: - list_missing_subtitles(no=seriesid) + seriesIdList.append(seriesid) + if len(lang): + seriesidLangList.append([str(lang), seriesid]) + if len(hi): + seriesidHiList.append([hi[0], seriesid]) + if len(forced): + seriesidForcedList.append([forced[0], seriesid]) + + try: + if len(lang): + database.execute("UPDATE table_shows SET languages=? WHERE sonarrSeriesId=?", seriesidLangList, + execute_many=True) + if len(hi): + database.execute("UPDATE table_shows SET hearing_impaired=? WHERE sonarrSeriesId=?", seriesidHiList, + execute_many=True) + if len(forced): + database.execute("UPDATE table_shows SET forced=? WHERE sonarrSeriesId=?", seriesidForcedList, + execute_many=True) + except: + pass + else: + for seriesId in seriesIdList: + list_missing_subtitles(no=seriesId, update_wanted=False) + + event_stream(type='series_editor', action='update') + event_stream(type='badges') return '', 204 @@ -884,19 +903,37 @@ class MoviesEditSave(Resource): if lang == ['None']: lang = 'None' + radarrIdList = [] + radarrIdLangList = [] + radarrIdHiList = [] + radarrIdForcedList = [] for item in request.form.getlist('radarrid[]'): radarrid = item.lstrip('row_') - try: - if len(lang): - database.execute("UPDATE table_movies SET languages=? WHERE radarrId=?", (str(lang), radarrid)) - if len(hi): - database.execute("UPDATE table_movies SET hearing_impaired=? WHERE radarrId=?", (hi[0], radarrid)) - if len(forced): - database.execute("UPDATE table_movies SET forced=? WHERE radarrId=?", (forced[0], radarrid)) - except: - pass - else: - list_missing_subtitles_movies(no=radarrid) + radarrIdList.append(radarrid) + if len(lang): + radarrIdLangList.append([str(lang), radarrid]) + if len(hi): + radarrIdHiList.append([hi[0], radarrid]) + if len(forced): + radarrIdForcedList.append([forced[0], radarrid]) + try: + if len(lang): + database.execute("UPDATE table_movies SET languages=? WHERE radarrId=?", radarrIdLangList, + execute_many=True) + if len(hi): + database.execute("UPDATE table_movies SET hearing_impaired=? WHERE radarrId=?", radarrIdHiList, + execute_many=True) + if len(forced): + database.execute("UPDATE table_movies SET forced=? WHERE radarrId=?", radarrIdForcedList, + execute_many=True) + except: + pass + else: + for radarrId in radarrIdList: + list_missing_subtitles_movies(no=radarrId, update_wanted=False) + + event_stream(type='movies_editor', action='update') + event_stream(type='badges') return '', 204 diff --git a/bazarr/list_subtitles.py b/bazarr/list_subtitles.py index 015713e05..a404d66e8 100644 --- a/bazarr/list_subtitles.py +++ b/bazarr/list_subtitles.py @@ -169,7 +169,7 @@ def store_subtitles_movie(original_path, reversed_path): return actual_subtitles -def list_missing_subtitles(no=None, epno=None): +def list_missing_subtitles(no=None, epno=None, update_wanted=True): if no is not None: episodes_subtitles_clause = " WHERE table_episodes.sonarrSeriesId=" + str(no) elif epno is not None: @@ -233,10 +233,11 @@ def list_missing_subtitles(no=None, epno=None): event_stream(type='episode', action='update', series=missing_subtitles_item[2], episode=missing_subtitles_item[1]) - event_stream(type='badges') + if update_wanted: + event_stream(type='badges') -def list_missing_subtitles_movies(no=None): +def list_missing_subtitles_movies(no=None, update_wanted=True): if no is not None: movies_subtitles_clause = " WHERE radarrId=" + str(no) else: @@ -293,7 +294,8 @@ def list_missing_subtitles_movies(no=None): (missing_subtitles_item[0], missing_subtitles_item[1])) event_stream(type='movie', action='update', movie=missing_subtitles_item[1]) - event_stream(type='badges') + if update_wanted: + event_stream(type='badges') def series_full_scan_subtitles(): diff --git a/views/movieseditor.html b/views/movieseditor.html index ee743ebf4..97bd75a60 100644 --- a/views/movieseditor.html +++ b/views/movieseditor.html @@ -65,37 +65,16 @@ events.on('event', function (event) { var event_json = JSON.parse(event); - if (event_json.type === 'movie' && event_json.action === 'insert') { + if (event_json.type === 'movies_editor' && event_json.action === 'update') { $.ajax({ - url: "{{ url_for('api.movies') }}?radarrid=" + event_json.movie, + url: "{{ url_for('api.movies') }}", success: function (data) { if (data.data.length) { - $('#movies').DataTable().rows.add(data.data); - $('#movies').DataTable().columns.adjust().draw(false); + $('#movies').DataTable().ajax.reload(resetPaging = false); $('[data-toggle="tooltip"]').tooltip({html: true}); } } }) - } else if (event_json.type === 'movie' && event_json.action === 'update') { - var rowId = $('#movies').DataTable().row('#row_' + event_json.movie); - if (rowId.length) { - $.ajax({ - url: "{{ url_for('api.movies') }}?radarrid=" + event_json.movie, - success: function (data) { - if (data.data.length) { - $('#movies').DataTable().row(rowId).data(data.data[0]).draw('page'); - $('[data-toggle="tooltip"]').tooltip({html: true}); - } - } - }) - } - } else if (event_json.type === 'movie' && event_json.action === 'delete') { - var rowId = $('#movies').DataTable().row('#row_' + event_json.movie); - if (rowId.length) { - $('#movies').DataTable().row(rowId).remove(); - $('#movies').DataTable().columns.adjust().draw(false); - $('[data-toggle="tooltip"]').tooltip({html: true}); - } } }); @@ -220,6 +199,13 @@ url: "{{ url_for('api.movieseditsave') }}", method: "POST", data: values, + beforeSend: function () { + $('.selectpicker').prop('disabled', true); + $('.selectpicker').selectpicker('refresh'); + $('#save_button').prop('disabled', true); + $('#save_button').addClass('disabled'); + $('#save_button').css('cursor', 'wait'); + }, success: function () { table.rows().deselect(); $('#languages_select').selectpicker('val', ''); diff --git a/views/serieseditor.html b/views/serieseditor.html index 6f6f4cf29..81a13d438 100644 --- a/views/serieseditor.html +++ b/views/serieseditor.html @@ -65,37 +65,16 @@ events.on('event', function (event) { var event_json = JSON.parse(event); - if (event_json.type === 'series' && event_json.action === 'insert') { + if (event_json.type === 'series_editor' && event_json.action === 'update') { $.ajax({ - url: "{{ url_for('api.series') }}?seriesid=" + event_json.series, + url: "{{ url_for('api.series') }}", success: function (data) { if (data.data.length) { - $('#series').DataTable().rows.add(data.data); - $('#series').DataTable().columns.adjust().draw(false); + $('#series').DataTable().ajax.reload(resetPaging = false); $('[data-toggle="tooltip"]').tooltip({html: true}); } } }) - } else if (event_json.type === 'series' && event_json.action === 'update') { - var rowId = $('#series').DataTable().row('#row_' + event_json.series); - if (rowId.length) { - $.ajax({ - url: "{{ url_for('api.series') }}?seriesid=" + event_json.series, - success: function (data) { - if (data.data.length) { - $('#series').DataTable().row(rowId).data(data.data[0]).draw('page'); - $('[data-toggle="tooltip"]').tooltip({html: true}); - } - } - }) - } - } else if (event_json.type === 'series' && event_json.action === 'delete') { - var rowId = $('#series').DataTable().row('#row_' + event_json.series); - if (rowId.length) { - $('#series').DataTable().row(rowId).remove(); - $('#series').DataTable().columns.adjust().draw(false); - $('[data-toggle="tooltip"]').tooltip({html: true}); - } } }); @@ -214,6 +193,13 @@ url: "{{ url_for('api.serieseditsave') }}", method: "POST", data: values, + beforeSend: function () { + $('.selectpicker').prop('disabled', true); + $('.selectpicker').selectpicker('refresh'); + $('#save_button').prop('disabled', true); + $('#save_button').addClass('disabled'); + $('#save_button').css('cursor', 'wait'); + }, success: function () { table.rows().deselect(); $('#languages_select').selectpicker('val', '');