Settings: Add support for post edit callbacks

Settings can be provided with a function via the new
"post_edit_function" argument. This function will be called
when the setting's value is updated. The function will only
receive one argument: The instance of the setting being
changed.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
Roberto Rosario
2018-12-04 15:43:54 -04:00
parent f4e0e06c66
commit 984a1903ce

View File

@@ -146,13 +146,14 @@ class Setting(object):
path=settings.CONFIGURATION_LAST_GOOD_FILEPATH
)
def __init__(self, namespace, global_name, default, help_text=None, is_path=False):
def __init__(self, namespace, global_name, default, help_text=None, is_path=False, post_edit_function=None):
self.global_name = global_name
self.default = default
self.help_text = help_text
self.loaded = False
self.namespace = namespace
self.environment_variable = False
self.post_edit_function = post_edit_function
namespace._settings.append(self)
self.__class__._registry[global_name] = self
@@ -204,3 +205,5 @@ class Setting(object):
# value is in YAML format
self.yaml = value
self.raw_value = Setting.deserialize_value(value)
if self.post_edit_function:
self.post_edit_function(setting=self)