2018-04-23 11:10:13 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import unicode_literals
|
2018-04-14 04:11:46 +00:00
|
|
|
|
2018-04-23 11:18:35 +00:00
|
|
|
from django_filters.rest_framework import DjangoFilterBackend
|
2018-04-23 11:10:13 +00:00
|
|
|
from rest_framework import filters
|
|
|
|
from rest_framework import generics, permissions
|
2018-04-14 04:11:46 +00:00
|
|
|
|
2018-04-23 11:10:13 +00:00
|
|
|
from django.conf.urls import url
|
2018-04-14 04:11:46 +00:00
|
|
|
|
2018-04-28 13:22:12 +00:00
|
|
|
from .models import Part, PartCategory
|
2018-04-23 11:10:13 +00:00
|
|
|
from .serializers import PartSerializer
|
2018-04-14 04:11:46 +00:00
|
|
|
|
2018-04-28 13:22:12 +00:00
|
|
|
from InvenTree.views import TreeSerializer
|
|
|
|
|
|
|
|
class PartCategoryTree(TreeSerializer):
|
|
|
|
|
|
|
|
title = "Parts"
|
|
|
|
model = PartCategory
|
|
|
|
|
2018-04-14 04:11:46 +00:00
|
|
|
|
|
|
|
class PartList(generics.ListCreateAPIView):
|
|
|
|
|
|
|
|
queryset = Part.objects.all()
|
|
|
|
serializer_class = PartSerializer
|
2018-04-15 15:02:17 +00:00
|
|
|
|
2018-04-23 11:10:13 +00:00
|
|
|
permission_classes = [
|
|
|
|
permissions.IsAuthenticatedOrReadOnly,
|
|
|
|
]
|
2018-04-14 04:19:03 +00:00
|
|
|
|
2018-04-23 11:10:13 +00:00
|
|
|
filter_backends = [
|
|
|
|
DjangoFilterBackend,
|
|
|
|
filters.SearchFilter,
|
|
|
|
filters.OrderingFilter,
|
|
|
|
]
|
2018-04-14 04:19:03 +00:00
|
|
|
|
2018-04-23 11:10:13 +00:00
|
|
|
filter_fields = [
|
2018-04-23 11:18:35 +00:00
|
|
|
'category',
|
2018-04-23 11:10:13 +00:00
|
|
|
]
|
2018-04-14 04:19:03 +00:00
|
|
|
|
2018-04-23 11:10:13 +00:00
|
|
|
ordering_fields = [
|
|
|
|
'name',
|
|
|
|
]
|
2018-04-14 04:19:03 +00:00
|
|
|
|
2018-04-23 11:10:13 +00:00
|
|
|
ordering = 'name'
|
2018-04-14 04:19:03 +00:00
|
|
|
|
2018-04-23 11:18:35 +00:00
|
|
|
search_fields = [
|
|
|
|
'name',
|
|
|
|
'description',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2018-04-23 11:10:13 +00:00
|
|
|
part_api_urls = [
|
2018-04-14 04:19:03 +00:00
|
|
|
|
2018-04-28 13:22:12 +00:00
|
|
|
url(r'^tree/?', PartCategoryTree.as_view(), name='api-part-tree'),
|
|
|
|
|
2018-04-23 11:10:13 +00:00
|
|
|
url(r'^.*$', PartList.as_view(), name='api-part-list'),
|
|
|
|
]
|