From 9b16d3bb5677a42c131bd7a233f3854ee7afd715 Mon Sep 17 00:00:00 2001 From: Leandro Roberto Date: Wed, 8 Sep 2021 09:31:15 -0300 Subject: [PATCH] Corrige get_fields do mixin para filterset da api --- sapl/api/core/filters.py | 14 ++++---------- sapl/api/pagination.py | 2 +- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/sapl/api/core/filters.py b/sapl/api/core/filters.py index 312f32131..bf5f68007 100644 --- a/sapl/api/core/filters.py +++ b/sapl/api/core/filters.py @@ -1,17 +1,13 @@ from collections import OrderedDict -from django.conf import settings -from django.db.models.fields import DateTimeField, DateField from django.db.models.fields.files import FileField from django.template.defaultfilters import capfirst import django_filters from django_filters.constants import ALL_FIELDS from django_filters.filters import CharFilter -from django_filters.filterset import BaseFilterSet, FilterSetMetaclass, \ - FilterSet +from django_filters.filterset import FilterSet from django_filters.utils import resolve_field, get_all_model_fields -from sapl.materia.models import MateriaLegislativa class SaplFilterSetMixin(FilterSet): @@ -47,17 +43,15 @@ class SaplFilterSetMixin(FilterSet): fields_filter = ALL_FIELDS fields = fields_filter if isinstance(fields_filter, dict) else {} - if not isinstance(fields_filter, (dict, str)): - for f in fields_filter: - fields[f] = ['exact'] for f_str in fields_model: if f_str not in fields: + f = model._meta.get_field(f_str) if f.many_to_many: continue - fields[f_str] = [] + fields[f_str] = ['exact'] def get_keys_lookups(cl, sub_f): r = [] @@ -80,7 +74,7 @@ class SaplFilterSetMixin(FilterSet): return r fields[f_str] = list( - set(get_keys_lookups(f.class_lookups, ''))) + set(fields[f_str] + get_keys_lookups(f.class_lookups, ''))) # Remove excluded fields exclude = exclude or [] diff --git a/sapl/api/pagination.py b/sapl/api/pagination.py index 9d1c2f1eb..67aecd7f5 100644 --- a/sapl/api/pagination.py +++ b/sapl/api/pagination.py @@ -6,7 +6,7 @@ from rest_framework.response import Response class StandardPagination(pagination.PageNumberPagination): page_size = 10 page_size_query_param = 'page_size' - max_page_size = 50 + max_page_size = 100 def paginate_queryset(self, queryset, request, view=None): if request.query_params.get('get_all', '').lower() == 'true':