mirror of
https://github.com/netbox-community/netbox.git
synced 2025-07-29 11:56:25 -06:00
7848 review comments
This commit is contained in:
parent
abff1827cb
commit
3ec3bef5fa
@ -18,9 +18,9 @@ from django_rq.queues import get_queue, get_redis_connection
|
|||||||
from django_rq.utils import get_statistics
|
from django_rq.utils import get_statistics
|
||||||
from django_rq.settings import QUEUES_LIST
|
from django_rq.settings import QUEUES_LIST
|
||||||
from netbox.api.metadata import ContentTypeMetadata
|
from netbox.api.metadata import ContentTypeMetadata
|
||||||
|
from netbox.api.pagination import LimitOffsetListPagination
|
||||||
from netbox.api.viewsets import NetBoxModelViewSet, NetBoxReadOnlyModelViewSet
|
from netbox.api.viewsets import NetBoxModelViewSet, NetBoxReadOnlyModelViewSet
|
||||||
from rest_framework import viewsets
|
from rest_framework import viewsets
|
||||||
from rest_framework.pagination import LimitOffsetPagination
|
|
||||||
from rest_framework.permissions import IsAdminUser
|
from rest_framework.permissions import IsAdminUser
|
||||||
from rq.job import Job as RQ_Job
|
from rq.job import Job as RQ_Job
|
||||||
from rq.worker import Worker
|
from rq.worker import Worker
|
||||||
@ -85,31 +85,6 @@ class ObjectChangeViewSet(ReadOnlyModelViewSet):
|
|||||||
filterset_class = filtersets.ObjectChangeFilterSet
|
filterset_class = filtersets.ObjectChangeFilterSet
|
||||||
|
|
||||||
|
|
||||||
class LimitOffsetListPagination(LimitOffsetPagination):
|
|
||||||
"""
|
|
||||||
DRF LimitOffset Paginator but for list instead of queryset
|
|
||||||
"""
|
|
||||||
count = 0
|
|
||||||
offset = 0
|
|
||||||
|
|
||||||
def paginate_list(self, data, request, view=None):
|
|
||||||
self.request = request
|
|
||||||
self.limit = self.get_limit(request)
|
|
||||||
self.count = len(data)
|
|
||||||
self.offset = self.get_offset(request)
|
|
||||||
|
|
||||||
if self.limit is None:
|
|
||||||
self.limit = self.count
|
|
||||||
|
|
||||||
if self.count == 0 or self.offset > self.count:
|
|
||||||
return []
|
|
||||||
|
|
||||||
if self.count > self.limit and self.template is not None:
|
|
||||||
self.display_page_controls = True
|
|
||||||
|
|
||||||
return data[self.offset:self.offset + self.limit]
|
|
||||||
|
|
||||||
|
|
||||||
class BaseRQListView(viewsets.ViewSet):
|
class BaseRQListView(viewsets.ViewSet):
|
||||||
"""
|
"""
|
||||||
Retrieve a list of RQ Queues.
|
Retrieve a list of RQ Queues.
|
||||||
@ -155,11 +130,8 @@ class WorkerViewSet(BaseRQListView):
|
|||||||
config = QUEUES_LIST[0]
|
config = QUEUES_LIST[0]
|
||||||
return Worker.all(get_redis_connection(config['connection_config']))
|
return Worker.all(get_redis_connection(config['connection_config']))
|
||||||
|
|
||||||
def retrieve(self, request, name=None):
|
def retrieve(self, request, name):
|
||||||
# all the RQ queues should use the same connection
|
# all the RQ queues should use the same connection
|
||||||
if not name:
|
|
||||||
raise Http404
|
|
||||||
|
|
||||||
config = QUEUES_LIST[0]
|
config = QUEUES_LIST[0]
|
||||||
workers = Worker.all(get_redis_connection(config['connection_config']))
|
workers = Worker.all(get_redis_connection(config['connection_config']))
|
||||||
worker = next((item for item in workers if item.name == name), None)
|
worker = next((item for item in workers if item.name == name), None)
|
||||||
@ -222,7 +194,6 @@ class TaskViewSet(viewsets.ViewSet):
|
|||||||
Background Task API.
|
Background Task API.
|
||||||
"""
|
"""
|
||||||
permission_classes = [IsAdminUser]
|
permission_classes = [IsAdminUser]
|
||||||
registry = "default"
|
|
||||||
|
|
||||||
def get_view_name(self):
|
def get_view_name(self):
|
||||||
return "Background Tasks"
|
return "Background Tasks"
|
||||||
@ -266,4 +237,4 @@ class TaskViewSet(viewsets.ViewSet):
|
|||||||
|
|
||||||
@action(methods=["GET"], detail=False)
|
@action(methods=["GET"], detail=False)
|
||||||
def queued(self, request, queue_name):
|
def queued(self, request, queue_name):
|
||||||
return self.cget_response(request, queue_name, None)
|
return self.get_response(request, queue_name, None)
|
||||||
|
@ -83,3 +83,28 @@ class StripCountAnnotationsPaginator(OptionalLimitOffsetPagination):
|
|||||||
cloned_queryset.query.annotations.clear()
|
cloned_queryset.query.annotations.clear()
|
||||||
|
|
||||||
return cloned_queryset.count()
|
return cloned_queryset.count()
|
||||||
|
|
||||||
|
|
||||||
|
class LimitOffsetListPagination(LimitOffsetPagination):
|
||||||
|
"""
|
||||||
|
DRF LimitOffset Paginator but for list instead of queryset
|
||||||
|
"""
|
||||||
|
count = 0
|
||||||
|
offset = 0
|
||||||
|
|
||||||
|
def paginate_list(self, data, request, view=None):
|
||||||
|
self.request = request
|
||||||
|
self.limit = self.get_limit(request)
|
||||||
|
self.count = len(data)
|
||||||
|
self.offset = self.get_offset(request)
|
||||||
|
|
||||||
|
if self.limit is None:
|
||||||
|
self.limit = self.count
|
||||||
|
|
||||||
|
if self.count == 0 or self.offset > self.count:
|
||||||
|
return []
|
||||||
|
|
||||||
|
if self.count > self.limit and self.template is not None:
|
||||||
|
self.display_page_controls = True
|
||||||
|
|
||||||
|
return data[self.offset:self.offset + self.limit]
|
||||||
|
Loading…
Reference in New Issue
Block a user