Browse Source

Refatora formulário de pesquisa de normas

pull/2448/head
Leandro Roberto 6 years ago
parent
commit
93e394d3f5
  1. 15
      sapl/norma/forms.py
  2. 31
      sapl/norma/migrations/0020_auto_20190106_0454.py
  3. 21
      sapl/norma/models.py

15
sapl/norma/forms.py

@ -6,6 +6,7 @@ from crispy_forms.layout import Fieldset, Layout
from django import forms from django import forms
from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.db import models from django.db import models
from django.db.models import Q
from django.forms import ModelForm, widgets, ModelChoiceField from django.forms import ModelForm, widgets, ModelChoiceField
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 _
@ -44,7 +45,9 @@ class NormaFilterSet(django_filters.FilterSet):
label='Ano', label='Ano',
choices=choice_anos_com_normas) choices=choice_anos_com_normas)
ementa = django_filters.CharFilter(lookup_expr='icontains') ementa = django_filters.CharFilter(
method='filter_ementa',
label=_('Pesquisar expressões na ementa da norma'))
indexacao = django_filters.CharFilter(lookup_expr='icontains', indexacao = django_filters.CharFilter(lookup_expr='icontains',
label=_('Indexação')) label=_('Indexação'))
@ -52,7 +55,7 @@ class NormaFilterSet(django_filters.FilterSet):
assuntos = django_filters.ModelChoiceFilter( assuntos = django_filters.ModelChoiceFilter(
queryset=AssuntoNorma.objects.all()) queryset=AssuntoNorma.objects.all())
o = NormaPesquisaOrderingFilter() o = NormaPesquisaOrderingFilter(help_text='')
class Meta: class Meta:
filter_overrides = {models.DateField: { filter_overrides = {models.DateField: {
@ -82,6 +85,14 @@ class NormaFilterSet(django_filters.FilterSet):
form_actions(label='Pesquisar')) form_actions(label='Pesquisar'))
) )
def filter_ementa(self, queryset, name, value):
texto = value.split()
q = Q()
for t in texto:
q &= Q(ementa__icontains=t)
return queryset.filter(q)
class NormaJuridicaForm(ModelForm): class NormaJuridicaForm(ModelForm):

31
sapl/norma/migrations/0020_auto_20190106_0454.py

@ -0,0 +1,31 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10.8 on 2019-01-06 06:54
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('norma', '0019_auto_20190104_1021'),
]
operations = [
migrations.AlterField(
model_name='normajuridica',
name='data_publicacao',
field=models.DateField(blank=True, null=True, verbose_name='Data de Publicação'),
),
migrations.AlterField(
model_name='normajuridica',
name='tipo',
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='norma.TipoNormaJuridica', verbose_name='Tipo da Norma Jurídica'),
),
migrations.AlterField(
model_name='normajuridica',
name='veiculo_publicacao',
field=models.CharField(blank=True, max_length=30, verbose_name='Veículo de Publicação'),
),
]

21
sapl/norma/models.py

@ -83,7 +83,7 @@ class NormaJuridica(models.Model):
tipo = models.ForeignKey( tipo = models.ForeignKey(
TipoNormaJuridica, TipoNormaJuridica,
on_delete=models.PROTECT, on_delete=models.PROTECT,
verbose_name=_('Tipo da Norma Juridica')) verbose_name=_('Tipo da Norma Jurídica'))
materia = models.ForeignKey( materia = models.ForeignKey(
MateriaLegislativa, blank=True, null=True, MateriaLegislativa, blank=True, null=True,
on_delete=models.PROTECT, verbose_name=_('Matéria')) on_delete=models.PROTECT, verbose_name=_('Matéria'))
@ -98,11 +98,11 @@ class NormaJuridica(models.Model):
choices=ESFERA_FEDERACAO_CHOICES) choices=ESFERA_FEDERACAO_CHOICES)
data = models.DateField(blank=False, null=True, verbose_name=_('Data')) data = models.DateField(blank=False, null=True, verbose_name=_('Data'))
data_publicacao = models.DateField( data_publicacao = models.DateField(
blank=True, null=True, verbose_name=_('Data Publicação')) blank=True, null=True, verbose_name=_('Data de Publicação'))
veiculo_publicacao = models.CharField( veiculo_publicacao = models.CharField(
max_length=30, max_length=30,
blank=True, blank=True,
verbose_name=_('Veículo Publicação')) verbose_name=_('Veículo de Publicação'))
pagina_inicio_publicacao = models.PositiveIntegerField( pagina_inicio_publicacao = models.PositiveIntegerField(
blank=True, null=True, verbose_name=_('Pg. Início')) blank=True, null=True, verbose_name=_('Pg. Início'))
pagina_fim_publicacao = models.PositiveIntegerField( pagina_fim_publicacao = models.PositiveIntegerField(
@ -119,7 +119,8 @@ class NormaJuridica(models.Model):
assuntos = models.ManyToManyField( assuntos = models.ManyToManyField(
AssuntoNorma, blank=True, AssuntoNorma, blank=True,
verbose_name=_('Assuntos')) verbose_name=_('Assuntos'))
data_vigencia = models.DateField(blank=True, null=True, verbose_name=_('Data Fim Vigência')) data_vigencia = models.DateField(
blank=True, null=True, verbose_name=_('Data Fim Vigência'))
timestamp = models.DateTimeField(null=True) timestamp = models.DateTimeField(null=True)
texto_articulado = GenericRelation( texto_articulado = GenericRelation(
@ -197,7 +198,8 @@ class NormaEstatisticas(models.Model):
blank=True, null=True, blank=True, null=True,
auto_now=True) auto_now=True)
norma = models.ForeignKey(NormaJuridica, norma = models.ForeignKey(NormaJuridica,
on_delete=models.CASCADE) on_delete=models.CASCADE)
def __str__(self): def __str__(self):
return _('Usuário: %(usuario)s, Norma: %(norma)s') % { return _('Usuário: %(usuario)s, Norma: %(norma)s') % {
'usuario': self.usuario, 'norma': self.norma} 'usuario': self.usuario, 'norma': self.norma}
@ -225,6 +227,7 @@ class AutoriaNorma(models.Model):
return _('Autoria: %(autor)s - %(norma)s') % { return _('Autoria: %(autor)s - %(norma)s') % {
'autor': self.autor, 'norma': self.norma} 'autor': self.autor, 'norma': self.norma}
@reversion.register() @reversion.register()
class LegislacaoCitada(models.Model): class LegislacaoCitada(models.Model):
materia = models.ForeignKey(MateriaLegislativa, on_delete=models.CASCADE) materia = models.ForeignKey(MateriaLegislativa, on_delete=models.CASCADE)
@ -271,8 +274,8 @@ class TipoVinculoNormaJuridica(models.Model):
descricao_passiva = models.CharField( descricao_passiva = models.CharField(
max_length=50, blank=True, verbose_name=_('Descrição Passiva')) max_length=50, blank=True, verbose_name=_('Descrição Passiva'))
revoga_integralmente = models.BooleanField(verbose_name=_('Revoga Integralmente?'), revoga_integralmente = models.BooleanField(verbose_name=_('Revoga Integralmente?'),
choices=YES_NO_CHOICES, choices=YES_NO_CHOICES,
default=False) default=False)
class Meta: class Meta:
verbose_name = _('Tipo de Vínculo entre Normas Jurídicas') verbose_name = _('Tipo de Vínculo entre Normas Jurídicas')
@ -318,8 +321,8 @@ class AnexoNormaJuridica(models.Model):
on_delete=models.PROTECT, on_delete=models.PROTECT,
verbose_name=_('Norma Juridica')) verbose_name=_('Norma Juridica'))
assunto_anexo = models.TextField( assunto_anexo = models.TextField(
blank = True, blank=True,
default = "", default="",
verbose_name=_('Assunto do Anexo'), verbose_name=_('Assunto do Anexo'),
max_length=250 max_length=250
) )

Loading…
Cancel
Save