2019-04-27 12:18:07 +00:00
|
|
|
"""
|
|
|
|
Provides a JSON API for the Part app
|
|
|
|
"""
|
|
|
|
|
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
|
2019-06-17 15:31:30 +00:00
|
|
|
from django.conf import settings
|
|
|
|
|
2020-03-26 06:08:01 +00:00
|
|
|
from django.db.models import Q, Sum, Count
|
2019-05-04 23:14:12 +00:00
|
|
|
|
2019-05-05 00:47:57 +00:00
|
|
|
from rest_framework import status
|
|
|
|
from rest_framework.response import Response
|
2019-09-05 09:29:51 +00:00
|
|
|
from rest_framework import filters, serializers
|
2019-04-13 23:25:46 +00:00
|
|
|
from rest_framework import generics, permissions
|
2018-04-14 04:11:46 +00:00
|
|
|
|
2018-05-04 13:54:57 +00:00
|
|
|
from django.conf.urls import url, include
|
2019-05-09 12:23:56 +00:00
|
|
|
from django.urls import reverse
|
2018-04-14 04:11:46 +00:00
|
|
|
|
2019-06-17 15:31:30 +00:00
|
|
|
import os
|
|
|
|
|
2019-05-04 23:05:44 +00:00
|
|
|
from .models import Part, PartCategory, BomItem, PartStar
|
2019-09-07 09:44:10 +00:00
|
|
|
from .models import PartParameter, PartParameterTemplate
|
2018-05-02 14:47:03 +00:00
|
|
|
|
2020-02-10 11:03:06 +00:00
|
|
|
from . import serializers as part_serializers
|
2018-04-14 04:11:46 +00:00
|
|
|
|
2020-03-26 06:43:02 +00:00
|
|
|
from InvenTree.status_codes import OrderStatus, StockStatus, BuildStatus
|
2018-04-28 13:22:12 +00:00
|
|
|
from InvenTree.views import TreeSerializer
|
2019-05-23 12:36:19 +00:00
|
|
|
from InvenTree.helpers import str2bool
|
2018-04-28 13:22:12 +00:00
|
|
|
|
2019-04-13 23:25:46 +00:00
|
|
|
|
2018-04-28 13:22:12 +00:00
|
|
|
class PartCategoryTree(TreeSerializer):
|
|
|
|
|
|
|
|
title = "Parts"
|
|
|
|
model = PartCategory
|
2019-05-09 12:23:56 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def root_url(self):
|
|
|
|
return reverse('part-index')
|
2018-04-28 13:22:12 +00:00
|
|
|
|
2019-06-17 13:52:49 +00:00
|
|
|
def get_items(self):
|
|
|
|
return PartCategory.objects.all().prefetch_related('parts', 'children')
|
|
|
|
|
2018-04-14 04:11:46 +00:00
|
|
|
|
2018-05-04 13:54:57 +00:00
|
|
|
class CategoryList(generics.ListCreateAPIView):
|
2019-04-27 12:18:07 +00:00
|
|
|
""" API endpoint for accessing a list of PartCategory objects.
|
|
|
|
|
|
|
|
- GET: Return a list of PartCategory objects
|
|
|
|
- POST: Create a new PartCategory object
|
|
|
|
"""
|
|
|
|
|
2018-05-04 13:54:57 +00:00
|
|
|
queryset = PartCategory.objects.all()
|
2020-02-10 11:03:06 +00:00
|
|
|
serializer_class = part_serializers.CategorySerializer
|
2018-05-04 13:54:57 +00:00
|
|
|
|
|
|
|
permission_classes = [
|
2019-07-08 09:20:00 +00:00
|
|
|
permissions.IsAuthenticated,
|
2018-05-04 13:54:57 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
filter_backends = [
|
|
|
|
DjangoFilterBackend,
|
2019-06-02 09:15:05 +00:00
|
|
|
filters.SearchFilter,
|
2018-05-04 13:54:57 +00:00
|
|
|
filters.OrderingFilter,
|
|
|
|
]
|
|
|
|
|
|
|
|
filter_fields = [
|
|
|
|
'parent',
|
|
|
|
]
|
|
|
|
|
|
|
|
ordering_fields = [
|
|
|
|
'name',
|
|
|
|
]
|
|
|
|
|
|
|
|
ordering = 'name'
|
|
|
|
|
|
|
|
search_fields = [
|
|
|
|
'name',
|
|
|
|
'description',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-04-26 15:03:11 +00:00
|
|
|
class CategoryDetail(generics.RetrieveUpdateDestroyAPIView):
|
2019-04-27 12:18:07 +00:00
|
|
|
""" API endpoint for detail view of a single PartCategory object """
|
2020-02-10 11:03:06 +00:00
|
|
|
serializer_class = part_serializers.CategorySerializer
|
2019-04-26 15:03:11 +00:00
|
|
|
queryset = PartCategory.objects.all()
|
|
|
|
|
|
|
|
|
2020-02-10 11:03:06 +00:00
|
|
|
class PartThumbs(generics.ListAPIView):
|
|
|
|
""" API endpoint for retrieving information on available Part thumbnails """
|
|
|
|
|
|
|
|
serializer_class = part_serializers.PartThumbSerializer
|
|
|
|
|
|
|
|
def list(self, reguest, *args, **kwargs):
|
|
|
|
"""
|
|
|
|
Serialize the available Part images.
|
|
|
|
- Images may be used for multiple parts!
|
|
|
|
"""
|
|
|
|
|
|
|
|
# Get all Parts which have an associated image
|
|
|
|
queryset = Part.objects.all().exclude(image='')
|
|
|
|
|
2020-02-10 12:48:45 +00:00
|
|
|
# Return the most popular parts first
|
2020-02-10 11:03:06 +00:00
|
|
|
data = queryset.values(
|
|
|
|
'image',
|
|
|
|
).annotate(count=Count('image')).order_by('-count')
|
|
|
|
|
|
|
|
return Response(data)
|
|
|
|
|
|
|
|
|
2019-04-28 13:41:47 +00:00
|
|
|
class PartDetail(generics.RetrieveUpdateAPIView):
|
2019-04-27 12:18:07 +00:00
|
|
|
""" API endpoint for detail view of a single Part object """
|
2020-02-10 12:48:45 +00:00
|
|
|
|
2018-05-04 14:51:17 +00:00
|
|
|
queryset = Part.objects.all()
|
2020-02-10 11:03:06 +00:00
|
|
|
serializer_class = part_serializers.PartSerializer
|
2018-05-04 14:51:17 +00:00
|
|
|
|
|
|
|
permission_classes = [
|
2019-07-08 09:20:00 +00:00
|
|
|
permissions.IsAuthenticated,
|
2018-05-04 14:51:17 +00:00
|
|
|
]
|
|
|
|
|
2019-04-13 23:25:46 +00:00
|
|
|
|
2018-04-14 04:11:46 +00:00
|
|
|
class PartList(generics.ListCreateAPIView):
|
2019-04-27 12:18:07 +00:00
|
|
|
""" API endpoint for accessing a list of Part objects
|
|
|
|
|
|
|
|
- GET: Return list of objects
|
|
|
|
- POST: Create a new Part object
|
|
|
|
"""
|
2018-04-14 04:11:46 +00:00
|
|
|
|
2020-02-10 11:03:06 +00:00
|
|
|
serializer_class = part_serializers.PartSerializer
|
2018-04-15 15:02:17 +00:00
|
|
|
|
2020-03-18 11:00:32 +00:00
|
|
|
def create(self, request, *args, **kwargs):
|
|
|
|
""" Override the default 'create' behaviour:
|
|
|
|
We wish to save the user who created this part!
|
|
|
|
|
|
|
|
Note: Implementation coped from DRF class CreateModelMixin
|
|
|
|
"""
|
|
|
|
|
|
|
|
serializer = self.get_serializer(data=request.data)
|
|
|
|
serializer.is_valid(raise_exception=True)
|
|
|
|
|
|
|
|
# Record the user who created this Part object
|
|
|
|
part = serializer.save()
|
|
|
|
part.creation_user = request.user
|
|
|
|
part.save()
|
|
|
|
|
|
|
|
headers = self.get_success_headers(serializer.data)
|
|
|
|
return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
|
|
|
|
|
2019-06-17 15:31:30 +00:00
|
|
|
def list(self, request, *args, **kwargs):
|
|
|
|
"""
|
|
|
|
Instead of using the DRF serialiser to LIST,
|
2020-02-10 11:03:06 +00:00
|
|
|
we serialize the objects manually.
|
2019-06-17 15:31:30 +00:00
|
|
|
This turns out to be significantly faster.
|
|
|
|
"""
|
|
|
|
|
|
|
|
queryset = self.filter_queryset(self.get_queryset())
|
|
|
|
|
2020-03-26 06:08:01 +00:00
|
|
|
# Filters for annotations
|
|
|
|
|
|
|
|
# "in_stock" count should only sum stock items which are "in stock"
|
|
|
|
stock_filter = Q(stock_items__status__in=StockStatus.AVAILABLE_CODES)
|
|
|
|
|
|
|
|
# "on_order" items should only sum orders which are currently outstanding
|
|
|
|
order_filter = Q(supplier_parts__purchase_order_line_items__order__status__in=OrderStatus.OPEN)
|
|
|
|
|
2020-03-26 06:43:02 +00:00
|
|
|
# "building" should only reference builds which are active
|
|
|
|
build_filter = Q(builds__status__in=BuildStatus.ACTIVE_CODES)
|
|
|
|
|
2020-03-26 06:08:01 +00:00
|
|
|
# Set of fields we wish to serialize
|
2019-06-17 15:31:30 +00:00
|
|
|
data = queryset.values(
|
|
|
|
'pk',
|
|
|
|
'category',
|
|
|
|
'image',
|
|
|
|
'name',
|
|
|
|
'IPN',
|
2019-06-20 11:46:16 +00:00
|
|
|
'revision',
|
2019-06-17 15:31:30 +00:00
|
|
|
'description',
|
|
|
|
'keywords',
|
|
|
|
'is_template',
|
|
|
|
'URL',
|
|
|
|
'units',
|
2020-03-30 02:21:33 +00:00
|
|
|
'minimum_stock',
|
2019-06-17 15:31:30 +00:00
|
|
|
'trackable',
|
|
|
|
'assembly',
|
|
|
|
'component',
|
|
|
|
'salable',
|
|
|
|
'active',
|
|
|
|
).annotate(
|
2020-03-26 06:08:01 +00:00
|
|
|
# Quantity of items which are "in stock"
|
|
|
|
in_stock=Sum('stock_items__quantity', filter=stock_filter),
|
2020-03-26 06:43:02 +00:00
|
|
|
on_order=Sum('supplier_parts__purchase_order_line_items__quantity', filter=order_filter),
|
|
|
|
building=Sum('builds__quantity', filter=build_filter),
|
2019-06-17 15:31:30 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
# Reduce the number of lookups we need to do for the part categories
|
|
|
|
categories = {}
|
|
|
|
|
|
|
|
for item in data:
|
|
|
|
|
|
|
|
if item['image']:
|
|
|
|
item['image'] = os.path.join(settings.MEDIA_URL, item['image'])
|
|
|
|
|
|
|
|
cat_id = item['category']
|
|
|
|
|
|
|
|
if cat_id:
|
|
|
|
if cat_id not in categories:
|
|
|
|
categories[cat_id] = PartCategory.objects.get(pk=cat_id).pathstring
|
|
|
|
|
|
|
|
item['category__name'] = categories[cat_id]
|
|
|
|
else:
|
|
|
|
item['category__name'] = None
|
|
|
|
|
|
|
|
return Response(data)
|
|
|
|
|
2019-04-14 01:59:07 +00:00
|
|
|
def get_queryset(self):
|
|
|
|
|
|
|
|
# Does the user wish to filter by category?
|
|
|
|
cat_id = self.request.query_params.get('category', None)
|
|
|
|
|
2019-04-15 12:39:28 +00:00
|
|
|
# Start with all objects
|
|
|
|
parts_list = Part.objects.all()
|
|
|
|
|
2019-04-14 01:59:07 +00:00
|
|
|
if cat_id:
|
2019-04-28 01:09:19 +00:00
|
|
|
try:
|
|
|
|
category = PartCategory.objects.get(pk=cat_id)
|
2019-06-17 15:38:43 +00:00
|
|
|
parts_list = parts_list.filter(category__in=category.getUniqueChildren())
|
2019-04-28 01:09:19 +00:00
|
|
|
except PartCategory.DoesNotExist:
|
|
|
|
pass
|
2019-04-14 02:30:06 +00:00
|
|
|
|
2019-05-19 22:13:22 +00:00
|
|
|
# Ensure that related models are pre-loaded to reduce DB trips
|
|
|
|
parts_list = self.get_serializer_class().setup_eager_loading(parts_list)
|
|
|
|
|
2019-04-15 12:39:28 +00:00
|
|
|
return parts_list
|
2019-04-14 01:59:07 +00:00
|
|
|
|
2018-04-23 11:10:13 +00:00
|
|
|
permission_classes = [
|
2019-07-08 09:20:00 +00:00
|
|
|
permissions.IsAuthenticated,
|
2018-04-23 11:10:13 +00:00
|
|
|
]
|
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 = [
|
2019-05-26 01:15:41 +00:00
|
|
|
'is_template',
|
|
|
|
'variant_of',
|
2019-06-02 09:46:30 +00:00
|
|
|
'assembly',
|
|
|
|
'component',
|
2019-04-15 14:01:15 +00:00
|
|
|
'trackable',
|
|
|
|
'purchaseable',
|
|
|
|
'salable',
|
2019-04-28 13:15:30 +00:00
|
|
|
'active',
|
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 = [
|
2019-04-16 22:19:40 +00:00
|
|
|
'$name',
|
2018-04-23 11:18:35 +00:00
|
|
|
'description',
|
2019-05-06 01:23:55 +00:00
|
|
|
'$IPN',
|
2019-05-14 07:23:20 +00:00
|
|
|
'keywords',
|
2018-04-23 11:18:35 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-05-05 00:36:48 +00:00
|
|
|
class PartStarDetail(generics.RetrieveDestroyAPIView):
|
|
|
|
""" API endpoint for viewing or removing a PartStar object """
|
|
|
|
|
|
|
|
queryset = PartStar.objects.all()
|
2020-02-10 11:03:06 +00:00
|
|
|
serializer_class = part_serializers.PartStarSerializer
|
2019-05-05 00:36:48 +00:00
|
|
|
|
|
|
|
|
2019-05-04 23:05:44 +00:00
|
|
|
class PartStarList(generics.ListCreateAPIView):
|
|
|
|
""" API endpoint for accessing a list of PartStar objects.
|
|
|
|
|
|
|
|
- GET: Return list of PartStar objects
|
|
|
|
- POST: Create a new PartStar object
|
|
|
|
"""
|
|
|
|
|
|
|
|
queryset = PartStar.objects.all()
|
2020-02-10 11:03:06 +00:00
|
|
|
serializer_class = part_serializers.PartStarSerializer
|
2019-05-04 23:05:44 +00:00
|
|
|
|
2019-05-04 23:14:12 +00:00
|
|
|
def create(self, request, *args, **kwargs):
|
|
|
|
|
2019-05-05 00:47:57 +00:00
|
|
|
# Override the user field (with the logged-in user)
|
2019-05-05 00:36:48 +00:00
|
|
|
data = request.data.copy()
|
|
|
|
data['user'] = str(request.user.id)
|
|
|
|
|
|
|
|
serializer = self.get_serializer(data=data)
|
2019-05-04 23:14:12 +00:00
|
|
|
|
2019-05-05 00:36:48 +00:00
|
|
|
serializer.is_valid(raise_exception=True)
|
|
|
|
self.perform_create(serializer)
|
|
|
|
headers = self.get_success_headers(serializer.data)
|
|
|
|
return Response(serializer.data, status=status.HTTP_201_CREATED, headers=headers)
|
2019-05-04 23:14:12 +00:00
|
|
|
|
2019-05-04 23:05:44 +00:00
|
|
|
permission_classes = [
|
2019-07-08 09:20:00 +00:00
|
|
|
permissions.IsAuthenticated,
|
2019-05-04 23:05:44 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
filter_backends = [
|
|
|
|
DjangoFilterBackend,
|
|
|
|
filters.SearchFilter
|
|
|
|
]
|
|
|
|
|
|
|
|
filter_fields = [
|
|
|
|
'part',
|
|
|
|
'user',
|
|
|
|
]
|
|
|
|
|
|
|
|
search_fields = [
|
|
|
|
'partname'
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-09-07 09:44:10 +00:00
|
|
|
class PartParameterTemplateList(generics.ListCreateAPIView):
|
|
|
|
""" API endpoint for accessing a list of PartParameterTemplate objects.
|
|
|
|
|
|
|
|
- GET: Return list of PartParameterTemplate objects
|
|
|
|
- POST: Create a new PartParameterTemplate object
|
|
|
|
"""
|
|
|
|
|
|
|
|
queryset = PartParameterTemplate.objects.all()
|
2020-02-10 11:03:06 +00:00
|
|
|
serializer_class = part_serializers.PartParameterTemplateSerializer
|
2019-09-07 09:44:10 +00:00
|
|
|
|
|
|
|
permission_classes = [
|
|
|
|
permissions.IsAuthenticated,
|
|
|
|
]
|
|
|
|
|
|
|
|
filter_backends = [
|
|
|
|
filters.OrderingFilter,
|
|
|
|
]
|
|
|
|
|
|
|
|
filter_fields = [
|
|
|
|
'name',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
|
|
class PartParameterList(generics.ListCreateAPIView):
|
|
|
|
""" API endpoint for accessing a list of PartParameter objects
|
|
|
|
|
|
|
|
- GET: Return list of PartParameter objects
|
|
|
|
- POST: Create a new PartParameter object
|
|
|
|
"""
|
|
|
|
|
|
|
|
queryset = PartParameter.objects.all()
|
2020-02-10 11:03:06 +00:00
|
|
|
serializer_class = part_serializers.PartParameterSerializer
|
2019-09-07 09:44:10 +00:00
|
|
|
|
|
|
|
permission_classes = [
|
|
|
|
permissions.IsAuthenticated,
|
|
|
|
]
|
|
|
|
|
|
|
|
filter_backends = [
|
|
|
|
DjangoFilterBackend
|
|
|
|
]
|
|
|
|
|
|
|
|
filter_fields = [
|
|
|
|
'part',
|
|
|
|
'template',
|
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-04-25 14:29:53 +00:00
|
|
|
class BomList(generics.ListCreateAPIView):
|
2019-05-04 23:05:44 +00:00
|
|
|
""" API endpoint for accessing a list of BomItem objects.
|
2019-04-27 12:18:07 +00:00
|
|
|
|
|
|
|
- GET: Return list of BomItem objects
|
|
|
|
- POST: Create a new BomItem object
|
|
|
|
"""
|
2019-05-23 12:36:19 +00:00
|
|
|
|
2020-02-10 11:03:06 +00:00
|
|
|
serializer_class = part_serializers.BomItemSerializer
|
2019-05-23 12:36:19 +00:00
|
|
|
|
|
|
|
def get_serializer(self, *args, **kwargs):
|
|
|
|
|
|
|
|
# Do we wish to include extra detail?
|
2019-07-07 23:39:58 +00:00
|
|
|
try:
|
|
|
|
part_detail = str2bool(self.request.GET.get('part_detail', None))
|
|
|
|
sub_part_detail = str2bool(self.request.GET.get('sub_part_detail', None))
|
|
|
|
except AttributeError:
|
|
|
|
part_detail = None
|
|
|
|
sub_part_detail = None
|
2019-05-23 12:36:19 +00:00
|
|
|
|
|
|
|
kwargs['part_detail'] = part_detail
|
|
|
|
kwargs['sub_part_detail'] = sub_part_detail
|
|
|
|
|
|
|
|
kwargs['context'] = self.get_serializer_context()
|
|
|
|
return self.serializer_class(*args, **kwargs)
|
2018-05-02 13:42:57 +00:00
|
|
|
|
2019-05-19 22:31:03 +00:00
|
|
|
def get_queryset(self):
|
|
|
|
queryset = BomItem.objects.all()
|
|
|
|
queryset = self.get_serializer_class().setup_eager_loading(queryset)
|
|
|
|
return queryset
|
|
|
|
|
2018-05-02 13:42:57 +00:00
|
|
|
permission_classes = [
|
2019-07-08 09:20:00 +00:00
|
|
|
permissions.IsAuthenticated,
|
2018-05-02 13:42:57 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
filter_backends = [
|
|
|
|
DjangoFilterBackend,
|
|
|
|
filters.SearchFilter,
|
|
|
|
filters.OrderingFilter,
|
|
|
|
]
|
|
|
|
|
|
|
|
filter_fields = [
|
|
|
|
'part',
|
2019-09-05 09:29:51 +00:00
|
|
|
'sub_part',
|
2018-05-02 13:42:57 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-04-25 14:29:53 +00:00
|
|
|
class BomDetail(generics.RetrieveUpdateDestroyAPIView):
|
2019-04-27 12:18:07 +00:00
|
|
|
""" API endpoint for detail view of a single BomItem object """
|
2019-04-25 14:29:53 +00:00
|
|
|
|
|
|
|
queryset = BomItem.objects.all()
|
2020-02-10 11:03:06 +00:00
|
|
|
serializer_class = part_serializers.BomItemSerializer
|
2019-04-25 14:29:53 +00:00
|
|
|
|
|
|
|
permission_classes = [
|
2019-07-08 09:20:00 +00:00
|
|
|
permissions.IsAuthenticated,
|
2019-04-25 14:29:53 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
|
2019-09-05 09:29:51 +00:00
|
|
|
class BomItemValidate(generics.UpdateAPIView):
|
|
|
|
""" API endpoint for validating a BomItem """
|
|
|
|
|
|
|
|
# Very simple serializers
|
|
|
|
class BomItemValidationSerializer(serializers.Serializer):
|
|
|
|
|
|
|
|
valid = serializers.BooleanField(default=False)
|
|
|
|
|
|
|
|
queryset = BomItem.objects.all()
|
|
|
|
serializer_class = BomItemValidationSerializer
|
|
|
|
|
|
|
|
def update(self, request, *args, **kwargs):
|
|
|
|
""" Perform update request """
|
|
|
|
|
|
|
|
partial = kwargs.pop('partial', False)
|
|
|
|
|
|
|
|
valid = request.data.get('valid', False)
|
|
|
|
|
|
|
|
instance = self.get_object()
|
|
|
|
|
|
|
|
serializer = self.get_serializer(instance, data=request.data, partial=partial)
|
|
|
|
serializer.is_valid(raise_exception=True)
|
|
|
|
|
|
|
|
if type(instance) == BomItem:
|
|
|
|
instance.validate_hash(valid)
|
|
|
|
|
|
|
|
return Response(serializer.data)
|
|
|
|
|
|
|
|
|
2019-04-13 23:25:46 +00:00
|
|
|
cat_api_urls = [
|
2019-04-26 15:03:11 +00:00
|
|
|
|
|
|
|
url(r'^(?P<pk>\d+)/?', CategoryDetail.as_view(), name='api-part-category-detail'),
|
|
|
|
|
2018-05-04 13:54:57 +00:00
|
|
|
url(r'^$', CategoryList.as_view(), name='api-part-category-list'),
|
|
|
|
]
|
2018-05-02 14:47:03 +00:00
|
|
|
|
2019-04-25 13:56:03 +00:00
|
|
|
|
2019-05-04 23:05:44 +00:00
|
|
|
part_star_api_urls = [
|
2019-05-05 00:36:48 +00:00
|
|
|
url(r'^(?P<pk>\d+)/?', PartStarDetail.as_view(), name='api-part-star-detail'),
|
2019-05-04 23:05:44 +00:00
|
|
|
|
|
|
|
# Catchall
|
|
|
|
url(r'^.*$', PartStarList.as_view(), name='api-part-star-list'),
|
|
|
|
]
|
|
|
|
|
2019-09-07 09:44:10 +00:00
|
|
|
part_param_api_urls = [
|
2019-09-07 09:53:47 +00:00
|
|
|
url(r'^template/$', PartParameterTemplateList.as_view(), name='api-part-param-template-list'),
|
2019-09-07 09:44:10 +00:00
|
|
|
|
|
|
|
url(r'^.*$', PartParameterList.as_view(), name='api-part-param-list'),
|
|
|
|
]
|
2019-05-18 10:24:09 +00:00
|
|
|
|
2018-04-23 11:10:13 +00:00
|
|
|
part_api_urls = [
|
2018-04-28 13:22:12 +00:00
|
|
|
url(r'^tree/?', PartCategoryTree.as_view(), name='api-part-tree'),
|
|
|
|
|
2018-05-04 13:54:57 +00:00
|
|
|
url(r'^category/', include(cat_api_urls)),
|
2019-05-04 23:05:44 +00:00
|
|
|
url(r'^star/', include(part_star_api_urls)),
|
2019-09-07 09:44:10 +00:00
|
|
|
url(r'^parameter/', include(part_param_api_urls)),
|
2019-05-04 23:05:44 +00:00
|
|
|
|
2020-02-10 11:03:06 +00:00
|
|
|
url(r'^thumbs/', PartThumbs.as_view(), name='api-part-thumbs'),
|
|
|
|
|
2019-06-23 14:01:34 +00:00
|
|
|
url(r'^(?P<pk>\d+)/?', PartDetail.as_view(), name='api-part-detail'),
|
2018-05-04 14:51:17 +00:00
|
|
|
|
2018-04-23 11:10:13 +00:00
|
|
|
url(r'^.*$', PartList.as_view(), name='api-part-list'),
|
|
|
|
]
|
2019-04-25 14:29:53 +00:00
|
|
|
|
2019-09-05 09:29:51 +00:00
|
|
|
bom_item_urls = [
|
|
|
|
|
|
|
|
url(r'^validate/?', BomItemValidate.as_view(), name='api-bom-item-validate'),
|
|
|
|
|
|
|
|
url(r'^.*$', BomDetail.as_view(), name='api-bom-item-detail'),
|
|
|
|
]
|
2019-05-18 10:24:09 +00:00
|
|
|
|
2019-04-25 14:29:53 +00:00
|
|
|
bom_api_urls = [
|
|
|
|
# BOM Item Detail
|
2019-09-05 09:29:51 +00:00
|
|
|
url(r'^(?P<pk>\d+)/', include(bom_item_urls)),
|
2019-04-25 14:29:53 +00:00
|
|
|
|
|
|
|
# Catch-all
|
|
|
|
url(r'^.*$', BomList.as_view(), name='api-bom-list'),
|
2019-04-26 13:34:15 +00:00
|
|
|
]
|