Browse Source

Corrige get_fields do mixin para filterset da api

pull/3453/head
Leandro Roberto 3 years ago
parent
commit
9b16d3bb56
  1. 14
      sapl/api/core/filters.py
  2. 2
      sapl/api/pagination.py

14
sapl/api/core/filters.py

@ -1,17 +1,13 @@
from collections import OrderedDict 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.db.models.fields.files import FileField
from django.template.defaultfilters import capfirst from django.template.defaultfilters import capfirst
import django_filters import django_filters
from django_filters.constants import ALL_FIELDS from django_filters.constants import ALL_FIELDS
from django_filters.filters import CharFilter from django_filters.filters import CharFilter
from django_filters.filterset import BaseFilterSet, FilterSetMetaclass, \ from django_filters.filterset import FilterSet
FilterSet
from django_filters.utils import resolve_field, get_all_model_fields from django_filters.utils import resolve_field, get_all_model_fields
from sapl.materia.models import MateriaLegislativa
class SaplFilterSetMixin(FilterSet): class SaplFilterSetMixin(FilterSet):
@ -47,17 +43,15 @@ class SaplFilterSetMixin(FilterSet):
fields_filter = ALL_FIELDS fields_filter = ALL_FIELDS
fields = fields_filter if isinstance(fields_filter, dict) else {} 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: for f_str in fields_model:
if f_str not in fields: if f_str not in fields:
f = model._meta.get_field(f_str) f = model._meta.get_field(f_str)
if f.many_to_many: if f.many_to_many:
continue continue
fields[f_str] = [] fields[f_str] = ['exact']
def get_keys_lookups(cl, sub_f): def get_keys_lookups(cl, sub_f):
r = [] r = []
@ -80,7 +74,7 @@ class SaplFilterSetMixin(FilterSet):
return r return r
fields[f_str] = list( fields[f_str] = list(
set(get_keys_lookups(f.class_lookups, ''))) set(fields[f_str] + get_keys_lookups(f.class_lookups, '')))
# Remove excluded fields # Remove excluded fields
exclude = exclude or [] exclude = exclude or []

2
sapl/api/pagination.py

@ -6,7 +6,7 @@ from rest_framework.response import Response
class StandardPagination(pagination.PageNumberPagination): class StandardPagination(pagination.PageNumberPagination):
page_size = 10 page_size = 10
page_size_query_param = 'page_size' page_size_query_param = 'page_size'
max_page_size = 50 max_page_size = 100
def paginate_queryset(self, queryset, request, view=None): def paginate_queryset(self, queryset, request, view=None):
if request.query_params.get('get_all', '').lower() == 'true': if request.query_params.get('get_all', '').lower() == 'true':

Loading…
Cancel
Save