mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Merge pull request #887 from eeintech/allow_api_thumbnail_update
Allowing Part thumbnail (image) update via API
This commit is contained in:
commit
daab81fa2c
@ -190,6 +190,21 @@ class PartThumbs(generics.ListAPIView):
|
|||||||
return Response(data)
|
return Response(data)
|
||||||
|
|
||||||
|
|
||||||
|
class PartThumbsUpdate(generics.RetrieveUpdateAPIView):
|
||||||
|
""" API endpoint for updating Part thumbnails"""
|
||||||
|
|
||||||
|
queryset = Part.objects.all()
|
||||||
|
serializer_class = part_serializers.PartThumbSerializerUpdate
|
||||||
|
|
||||||
|
permission_classes = [
|
||||||
|
permissions.IsAuthenticated,
|
||||||
|
]
|
||||||
|
|
||||||
|
filter_backends = [
|
||||||
|
DjangoFilterBackend
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class PartDetail(generics.RetrieveUpdateDestroyAPIView):
|
class PartDetail(generics.RetrieveUpdateDestroyAPIView):
|
||||||
""" API endpoint for detail view of a single Part object """
|
""" API endpoint for detail view of a single Part object """
|
||||||
|
|
||||||
@ -716,7 +731,10 @@ part_api_urls = [
|
|||||||
url(r'^.*$', PartParameterList.as_view(), name='api-part-param-list'),
|
url(r'^.*$', PartParameterList.as_view(), name='api-part-param-list'),
|
||||||
])),
|
])),
|
||||||
|
|
||||||
url(r'^thumbs/', PartThumbs.as_view(), name='api-part-thumbs'),
|
url(r'^thumbs/', include([
|
||||||
|
url(r'^$', PartThumbs.as_view(), name='api-part-thumbs'),
|
||||||
|
url(r'^(?P<pk>\d+)/?', PartThumbsUpdate.as_view(), name='api-part-thumbs-update'),
|
||||||
|
])),
|
||||||
|
|
||||||
url(r'^(?P<pk>\d+)/?', PartDetail.as_view(), name='api-part-detail'),
|
url(r'^(?P<pk>\d+)/?', PartDetail.as_view(), name='api-part-detail'),
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
"""
|
"""
|
||||||
JSON serializers for Part app
|
JSON serializers for Part app
|
||||||
"""
|
"""
|
||||||
|
import imghdr
|
||||||
|
|
||||||
from rest_framework import serializers
|
from rest_framework import serializers
|
||||||
|
|
||||||
@ -92,6 +93,27 @@ class PartThumbSerializer(serializers.Serializer):
|
|||||||
count = serializers.IntegerField(read_only=True)
|
count = serializers.IntegerField(read_only=True)
|
||||||
|
|
||||||
|
|
||||||
|
class PartThumbSerializerUpdate(InvenTreeModelSerializer):
|
||||||
|
""" Serializer for updating Part thumbnail """
|
||||||
|
|
||||||
|
def validate_image(self, value):
|
||||||
|
"""
|
||||||
|
Check that file is an image.
|
||||||
|
"""
|
||||||
|
validate = imghdr.what(value)
|
||||||
|
if not validate:
|
||||||
|
raise serializers.ValidationError("File is not an image")
|
||||||
|
return value
|
||||||
|
|
||||||
|
image = InvenTreeAttachmentSerializerField(required=True)
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Part
|
||||||
|
fields = [
|
||||||
|
'image',
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class PartBriefSerializer(InvenTreeModelSerializer):
|
class PartBriefSerializer(InvenTreeModelSerializer):
|
||||||
""" Serializer for Part (brief detail) """
|
""" Serializer for Part (brief detail) """
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user