mirror of
https://github.com/netbox-community/netbox.git
synced 2025-08-23 07:56:44 -06:00
Implement the limit parameter for the available-vlans endpoint
This commit is contained in:
parent
7a44a4e305
commit
d160a02c85
@ -344,9 +344,25 @@ class AvailableVLANsView(ObjectValidationMixin, APIView):
|
||||
@swagger_auto_schema(responses={200: serializers.AvailableVLANSerializer(many=True)})
|
||||
def get(self, request, pk):
|
||||
vlangroup = get_object_or_404(VLANGroup.objects.restrict(request.user), pk=pk)
|
||||
available_vlans = vlangroup.get_available_vids()
|
||||
config = get_config()
|
||||
PAGINATE_COUNT = config.PAGINATE_COUNT
|
||||
MAX_PAGE_SIZE = config.MAX_PAGE_SIZE
|
||||
|
||||
serializer = serializers.AvailableVLANSerializer(available_vlans, many=True, context={
|
||||
try:
|
||||
limit = int(request.query_params.get('limit', PAGINATE_COUNT))
|
||||
except ValueError:
|
||||
limit = PAGINATE_COUNT
|
||||
if MAX_PAGE_SIZE:
|
||||
limit = min(limit, MAX_PAGE_SIZE)
|
||||
|
||||
# Calculate available VLANs within the group
|
||||
vlan_list = []
|
||||
for index, vlan in enumerate(vlangroup.get_available_vids(), start=1):
|
||||
vlan_list.append(vlan)
|
||||
if index == limit:
|
||||
break
|
||||
|
||||
serializer = serializers.AvailableVLANSerializer(vlan_list, many=True, context={
|
||||
'request': request,
|
||||
'group': vlangroup,
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user