mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Enable optional pagination for the BomItem API endpoint
This commit is contained in:
parent
a00dc9b0b1
commit
7c396f9f39
@ -1078,11 +1078,23 @@ class BomList(generics.ListCreateAPIView):
|
|||||||
|
|
||||||
queryset = self.filter_queryset(self.get_queryset())
|
queryset = self.filter_queryset(self.get_queryset())
|
||||||
|
|
||||||
|
page = self.paginate_queryset(queryset)
|
||||||
|
|
||||||
|
if page is not None:
|
||||||
|
serializer = self.get_serializer(page, many=True)
|
||||||
|
else:
|
||||||
serializer = self.get_serializer(queryset, many=True)
|
serializer = self.get_serializer(queryset, many=True)
|
||||||
|
|
||||||
data = serializer.data
|
data = serializer.data
|
||||||
|
|
||||||
if request.is_ajax():
|
"""
|
||||||
|
Determine the response type based on the request.
|
||||||
|
a) For HTTP requests (e.g. via the browseable API) return a DRF response
|
||||||
|
b) For AJAX requests, simply return a JSON rendered response.
|
||||||
|
"""
|
||||||
|
if page is not None:
|
||||||
|
return self.get_paginated_response(data)
|
||||||
|
elif request.is_ajax():
|
||||||
return JsonResponse(data, safe=False)
|
return JsonResponse(data, safe=False)
|
||||||
else:
|
else:
|
||||||
return Response(data)
|
return Response(data)
|
||||||
@ -1147,7 +1159,9 @@ class BomList(generics.ListCreateAPIView):
|
|||||||
except (ValueError, Part.DoesNotExist):
|
except (ValueError, Part.DoesNotExist):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
include_pricing = str2bool(params.get('include_pricing', True))
|
pricing_default = InvenTreeSetting.get_setting('PART_SHOW_PRICE_IN_BOM')
|
||||||
|
|
||||||
|
include_pricing = str2bool(params.get('include_pricing', pricing_default))
|
||||||
|
|
||||||
if include_pricing:
|
if include_pricing:
|
||||||
queryset = self.annotate_pricing(queryset)
|
queryset = self.annotate_pricing(queryset)
|
||||||
|
Loading…
Reference in New Issue
Block a user