diff options
author | James Taylor <user234683@users.noreply.github.com> | 2021-07-19 13:59:11 -0700 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2021-07-28 23:14:10 -0500 |
commit | 5df5e9921385d8c40c4929e162bcfde98a68dbf7 (patch) | |
tree | 6428eef6440836c4daef4d0a2aecb4d8e446b089 /settings.py | |
parent | 4a5a64a97546caa865730fe08ba1d21ddea8634b (diff) | |
download | yt-local-5df5e9921385d8c40c4929e162bcfde98a68dbf7.tar.lz yt-local-5df5e9921385d8c40c4929e162bcfde98a68dbf7.tar.xz yt-local-5df5e9921385d8c40c4929e162bcfde98a68dbf7.zip |
Call setting hooks after change, rather than before
More convenient for functions that already read the current value
from settings.[...]. See next commit
Signed-off-by: Jesús <heckyel@hyperbola.info>
Diffstat (limited to 'settings.py')
-rw-r--r-- | settings.py | 12 |
1 files 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) |