Browse Source

Adiciona busca textual em campos de Norma

pull/3585/head
Edward Ribeiro 2 years ago
parent
commit
38942dacbf
  1. 1
      requirements/requirements.txt
  2. 2
      sapl/api/core/filters.py
  3. 25
      sapl/norma/forms.py
  4. 1
      sapl/settings.py

1
requirements/requirements.txt

@ -5,6 +5,7 @@ djangorestframework==3.12.4
dj-database-url==0.5.0 dj-database-url==0.5.0
django-braces==1.14.0 django-braces==1.14.0
django-crispy-forms==1.7.2 django-crispy-forms==1.7.2
django-contrib-postgres==0.0.1
django-floppyforms==1.8.0 django-floppyforms==1.8.0
django-extra-views==0.12.0 django-extra-views==0.12.0
django-model-utils==3.1.2 django-model-utils==3.1.2

2
sapl/api/core/filters.py

@ -71,7 +71,7 @@ class SaplFilterSetMixin(FilterSet):
if hasattr(lv, 'class_lookups'): if hasattr(lv, 'class_lookups'):
r += get_keys_lookups(lv.class_lookups, sflk) 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.append(f'{sflk}{"__" if sflk else ""}range')
r += get_keys_lookups(lv.output_field.class_lookups, sflk) r += get_keys_lookups(lv.output_field.class_lookups, sflk)

25
sapl/norma/forms.py

@ -1,26 +1,23 @@
import logging import logging
import django_filters
from crispy_forms.layout import (Button, Fieldset, HTML, Layout) from crispy_forms.layout import (Button, Fieldset, HTML, Layout)
from django import forms from django import forms
from django.contrib.postgres.search import SearchVector
from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.db import models
from django.db.models import Q from django.db.models import Q
from django.forms import ModelChoiceField, ModelForm, widgets from django.forms import ModelChoiceField, ModelForm, widgets
from django.utils import timezone from django.utils import timezone
from django.utils.translation import ugettext_lazy as _ 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.crispy_layout_mixin import form_actions, SaplFormHelper, to_row
from sapl.materia.forms import choice_anos_com_materias
from sapl.materia.models import (MateriaLegislativa, from sapl.materia.models import (MateriaLegislativa,
TipoMateriaLegislativa, Orgao) TipoMateriaLegislativa, Orgao)
from sapl.parlamentares.models import Partido 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, FileFieldCheckMixin, FilterOverridesMetaMixin,
NormaPesquisaOrderingFilter, RangeWidgetOverride, NormaPesquisaOrderingFilter, validar_arquivo)
validar_arquivo)
from .models import (AnexoNormaJuridica, AssuntoNorma, AutoriaNorma, from .models import (AnexoNormaJuridica, AssuntoNorma, AutoriaNorma,
NormaJuridica, NormaRelacionada, TipoNormaJuridica) NormaJuridica, NormaRelacionada, TipoNormaJuridica)
@ -75,7 +72,7 @@ class NormaFilterSet(django_filters.FilterSet):
method='filter_ementa', method='filter_ementa',
label=_('Pesquisar expressões na ementa da norma')) 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')) label=_('Indexação'))
assuntos = django_filters.ModelChoiceFilter( assuntos = django_filters.ModelChoiceFilter(
@ -132,12 +129,12 @@ class NormaFilterSet(django_filters.FilterSet):
) )
def filter_ementa(self, queryset, name, value): def filter_ementa(self, queryset, name, value):
texto = value.split() return queryset.annotate(search=SearchVector('ementa',
q = Q() config='portuguese')).filter(search=value)
for t in texto:
q &= Q(ementa__icontains=t)
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): def filter_autoria(self, queryset, name, value):
return queryset.filter(**{ return queryset.filter(**{

1
sapl/settings.py

@ -92,6 +92,7 @@ INSTALLED_APPS = (
'reversion_compare', 'reversion_compare',
'haystack', 'haystack',
'django.contrib.postgres',
'speedinfo', 'speedinfo',
'webpack_loader', 'webpack_loader',

Loading…
Cancel
Save