refactor clean method to reduce duplication

This commit is contained in:
Matthias 2022-04-05 00:14:39 +02:00
parent 8d01df0b5e
commit 205916e0b2
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076

View File

@ -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