InvenTree/InvenTree/part/views.py

179 lines
3.8 KiB
Python
Raw Normal View History

2017-04-15 13:14:16 +00:00
from django_filters.rest_framework import FilterSet, DjangoFilterBackend
2017-04-14 02:14:50 +00:00
from rest_framework import generics, permissions
from InvenTree.models import FilterChildren
from .models import PartCategory, Part
2017-04-11 13:33:08 +00:00
from .serializers import PartSerializer
2017-04-14 05:25:10 +00:00
from .serializers import PartCategorySerializer
#from .serializers import PartParameterSerializer
#from .serializers import PartTemplateSerializer
2017-03-28 12:38:12 +00:00
class PartDetail(generics.RetrieveUpdateDestroyAPIView):
2017-04-15 13:04:09 +00:00
"""
get:
Return detail on a single Part
post:
Update data for a single Part
delete:
Remove a part from the database
"""
queryset = Part.objects.all()
2017-04-11 13:33:08 +00:00
serializer_class = PartSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
2017-04-11 13:33:08 +00:00
"""
2017-04-15 13:14:16 +00:00
class PartParamFilter(FilterSet):
class Meta:
model = PartParameter
fields = ['part']
2017-04-14 01:46:18 +00:00
class PartParamList(generics.ListCreateAPIView):
"
2017-04-15 13:04:09 +00:00
get:
Return a list of all part parameters (with optional filters)
post:
Create a new part parameter
""
2017-04-14 01:46:18 +00:00
2017-04-15 13:14:16 +00:00
queryset = PartParameter.objects.all()
2017-04-14 01:46:18 +00:00
serializer_class = PartParameterSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
2017-04-15 13:14:16 +00:00
filter_backends = (DjangoFilterBackend,)
filter_class = PartParamFilter
2017-04-14 01:46:18 +00:00
class PartParamDetail(generics.RetrieveUpdateDestroyAPIView):
""
2017-04-15 13:04:09 +00:00
get:
Detail view of a single PartParameter
post:
Update data for a PartParameter
delete:
Remove a PartParameter from the database
"
2017-04-14 01:46:18 +00:00
queryset = PartParameter.objects.all()
2017-04-11 13:33:08 +00:00
serializer_class = PartParameterSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
"""
2017-03-28 12:31:41 +00:00
2017-04-15 13:14:16 +00:00
class PartFilter(FilterSet):
2017-04-14 02:14:50 +00:00
class Meta:
model = Part
2017-04-15 13:14:16 +00:00
fields = ['category']
2017-04-14 02:14:50 +00:00
class PartList(generics.ListCreateAPIView):
2017-04-15 13:04:09 +00:00
"""
get:
List of Parts, with optional filters
post:
Create a new Part
2017-04-14 02:14:50 +00:00
"""
2017-04-15 13:14:16 +00:00
queryset = Part.objects.all()
2017-04-11 13:33:08 +00:00
serializer_class = PartSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
2017-04-15 13:14:16 +00:00
filter_backends = (DjangoFilterBackend,)
filter_class = PartFilter
2017-03-28 12:31:41 +00:00
2017-04-14 01:46:18 +00:00
class PartCategoryDetail(generics.RetrieveUpdateDestroyAPIView):
2017-04-15 13:04:09 +00:00
"""
get:
Return information on a single PartCategory
post:
Update a PartCategory
delete:
Remove a PartCategory
2017-04-10 23:41:03 +00:00
"""
queryset = PartCategory.objects.all()
2017-04-14 05:25:10 +00:00
serializer_class = PartCategorySerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
2017-03-28 12:31:41 +00:00
class PartCategoryList(generics.ListCreateAPIView):
2017-04-15 13:04:09 +00:00
"""
get:
Return a list of all categories
(with optional filters)
post:
Create a new PartCategory
2017-04-10 23:41:03 +00:00
"""
def get_queryset(self):
params = self.request.query_params
categories = PartCategory.objects.all()
categories = FilterChildren(categories, params.get('parent', None))
return categories
2017-04-10 23:41:03 +00:00
queryset = PartCategory.objects.filter(parent=None)
2017-04-14 05:25:10 +00:00
serializer_class = PartCategorySerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
2017-04-14 01:46:18 +00:00
"""
2017-04-14 01:46:18 +00:00
class PartTemplateDetail(generics.RetrieveUpdateDestroyAPIView):
""
2017-04-15 13:04:09 +00:00
get:
Return detail on a single PartParameterTemplate object
post:
Update a PartParameterTemplate object
delete:
Remove a PartParameterTemplate object
""
2017-04-14 01:46:18 +00:00
queryset = PartParameterTemplate.objects.all()
serializer_class = PartTemplateSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
class PartTemplateList(generics.ListCreateAPIView):
""
2017-04-15 13:04:09 +00:00
get:
Return a list of all PartParameterTemplate objects
(with optional query filters)
post:
Create a new PartParameterTemplate object
""
2017-04-14 01:46:18 +00:00
queryset = PartParameterTemplate.objects.all()
serializer_class = PartTemplateSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
"""