From 205916e0b241925bff432f4df147432ab43c8b3f Mon Sep 17 00:00:00 2001 From: Matthias Date: Tue, 5 Apr 2022 00:14:39 +0200 Subject: [PATCH] refactor clean method to reduce duplication --- InvenTree/plugin/models.py | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/InvenTree/plugin/models.py b/InvenTree/plugin/models.py index 39d863d32e..3b295c5a54 100644 --- a/InvenTree/plugin/models.py +++ b/InvenTree/plugin/models.py @@ -112,6 +112,17 @@ class GenericSettingClassMixin: self.REFERENCE_NAME: getattr(self, self.REFERENCE_NAME) } + """ + We override the following class methods, + so that we can pass the modified key instance as an additional argument + """ + + def clean(self, **kwargs): + + kwargs[self.REFERENCE_NAME] = getattr(self, self.REFERENCE_NAME) + + super().clean(**kwargs) + def is_bool(self, **kwargs): kwargs[self.REFERENCE_NAME] = getattr(self, self.REFERENCE_NAME) @@ -148,17 +159,6 @@ class PluginSetting(GenericSettingClassMixin, common.models.BaseInvenTreeSetting ('plugin', 'key'), ] - def clean(self, **kwargs): - - kwargs['plugin'] = self.plugin - - super().clean(**kwargs) - - """ - We override the following class methods, - so that we can pass the plugin instance - """ - REFERENCE_NAME = 'plugin' @classmethod @@ -208,17 +208,6 @@ class NotificationUserSetting(common.models.BaseInvenTreeSetting): ('method', 'user', 'key'), ] - def clean(self, **kwargs): - - kwargs['method'] = self.method - - super().clean(**kwargs) - - """ - We override the following class methods, - so that we can pass the method instance - """ - REFERENCE_NAME = 'method' @classmethod