From 62093864f2a2154ac60ce4559780b322a58f75c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Louis=20V=C3=A9zina?= <5130500+morpheus65535@users.noreply.github.com> Date: Fri, 24 Apr 2020 11:19:18 -0400 Subject: [PATCH] WIP --- bazarr/api.py | 3 ++- bazarr/config.py | 8 +++++++- views/settingslanguages.html | 18 +++++++++++++----- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/bazarr/api.py b/bazarr/api.py index a07ea1fd2..eed100d5d 100644 --- a/bazarr/api.py +++ b/bazarr/api.py @@ -127,7 +127,8 @@ class Search(Resource): class SaveSettings(Resource): @authenticate def post(self): - save_settings(request.form.items()) + + save_settings(zip(request.form.keys(), request.form.listvalues())) scheduler.update_configurable_tasks() return '', 200 diff --git a/bazarr/config.py b/bazarr/config.py index 68e60c259..8854185dd 100644 --- a/bazarr/config.py +++ b/bazarr/config.py @@ -151,11 +151,17 @@ base_url = settings.general.base_url def save_settings(settings_items): + from database import database for key, value in settings_items: if key == 'enabled_languages': - print(key) + database.execute("UPDATE table_settings_languages SET enabled=0") + for item in value: + database.execute("UPDATE table_settings_languages SET enabled=1 WHERE code2=?", (item,)) continue + if isinstance(value, list) and len(value) == 1: + value = value[0] + settings_keys = key.split('-') if value == 'true': diff --git a/views/settingslanguages.html b/views/settingslanguages.html index 290671480..1be303144 100644 --- a/views/settingslanguages.html +++ b/views/settingslanguages.html @@ -3,7 +3,11 @@ {% block title %}Languages - Bazarr{% endblock %} {% block page_head %} - + {% endblock page_head %} {% block bcleft %} @@ -33,11 +37,13 @@
Single Language
-
+
+ +

@@ -143,7 +149,6 @@ $('input[type=checkbox]').each(function () { formdata.set($(this).prop('id'), $(this).prop('checked')); }); - $.ajax({ url: "{{ url_for('api.savesettings') }}", data: formdata, @@ -179,8 +184,11 @@ $.ajax({ url: "{{ url_for('api.languages') }}?enabled=true", success: function (data) { - console.log(data); - $('#enabled_languages').selectpicker('val', data); + let optArr = []; + $.each(data, function (i, item) { + optArr.push(item.code2); + }); + $('#enabled_languages').selectpicker('val', optArr); } }); }