diff --git a/requirements/requirements.txt b/requirements/requirements.txt index 45529b12b..40d3c4fdd 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -5,6 +5,7 @@ djangorestframework==3.12.4 dj-database-url==0.5.0 django-braces==1.14.0 django-crispy-forms==1.7.2 +django-contrib-postgres==0.0.1 django-floppyforms==1.8.0 django-extra-views==0.12.0 django-model-utils==3.1.2 diff --git a/sapl/api/core/filters.py b/sapl/api/core/filters.py index a718c0d67..90ef46bfa 100644 --- a/sapl/api/core/filters.py +++ b/sapl/api/core/filters.py @@ -71,7 +71,7 @@ class SaplFilterSetMixin(FilterSet): if hasattr(lv, 'class_lookups'): r += get_keys_lookups(lv.class_lookups, sflk) - if hasattr(lv, 'output_field'): + if hasattr(lv, 'output_field') and hasattr(lv, 'output_field.class_lookups'): r.append(f'{sflk}{"__" if sflk else ""}range') r += get_keys_lookups(lv.output_field.class_lookups, sflk) diff --git a/sapl/norma/forms.py b/sapl/norma/forms.py index 784d4ee7d..a8d80c7b9 100644 --- a/sapl/norma/forms.py +++ b/sapl/norma/forms.py @@ -1,26 +1,23 @@ import logging +import django_filters from crispy_forms.layout import (Button, Fieldset, HTML, Layout) from django import forms +from django.contrib.postgres.search import SearchVector from django.core.exceptions import ObjectDoesNotExist, ValidationError -from django.db import models from django.db.models import Q from django.forms import ModelChoiceField, ModelForm, widgets from django.utils import timezone from django.utils.translation import ugettext_lazy as _ -import django_filters -from sapl.base.models import Autor, TipoAutor +from sapl.base.models import TipoAutor from sapl.crispy_layout_mixin import form_actions, SaplFormHelper, to_row -from sapl.materia.forms import choice_anos_com_materias from sapl.materia.models import (MateriaLegislativa, TipoMateriaLegislativa, Orgao) from sapl.parlamentares.models import Partido -from sapl.utils import (autor_label, autor_modal, ANO_CHOICES, choice_anos_com_normas, +from sapl.utils import (autor_label, autor_modal, ANO_CHOICES, choice_anos_com_normas, FileFieldCheckMixin, FilterOverridesMetaMixin, - NormaPesquisaOrderingFilter, RangeWidgetOverride, - validar_arquivo) - + NormaPesquisaOrderingFilter, validar_arquivo) from .models import (AnexoNormaJuridica, AssuntoNorma, AutoriaNorma, NormaJuridica, NormaRelacionada, TipoNormaJuridica) @@ -75,7 +72,7 @@ class NormaFilterSet(django_filters.FilterSet): method='filter_ementa', label=_('Pesquisar expressões na ementa da norma')) - indexacao = django_filters.CharFilter(lookup_expr='icontains', + indexacao = django_filters.CharFilter(method='filter_indexacao', label=_('Indexação')) assuntos = django_filters.ModelChoiceFilter( @@ -132,12 +129,12 @@ class NormaFilterSet(django_filters.FilterSet): ) def filter_ementa(self, queryset, name, value): - texto = value.split() - q = Q() - for t in texto: - q &= Q(ementa__icontains=t) + return queryset.annotate(search=SearchVector('ementa', + config='portuguese')).filter(search=value) - return queryset.filter(q) + def filter_indexacao(self, queryset, name, value): + return queryset.annotate(search=SearchVector('indexacao', + config='portuguese')).filter(search=value) def filter_autoria(self, queryset, name, value): return queryset.filter(**{ diff --git a/sapl/settings.py b/sapl/settings.py index 315ef29dd..a17db0969 100644 --- a/sapl/settings.py +++ b/sapl/settings.py @@ -92,6 +92,7 @@ INSTALLED_APPS = ( 'reversion_compare', 'haystack', + 'django.contrib.postgres', 'speedinfo', 'webpack_loader',