mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Expose test templates to the API
This commit is contained in:
parent
f791ac9f57
commit
4d992ea528
@ -19,7 +19,7 @@ from django.urls import reverse
|
||||
|
||||
from .models import Part, PartCategory, BomItem, PartStar
|
||||
from .models import PartParameter, PartParameterTemplate
|
||||
from .models import PartAttachment
|
||||
from .models import PartAttachment, PartTestTemplate
|
||||
|
||||
from . import serializers as part_serializers
|
||||
|
||||
@ -120,6 +120,45 @@ class PartAttachmentList(generics.ListCreateAPIView, AttachmentMixin):
|
||||
]
|
||||
|
||||
|
||||
class PartTestTemplateList(generics.ListCreateAPIView):
|
||||
"""
|
||||
API endpoint for listing (and creating) a PartTestTemplate.
|
||||
"""
|
||||
|
||||
queryset = PartTestTemplate.objects.all()
|
||||
serializer_class = part_serializers.PartTestTemplateSerializer
|
||||
|
||||
def filter_queryset(self, queryset):
|
||||
"""
|
||||
Filter the test list queryset.
|
||||
|
||||
If filtering by 'part', we include results for any parts "above" the specified part.
|
||||
"""
|
||||
|
||||
queryset = super().filter_queryset(queryset)
|
||||
|
||||
params = self.request.query_params
|
||||
|
||||
part = params.get('part', None)
|
||||
|
||||
# Filter by part
|
||||
if part:
|
||||
try:
|
||||
part = Part.objects.get(pk=part)
|
||||
queryset = queryset.filter(part__in=part.get_ancestors(include_self=True))
|
||||
except (ValueError, Part.DoesNotExist):
|
||||
pass
|
||||
|
||||
return queryset
|
||||
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
|
||||
filter_backends = [
|
||||
DjangoFilterBackend,
|
||||
filters.OrderingFilter,
|
||||
filters.SearchFilter,
|
||||
]
|
||||
|
||||
class PartThumbs(generics.ListAPIView):
|
||||
""" API endpoint for retrieving information on available Part thumbnails """
|
||||
|
||||
@ -635,8 +674,13 @@ part_api_urls = [
|
||||
url(r'^$', CategoryList.as_view(), name='api-part-category-list'),
|
||||
])),
|
||||
|
||||
# Base URL for PartTestTemplate API endpoints
|
||||
url(r'^test-template/', include([
|
||||
url(r'^$', PartTestTemplateList.as_view(), name='api-part-test-template-list'),
|
||||
])),
|
||||
|
||||
# Base URL for PartAttachment API endpoints
|
||||
url(r'attachment/', include([
|
||||
url(r'^attachment/', include([
|
||||
url(r'^$', PartAttachmentList.as_view(), name='api-part-attachment-list'),
|
||||
])),
|
||||
|
||||
|
@ -10,6 +10,7 @@ from .models import PartCategory
|
||||
from .models import BomItem
|
||||
from .models import PartParameter, PartParameterTemplate
|
||||
from .models import PartAttachment
|
||||
from .models import PartTestTemplate
|
||||
|
||||
from decimal import Decimal
|
||||
|
||||
@ -56,6 +57,22 @@ class PartAttachmentSerializer(InvenTreeModelSerializer):
|
||||
]
|
||||
|
||||
|
||||
class PartTestTemplateSerializer(InvenTreeModelSerializer):
|
||||
"""
|
||||
Serializer for the PartTestTemplate class
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = PartTestTemplate
|
||||
|
||||
fields = [
|
||||
'pk',
|
||||
'part',
|
||||
'test_name',
|
||||
'required'
|
||||
]
|
||||
|
||||
|
||||
class PartThumbSerializer(serializers.Serializer):
|
||||
"""
|
||||
Serializer for the 'image' field of the Part model.
|
||||
|
Loading…
Reference in New Issue
Block a user