Bug fix: Part thumbnail API list was not working

- Part images could not be selected from grid
This commit is contained in:
Oliver Walters 2020-11-04 15:41:17 +11:00
parent fc99086c8f
commit f560be1a9a
3 changed files with 28 additions and 4 deletions

View File

@ -15,7 +15,9 @@ InvenTree | {% trans "Supplier List" %}
{% if pagetype == 'manufacturers' and roles.purchase_order.add or pagetype == 'suppliers' and roles.purchase_order.add or pagetype == 'customers' and roles.sales_order.add %} {% if pagetype == 'manufacturers' and roles.purchase_order.add or pagetype == 'suppliers' and roles.purchase_order.add or pagetype == 'customers' and roles.sales_order.add %}
<div id='button-toolbar'> <div id='button-toolbar'>
<div class='btn-group'> <div class='btn-group'>
<button type='button' class="btn btn-success" id='new-company'>{{ button_text }}</button> <button type='button' class="btn btn-success" id='new-company'>
<span class='fas fa-plus-circle'></span> {{ button_text }}
</button>
</div> </div>
</div> </div>
{% endif %} {% endif %}

View File

@ -186,18 +186,29 @@ class PartTestTemplateList(generics.ListCreateAPIView):
class PartThumbs(generics.ListAPIView): class PartThumbs(generics.ListAPIView):
""" API endpoint for retrieving information on available Part thumbnails """ """
API endpoint for retrieving information on available Part thumbnails
"""
queryset = Part.objects.all()
serializer_class = part_serializers.PartThumbSerializer serializer_class = part_serializers.PartThumbSerializer
def get_queryset(self):
queryset = super().get_queryset()
# Get all Parts which have an associated image
queryset = queryset.exclude(image='')
return queryset
def list(self, request, *args, **kwargs): def list(self, request, *args, **kwargs):
""" """
Serialize the available Part images. Serialize the available Part images.
- Images may be used for multiple parts! - Images may be used for multiple parts!
""" """
# Get all Parts which have an associated image queryset = self.get_queryset()
queryset = Part.objects.all().exclude(image='')
# TODO - We should return the thumbnails here, not the full image! # TODO - We should return the thumbnails here, not the full image!

View File

@ -241,6 +241,17 @@ class PartAPITest(APITestCase):
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def test_get_thumbs(self):
"""
Return list of part thumbnails
"""
url = reverse('api-part-thumbs')
response = self.client.get(url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
class PartAPIAggregationTest(APITestCase): class PartAPIAggregationTest(APITestCase):
""" """