mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-02 21:38:48 +00:00
Update settings API endpoints: (#5684)
* Update settings API endpoints: - Use cache to prevent unnecessary hits to db - Make settings detail endpoints case insensitive - Update API version * Remove is_admin and is_superuser - Contaminated from other commit * revert seralizers.py * Revert breaking change to users/api.py
This commit is contained in:
parent
e8e0b57cea
commit
89faf8e59d
@ -2,11 +2,15 @@
|
|||||||
|
|
||||||
|
|
||||||
# InvenTree API version
|
# InvenTree API version
|
||||||
INVENTREE_API_VERSION = 137
|
INVENTREE_API_VERSION = 138
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Increment this API version number whenever there is a significant change to the API that any clients need to know about
|
Increment this API version number whenever there is a significant change to the API that any clients need to know about
|
||||||
|
|
||||||
|
v138 -> 2023-10-11 : https://github.com/inventree/InvenTree/pull/5679
|
||||||
|
- Settings keys are no longer case sensitive
|
||||||
|
- Include settings units in API serializer
|
||||||
|
|
||||||
v137 -> 2023-10-04 : https://github.com/inventree/InvenTree/pull/5588
|
v137 -> 2023-10-04 : https://github.com/inventree/InvenTree/pull/5588
|
||||||
- Adds StockLocationType API endpoints
|
- Adds StockLocationType API endpoints
|
||||||
- Adds custom_icon, location_type to StockLocation endpoint
|
- Adds custom_icon, location_type to StockLocation endpoint
|
||||||
@ -89,7 +93,7 @@ v113 -> 2023-05-13 : https://github.com/inventree/InvenTree/pull/4800
|
|||||||
- Adds API endpoints for scrapping a build output
|
- Adds API endpoints for scrapping a build output
|
||||||
|
|
||||||
v112 -> 2023-05-13: https://github.com/inventree/InvenTree/pull/4741
|
v112 -> 2023-05-13: https://github.com/inventree/InvenTree/pull/4741
|
||||||
- Adds flag use_pack_size to the stock addition API, which allows addings packs
|
- Adds flag use_pack_size to the stock addition API, which allows adding packs
|
||||||
|
|
||||||
v111 -> 2023-05-02 : https://github.com/inventree/InvenTree/pull/4367
|
v111 -> 2023-05-02 : https://github.com/inventree/InvenTree/pull/4367
|
||||||
- Adds tags to the Part serializer
|
- Adds tags to the Part serializer
|
||||||
@ -169,7 +173,7 @@ v90 -> 2023-01-25 : https://github.com/inventree/InvenTree/pull/4186/files
|
|||||||
|
|
||||||
v89 -> 2023-01-25 : https://github.com/inventree/InvenTree/pull/4214
|
v89 -> 2023-01-25 : https://github.com/inventree/InvenTree/pull/4214
|
||||||
- Adds updated field to SupplierPart API
|
- Adds updated field to SupplierPart API
|
||||||
- Adds API date orddering for supplier part list
|
- Adds API date ordering for supplier part list
|
||||||
|
|
||||||
v88 -> 2023-01-17: https://github.com/inventree/InvenTree/pull/4225
|
v88 -> 2023-01-17: https://github.com/inventree/InvenTree/pull/4225
|
||||||
- Adds 'priority' field to Build model and api endpoints
|
- Adds 'priority' field to Build model and api endpoints
|
||||||
|
@ -298,7 +298,11 @@ class UserSerializer(InvenTreeModelSerializer):
|
|||||||
'username',
|
'username',
|
||||||
'first_name',
|
'first_name',
|
||||||
'last_name',
|
'last_name',
|
||||||
'email'
|
'email',
|
||||||
|
]
|
||||||
|
|
||||||
|
read_only_fields = [
|
||||||
|
'username',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -229,9 +229,9 @@ class GlobalSettingsDetail(RetrieveUpdateAPI):
|
|||||||
|
|
||||||
def get_object(self):
|
def get_object(self):
|
||||||
"""Attempt to find a global setting object with the provided key."""
|
"""Attempt to find a global setting object with the provided key."""
|
||||||
key = self.kwargs['key']
|
key = str(self.kwargs['key']).upper()
|
||||||
|
|
||||||
if key not in common.models.InvenTreeSetting.SETTINGS.keys():
|
if key.startswith('_') or key not in common.models.InvenTreeSetting.SETTINGS.keys():
|
||||||
raise NotFound()
|
raise NotFound()
|
||||||
|
|
||||||
return common.models.InvenTreeSetting.get_setting_object(
|
return common.models.InvenTreeSetting.get_setting_object(
|
||||||
@ -296,9 +296,9 @@ class UserSettingsDetail(RetrieveUpdateAPI):
|
|||||||
|
|
||||||
def get_object(self):
|
def get_object(self):
|
||||||
"""Attempt to find a user setting object with the provided key."""
|
"""Attempt to find a user setting object with the provided key."""
|
||||||
key = self.kwargs['key']
|
key = str(self.kwargs['key']).upper()
|
||||||
|
|
||||||
if key not in common.models.InvenTreeUserSetting.SETTINGS.keys():
|
if key.startswith('_') or key not in common.models.InvenTreeUserSetting.SETTINGS.keys():
|
||||||
raise NotFound()
|
raise NotFound()
|
||||||
|
|
||||||
return common.models.InvenTreeUserSetting.get_setting_object(
|
return common.models.InvenTreeUserSetting.get_setting_object(
|
||||||
|
@ -205,6 +205,12 @@ class BaseInvenTreeSetting(models.Model):
|
|||||||
If a particular setting is not present, create it with the default value
|
If a particular setting is not present, create it with the default value
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
cache_key = f"BUILD_DEFAULT_VALUES:{str(cls.__name__)}"
|
||||||
|
|
||||||
|
if InvenTree.helpers.str2bool(cache.get(cache_key, False)):
|
||||||
|
# Already built default values
|
||||||
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
existing_keys = cls.objects.filter(**kwargs).values_list('key', flat=True)
|
existing_keys = cls.objects.filter(**kwargs).values_list('key', flat=True)
|
||||||
settings_keys = cls.SETTINGS.keys()
|
settings_keys = cls.SETTINGS.keys()
|
||||||
@ -224,6 +230,8 @@ class BaseInvenTreeSetting(models.Model):
|
|||||||
logger.exception("Failed to build default values for %s (%s)", str(cls), str(type(exc)))
|
logger.exception("Failed to build default values for %s (%s)", str(cls), str(type(exc)))
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
cache.set(cache_key, True, timeout=3600)
|
||||||
|
|
||||||
def _call_settings_function(self, reference: str, args, kwargs):
|
def _call_settings_function(self, reference: str, args, kwargs):
|
||||||
"""Call a function associated with a particular setting.
|
"""Call a function associated with a particular setting.
|
||||||
|
|
||||||
@ -1241,7 +1249,7 @@ class InvenTreeSetting(BaseInvenTreeSetting):
|
|||||||
|
|
||||||
'BARCODE_ENABLE': {
|
'BARCODE_ENABLE': {
|
||||||
'name': _('Barcode Support'),
|
'name': _('Barcode Support'),
|
||||||
'description': _('Enable barcode scanner support'),
|
'description': _('Enable barcode scanner support in the web interface'),
|
||||||
'default': True,
|
'default': True,
|
||||||
'validator': bool,
|
'validator': bool,
|
||||||
},
|
},
|
||||||
|
@ -51,6 +51,8 @@ class SettingsSerializer(InvenTreeModelSerializer):
|
|||||||
|
|
||||||
value = SettingsValueField()
|
value = SettingsValueField()
|
||||||
|
|
||||||
|
units = serializers.CharField(read_only=True)
|
||||||
|
|
||||||
def get_choices(self, obj):
|
def get_choices(self, obj):
|
||||||
"""Returns the choices available for a given item."""
|
"""Returns the choices available for a given item."""
|
||||||
results = []
|
results = []
|
||||||
@ -81,6 +83,7 @@ class GlobalSettingsSerializer(SettingsSerializer):
|
|||||||
'name',
|
'name',
|
||||||
'description',
|
'description',
|
||||||
'type',
|
'type',
|
||||||
|
'units',
|
||||||
'choices',
|
'choices',
|
||||||
'model_name',
|
'model_name',
|
||||||
'api_url',
|
'api_url',
|
||||||
@ -103,6 +106,7 @@ class UserSettingsSerializer(SettingsSerializer):
|
|||||||
'description',
|
'description',
|
||||||
'user',
|
'user',
|
||||||
'type',
|
'type',
|
||||||
|
'units',
|
||||||
'choices',
|
'choices',
|
||||||
'model_name',
|
'model_name',
|
||||||
'api_url',
|
'api_url',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user