Remove custom API filters and suggest solution via templates

This commit is contained in:
Alan Rominger
2023-02-23 14:41:53 -05:00
committed by John Westcott IV
parent e6050804f9
commit e38f87eb1d
4 changed files with 31 additions and 26 deletions

View File

@@ -122,7 +122,6 @@ from awx.api.views.mixin import (
UnifiedJobDeletionMixin,
NoTruncateMixin,
)
from awx.api.filters import HostMetricSummaryMonthlyFieldLookupBackend
from awx.api.pagination import UnifiedJobEventPagination
from awx.main.utils import set_environ
@@ -1578,29 +1577,9 @@ class HostMetricSummaryMonthlyList(ListAPIView):
serializer_class = serializers.HostMetricSummaryMonthlySerializer
permission_classes = (IsSystemAdminOrAuditor,)
search_fields = ('date',)
filter_backends = [HostMetricSummaryMonthlyFieldLookupBackend]
def get_queryset(self):
queryset = self.model.objects.all()
past_months = self.request.query_params.get('past_months', None)
date_from = self._get_date_from(past_months)
queryset = queryset.filter(date__gte=date_from)
return queryset
@staticmethod
def _get_date_from(past_months, default=12, maximum=36):
try:
months_ago = int(past_months or default)
except ValueError:
months_ago = default
months_ago = min(months_ago, maximum)
months_ago = max(months_ago, 1)
date_from = datetime.date.today() - dateutil.relativedelta.relativedelta(months=months_ago)
# Set to beginning of the month
date_from = date_from.replace(day=1).isoformat()
return date_from
return self.model.objects.all()
class HostList(HostRelatedSearchMixin, ListCreateAPIView):