Coverage for apis_core/core/mixins.py: 33%
12 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-22 07:51 +0000
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-22 07:51 +0000
1from django.conf import settings
4class ListViewObjectFilterMixin:
5 """
6 Filter a queryset of a listview using the APIS_LIST_VIEW_OBJECT_FILTER
7 setting if it exists. A child class has to call the `filter_queryset`
8 method somewhere, most likely in the `get_queryset` method.
9 """
11 def filter_queryset(self, queryset):
12 if hasattr(super(), "filter_queryset"):
13 queryset = super().filter_queryset(queryset)
14 if hasattr(settings, "APIS_LIST_VIEW_OBJECT_FILTER"):
15 return settings.APIS_LIST_VIEW_OBJECT_FILTER(self, queryset)
16 return queryset
18 def get_permission_required(self):
19 if getattr(settings, "APIS_LIST_VIEWS_ALLOWED", False):
20 return []
21 return super().get_permission_required()