2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-18 13:05:42 +00:00

Edit plugin settings via the "settings" display

This commit is contained in:
Oliver
2022-01-04 21:03:01 +11:00
parent dc9e25ebad
commit 928b90a833
4 changed files with 24 additions and 16 deletions

View File

@ -371,23 +371,14 @@ class BaseInvenTreeSetting(models.Model):
validator = self.__class__.get_setting_validator(self.key, **kwargs)
if self.is_bool():
self.value = InvenTree.helpers.str2bool(self.value)
if self.is_int():
try:
self.value = int(self.value)
except (ValueError):
raise ValidationError(_('Must be an integer value'))
if validator is not None:
self.run_validator(validator)
options = self.valid_options()
if options and self.value not in options:
raise ValidationError(_("Chosen value is not a valid option"))
if validator is not None:
self.run_validator(validator)
def run_validator(self, validator):
"""
Run a validator against the 'value' field for this InvenTreeSetting object.
@ -399,7 +390,7 @@ class BaseInvenTreeSetting(models.Model):
value = self.value
# Boolean validator
if self.is_bool():
if validator is bool:
# Value must "look like" a boolean value
if InvenTree.helpers.is_bool(value):
# Coerce into either "True" or "False"
@ -410,7 +401,7 @@ class BaseInvenTreeSetting(models.Model):
})
# Integer validator
if self.is_int():
if validator is int:
try:
# Coerce into an integer value