Small tweaks

- Factor out native_value property (not needed!)
- PEP fixes
This commit is contained in:
Oliver Walters 2022-05-01 22:30:24 +10:00
parent f794d91e5c
commit d72efc3757
2 changed files with 4 additions and 16 deletions

View File

@ -398,17 +398,6 @@ class BaseInvenTreeSetting(models.Model):
def units(self):
return self.__class__.get_setting_units(self.key)
@property
def native_value(self):
if self.is_bool():
return self.as_bool()
if self.is_int():
return self.as_int()
return self.value
def clean(self, **kwargs):
"""
If a validator (or multiple validators) are defined for a particular setting key,
@ -418,7 +407,7 @@ class BaseInvenTreeSetting(models.Model):
super().clean()
# Encode as native values
self.value = self.native_value
self.value = self.to_native_value()
validator = self.__class__.get_setting_validator(self.key, **kwargs)
@ -1432,7 +1421,7 @@ class InvenTreeUserSetting(BaseInvenTreeSetting):
('MMM DD YYYY', 'Feb 22 2022'),
]
},
'DISPLAY_SCHEDULE_TAB': {
'name': _('Part Scheduling'),
'description': _('Display part scheduling information'),

View File

@ -158,7 +158,6 @@ class SettingsTest(TestCase):
raise ValueError(f'Non-boolean default value specified for {key}') # pragma: no cover
class GlobalSettingsApiTest(InvenTreeAPITestCase):
"""
Tests for the global settings API
@ -238,7 +237,7 @@ class UserSettingsApiTest(InvenTreeAPITestCase):
)
# Check default values
self.assertEqual(setting.native_value, True)
self.assertEqual(setting.to_native_value(), True)
# Fetch via API
url = reverse('api-user-setting-detail', kwargs={'pk': setting.pk})
@ -363,7 +362,7 @@ class UserSettingsApiTest(InvenTreeAPITestCase):
)
setting.refresh_from_db()
self.assertEqual(setting.native_value, v)
self.assertEqual(setting.to_native_value(), v)
# Set invalid options via the API
# Note that this particular setting has a MinValueValidator(1) associated with it