diff --git a/console/config/settings/base.py b/console/config/settings/base.py index fc30742..485b13e 100644 --- a/console/config/settings/base.py +++ b/console/config/settings/base.py @@ -241,6 +241,9 @@ def get_secret(setting, secrets=SECRETS): "rest_framework.authentication.TokenAuthentication", "rest_framework.authentication.SessionAuthentication", ), + # Pagination + "DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.LimitOffsetPagination", + "PAGE_SIZE": 100, } # SAML diff --git a/console/django_scantron/api/views.py b/console/django_scantron/api/views.py index 4e795b3..94832a4 100644 --- a/console/django_scantron/api/views.py +++ b/console/django_scantron/api/views.py @@ -4,8 +4,9 @@ # Third party Python libraries. from django.http import Http404, JsonResponse from django.utils.timezone import localtime +from django_filters.rest_framework import DjangoFilterBackend import redis -from rest_framework import mixins, viewsets +from rest_framework import filters, mixins, viewsets from rest_framework.decorators import api_view from rest_framework.permissions import IsAdminUser, IsAuthenticated import rq @@ -129,12 +130,31 @@ class ScanViewSet(DefaultsMixin, viewsets.ModelViewSet): permission_classes = (IsAuthenticated, IsAdminUser) -class ScheduledScanViewSet(ListRetrieveUpdateViewSet, DefaultsMixin): +class ScheduledScanViewSet(ListRetrieveUpdateViewSet): """API CRUD operations for ScheduledScan Model.""" model = ScheduledScan serializer_class = ScheduledScanSerializer + # Filter and search. + filter_backends = (DjangoFilterBackend, filters.SearchFilter) + filter_fields = ( + "id", + "site_name", + "start_time", + "scan_engine", + "start_datetime", + "scan_binary", + "scan_command", + "targets", + "excluded_targets", + "scan_status", + "completed_time", + "result_file_base_name", + "pooled_scan_result_file_base_name", + "scan_binary_process_id", + ) + def partial_update(self, request, pk=None, **kwargs): # Any updates to this dictionary should also be updated in console/django_scantron/models.py