From 5df5e9921385d8c40c4929e162bcfde98a68dbf7 Mon Sep 17 00:00:00 2001 From: James Taylor Date: Mon, 19 Jul 2021 13:59:11 -0700 Subject: Call setting hooks after change, rather than before MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit More convenient for functions that already read the current value from settings.[...]. See next commit Signed-off-by: Jesús --- settings.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/settings.py b/settings.py index 4cd882b..f0c297a 100644 --- a/settings.py +++ b/settings.py @@ -392,7 +392,7 @@ hooks = {} def add_setting_changed_hook(setting, func): - '''Called right before new settings take effect''' + '''Called right after new settings take effect''' if setting in hooks: hooks[setting].append(func) else: @@ -447,15 +447,21 @@ def settings_page(): assert SETTINGS_INFO[setting_name]['type'] is bool, missing_inputs current_settings_dict[setting_name] = False - # call setting hooks + # find settings that have changed to prepare setting hook calls + to_call = [] for setting_name, value in current_settings_dict.items(): old_value = globals()[setting_name] if value != old_value and setting_name in hooks: for func in hooks[setting_name]: - func(old_value, value) + to_call.append((func, old_value, value)) globals().update(current_settings_dict) save_settings(current_settings_dict) + + # call setting hooks + for func, old_value, value in to_call: + func(old_value, value) + return flask.redirect(util.URL_ORIGIN + '/settings', 303) else: flask.abort(400) -- cgit v1.2.3