From f19c8f23e92cf6442c30f121953662fe06112d59 Mon Sep 17 00:00:00 2001 From: opsdisk Date: Mon, 13 Dec 2021 19:21:23 -0600 Subject: [PATCH 1/3] Testing filtering with ScheduleScan model --- console/django_scantron/api/views.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/console/django_scantron/api/views.py b/console/django_scantron/api/views.py index 4e795b3..8c1c4fe 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 @@ -135,6 +136,25 @@ class ScheduledScanViewSet(ListRetrieveUpdateViewSet, DefaultsMixin): 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 From 63e51b4be54ca39d046a163ab173afc8b1ec2dba Mon Sep 17 00:00:00 2001 From: opsdisk Date: Mon, 13 Dec 2021 21:22:47 -0600 Subject: [PATCH 2/3] Remove DefaultsMixin from ScheduledScan --- console/django_scantron/api/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/console/django_scantron/api/views.py b/console/django_scantron/api/views.py index 8c1c4fe..94832a4 100644 --- a/console/django_scantron/api/views.py +++ b/console/django_scantron/api/views.py @@ -130,7 +130,7 @@ class ScanViewSet(DefaultsMixin, viewsets.ModelViewSet): permission_classes = (IsAuthenticated, IsAdminUser) -class ScheduledScanViewSet(ListRetrieveUpdateViewSet, DefaultsMixin): +class ScheduledScanViewSet(ListRetrieveUpdateViewSet): """API CRUD operations for ScheduledScan Model.""" model = ScheduledScan From 13a4674af768a3e5b378463e6f6a4539ace698c8 Mon Sep 17 00:00:00 2001 From: opsdisk Date: Mon, 13 Dec 2021 21:24:35 -0600 Subject: [PATCH 3/3] Added DRF pagination settings --- console/config/settings/base.py | 3 +++ 1 file changed, 3 insertions(+) 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