mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 05:05:42 +00:00 
			
		
		
		
	Small tweaks
- Factor out native_value property (not needed!) - PEP fixes
This commit is contained in:
		| @@ -398,17 +398,6 @@ class BaseInvenTreeSetting(models.Model): | |||||||
|     def units(self): |     def units(self): | ||||||
|         return self.__class__.get_setting_units(self.key) |         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): |     def clean(self, **kwargs): | ||||||
|         """ |         """ | ||||||
|         If a validator (or multiple validators) are defined for a particular setting key, |         If a validator (or multiple validators) are defined for a particular setting key, | ||||||
| @@ -418,7 +407,7 @@ class BaseInvenTreeSetting(models.Model): | |||||||
|         super().clean() |         super().clean() | ||||||
|  |  | ||||||
|         # Encode as native values |         # Encode as native values | ||||||
|         self.value = self.native_value |         self.value = self.to_native_value() | ||||||
|  |  | ||||||
|         validator = self.__class__.get_setting_validator(self.key, **kwargs) |         validator = self.__class__.get_setting_validator(self.key, **kwargs) | ||||||
|  |  | ||||||
|   | |||||||
| @@ -158,7 +158,6 @@ class SettingsTest(TestCase): | |||||||
|                     raise ValueError(f'Non-boolean default value specified for {key}')  # pragma: no cover |                     raise ValueError(f'Non-boolean default value specified for {key}')  # pragma: no cover | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| class GlobalSettingsApiTest(InvenTreeAPITestCase): | class GlobalSettingsApiTest(InvenTreeAPITestCase): | ||||||
|     """ |     """ | ||||||
|     Tests for the global settings API |     Tests for the global settings API | ||||||
| @@ -238,7 +237,7 @@ class UserSettingsApiTest(InvenTreeAPITestCase): | |||||||
|         ) |         ) | ||||||
|  |  | ||||||
|         # Check default values |         # Check default values | ||||||
|         self.assertEqual(setting.native_value, True) |         self.assertEqual(setting.to_native_value(), True) | ||||||
|  |  | ||||||
|         # Fetch via API |         # Fetch via API | ||||||
|         url = reverse('api-user-setting-detail', kwargs={'pk': setting.pk}) |         url = reverse('api-user-setting-detail', kwargs={'pk': setting.pk}) | ||||||
| @@ -363,7 +362,7 @@ class UserSettingsApiTest(InvenTreeAPITestCase): | |||||||
|             ) |             ) | ||||||
|  |  | ||||||
|             setting.refresh_from_db() |             setting.refresh_from_db() | ||||||
|             self.assertEqual(setting.native_value, v) |             self.assertEqual(setting.to_native_value(), v) | ||||||
|  |  | ||||||
|         # Set invalid options via the API |         # Set invalid options via the API | ||||||
|         # Note that this particular setting has a MinValueValidator(1) associated with it |         # Note that this particular setting has a MinValueValidator(1) associated with it | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user