diff --git a/tubearchivist/home/src/ta/config.py b/tubearchivist/home/src/ta/config.py index 4b98c4a..020e637 100644 --- a/tubearchivist/home/src/ta/config.py +++ b/tubearchivist/home/src/ta/config.py @@ -83,6 +83,7 @@ class AppConfig: def update_config(self, form_post): """update config values from settings form""" + updated = [] for key, value in form_post.items(): if not value and not isinstance(value, int): continue @@ -96,8 +97,10 @@ class AppConfig: config_dict, config_value = key.split("_", maxsplit=1) self.config[config_dict][config_value] = to_write + updated.append((config_value, to_write)) RedisArchivist().set_message("config", self.config, expire=False) + return updated @staticmethod def set_user_config(form_post, user_id): diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py index 92359b8..22d219a 100644 --- a/tubearchivist/home/views.py +++ b/tubearchivist/home/views.py @@ -14,6 +14,7 @@ from django.contrib.auth.forms import AuthenticationForm from django.http import JsonResponse from django.shortcuts import redirect, render from django.views import View +from home.src.download.yt_cookie import CookieHandler from home.src.es.index_setup import get_available_backups from home.src.frontend.api_calls import PostData from home.src.frontend.forms import ( @@ -791,8 +792,7 @@ class SettingsView(View): token = Token.objects.get_or_create(user=request.user)[0] return token - @staticmethod - def post(request): + def post(self, request): """handle form post to update settings""" user_form = UserSettingsForm(request.POST) if user_form.is_valid(): @@ -805,7 +805,8 @@ class SettingsView(View): app_form_post = app_form.cleaned_data if app_form_post: print(app_form_post) - AppConfig().update_config(app_form_post) + updated = AppConfig().update_config(app_form_post) + self.post_process_updated(updated) scheduler_form = SchedulerSettingsForm(request.POST) if scheduler_form.is_valid(): @@ -817,6 +818,19 @@ class SettingsView(View): sleep(1) return redirect("settings", permanent=True) + @staticmethod + def post_process_updated(updated): + """apply changes for config""" + if not updated: + return + + for config_value, updated_value in updated: + if config_value == "cookie_import": + if updated_value: + CookieHandler().import_cookie() + else: + CookieHandler().revoke() + def progress(request): # pylint: disable=unused-argument