|
@ -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 [] |
|
|