mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-01 13:06:45 +00:00
Add LIST endpoint for global settngs and user settings
- Read only, cannot create new settings - User settings filters against the user making the request
This commit is contained in:
parent
6c8f04b387
commit
cb583eb466
@ -53,7 +53,7 @@ admin.site.site_header = "InvenTree Admin"
|
|||||||
|
|
||||||
apipatterns = [
|
apipatterns = [
|
||||||
url(r'^barcode/', include(barcode_api_urls)),
|
url(r'^barcode/', include(barcode_api_urls)),
|
||||||
url(r'^common/', include(common_api_urls)),
|
url(r'^settings/', include(common_api_urls)),
|
||||||
url(r'^part/', include(part_api_urls)),
|
url(r'^part/', include(part_api_urls)),
|
||||||
url(r'^bom/', include(bom_api_urls)),
|
url(r'^bom/', include(bom_api_urls)),
|
||||||
url(r'^company/', include(company_api_urls)),
|
url(r'^company/', include(company_api_urls)),
|
||||||
|
@ -5,5 +5,85 @@ Provides a JSON API for common components.
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.conf.urls import url, include
|
||||||
|
|
||||||
|
from django_filters.rest_framework import DjangoFilterBackend
|
||||||
|
from rest_framework import filters, generics
|
||||||
|
|
||||||
|
import common.models
|
||||||
|
import common.serializers
|
||||||
|
|
||||||
|
|
||||||
|
class SettingsList(generics.ListAPIView):
|
||||||
|
|
||||||
|
filter_backends = [
|
||||||
|
DjangoFilterBackend,
|
||||||
|
filters.SearchFilter,
|
||||||
|
filters.OrderingFilter,
|
||||||
|
]
|
||||||
|
|
||||||
|
ordering_fields = [
|
||||||
|
'pk',
|
||||||
|
'key',
|
||||||
|
'name',
|
||||||
|
]
|
||||||
|
|
||||||
|
search_fields = [
|
||||||
|
'key',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class GlobalSettingsList(SettingsList):
|
||||||
|
"""
|
||||||
|
API endpoint for accessing a list of global settings objects
|
||||||
|
"""
|
||||||
|
|
||||||
|
queryset = common.models.InvenTreeSetting.objects.all()
|
||||||
|
serializer_class = common.serializers.GlobalSettingsSerializer
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class UserSettingsList(SettingsList):
|
||||||
|
"""
|
||||||
|
API endpoint for accessing a list of user settings objects
|
||||||
|
"""
|
||||||
|
|
||||||
|
queryset = common.models.InvenTreeUserSetting.objects.all()
|
||||||
|
serializer_class = common.serializers.UserSettingsSerializer
|
||||||
|
|
||||||
|
def filter_queryset(self, queryset):
|
||||||
|
"""
|
||||||
|
Only list settings which apply to the current user
|
||||||
|
"""
|
||||||
|
|
||||||
|
try:
|
||||||
|
user = self.request.user
|
||||||
|
except AttributeError:
|
||||||
|
return common.models.InvenTreeUserSetting.objects.none()
|
||||||
|
|
||||||
|
queryset = super().filter_queryset(queryset)
|
||||||
|
|
||||||
|
queryset = queryset.filter(user=user)
|
||||||
|
|
||||||
|
return queryset
|
||||||
|
|
||||||
|
|
||||||
common_api_urls = [
|
common_api_urls = [
|
||||||
|
|
||||||
|
# User settings
|
||||||
|
url(r'^user/', include([
|
||||||
|
# User Settings Detail
|
||||||
|
|
||||||
|
# User Settings List
|
||||||
|
url(r'^.*$', UserSettingsList.as_view(), name='api-user-setting-list'),
|
||||||
|
])),
|
||||||
|
|
||||||
|
# Global settings
|
||||||
|
url(r'^global/', include([
|
||||||
|
# Global Settings Detail
|
||||||
|
|
||||||
|
# Global Settings List
|
||||||
|
url(r'^.*$', GlobalSettingsList.as_view(), name='api-global-setting-list'),
|
||||||
|
]))
|
||||||
|
|
||||||
]
|
]
|
||||||
|
@ -850,7 +850,7 @@ class InvenTreeSetting(BaseInvenTreeSetting):
|
|||||||
},
|
},
|
||||||
'SIGNUP_GROUP': {
|
'SIGNUP_GROUP': {
|
||||||
'name': _('Group on signup'),
|
'name': _('Group on signup'),
|
||||||
'description': _('Group new user are asigned on registration'),
|
'description': _('Group to which new users are assigned on registration'),
|
||||||
'default': '',
|
'default': '',
|
||||||
'choices': settings_group_options
|
'choices': settings_group_options
|
||||||
},
|
},
|
||||||
|
@ -1,3 +1,58 @@
|
|||||||
"""
|
"""
|
||||||
JSON serializers for common components
|
JSON serializers for common components
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from InvenTree.serializers import InvenTreeModelSerializer
|
||||||
|
|
||||||
|
from rest_framework import serializers
|
||||||
|
|
||||||
|
from common.models import InvenTreeSetting, InvenTreeUserSetting
|
||||||
|
|
||||||
|
class GlobalSettingsSerializer(InvenTreeModelSerializer):
|
||||||
|
"""
|
||||||
|
Serializer for the InvenTreeSetting model
|
||||||
|
"""
|
||||||
|
|
||||||
|
name = serializers.CharField(read_only=True)
|
||||||
|
|
||||||
|
description = serializers.CharField(read_only=True)
|
||||||
|
|
||||||
|
# choices = serializers.CharField(read_only=True, many=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = InvenTreeSetting
|
||||||
|
fields = [
|
||||||
|
'pk',
|
||||||
|
'key',
|
||||||
|
'value',
|
||||||
|
'name',
|
||||||
|
'description',
|
||||||
|
# 'type',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class UserSettingsSerializer(InvenTreeModelSerializer):
|
||||||
|
"""
|
||||||
|
Serializer for the InvenTreeUserSetting model
|
||||||
|
"""
|
||||||
|
|
||||||
|
name = serializers.CharField(read_only=True)
|
||||||
|
|
||||||
|
description = serializers.CharField(read_only=True)
|
||||||
|
|
||||||
|
# choices = serializers.CharField(read_only=True, many=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = InvenTreeUserSetting
|
||||||
|
fields = [
|
||||||
|
'pk',
|
||||||
|
'key',
|
||||||
|
'value',
|
||||||
|
'name',
|
||||||
|
'description',
|
||||||
|
'user',
|
||||||
|
# 'type',
|
||||||
|
]
|
||||||
|
@ -18,3 +18,4 @@ const global_settings = {
|
|||||||
{{ key }}: {% primitive_to_javascript value %},
|
{{ key }}: {% primitive_to_javascript value %},
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user