Browse Source

Simplifica filtro

pull/282/head
Marcio Mazza 9 years ago
parent
commit
c9750b6e67
  1. 129
      materia/forms.py
  2. 3
      sapl/settings.py

129
materia/forms.py

@ -3,23 +3,21 @@ from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Button, Column, Fieldset, Layout, Submit
from django import forms
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.db import models
from django.db.models import Max
from django.forms import ModelForm
from django.utils.translation import ugettext_lazy as _
from django_filters import FilterSet
import crispy_layout_mixin
import sapl
from crispy_layout_mixin import form_actions
from norma.models import LegislacaoCitada, TipoNormaJuridica
from parlamentares.models import Parlamentar, Partido
from sapl.settings import MAX_DOC_UPLOAD_SIZE
from .models import (AcompanhamentoMateria, Anexada, Autor, Autoria,
DespachoInicial, DocumentoAcessorio, MateriaLegislativa,
Numeracao, Origem, Proposicao, Relatoria,
StatusTramitacao, TipoAutor, TipoMateriaLegislativa,
Tramitacao, UnidadeTramitacao)
Numeracao, Proposicao, Relatoria, TipoMateriaLegislativa,
Tramitacao)
def em_tramitacao():
@ -594,12 +592,11 @@ class AutoriaForm(ModelForm):
class RangeWidgetOverride(forms.MultiWidget):
def __init__(self, attrs=None):
widgets = (forms.DateInput(
format='%d/%m/%Y',
widgets = (forms.DateInput(format='%d/%m/%Y',
attrs={'class': 'dateinput'}),
forms.DateInput(
format='%d/%m/%Y',
forms.DateInput(format='%d/%m/%Y',
attrs={'class': 'dateinput'}))
super(RangeWidgetOverride, self).__init__(widgets, attrs)
@ -612,101 +609,35 @@ class RangeWidgetOverride(forms.MultiWidget):
return ''.join(rendered_widgets)
class MateriaLegislativaFilterSet(FilterSet):
numero = django_filters.CharFilter(required=False,
label=u'Número da Matéria',
help_text="")
numero_protocolo = django_filters.CharFilter(required=False,
label=u'Núm. Protocolo',
help_text="")
ano = django_filters.CharFilter(required=False,
label=u'Ano da Matéria',
help_text="")
tipo = django_filters.ModelChoiceFilter(
label=_('Tipo de Matéria'),
required=False,
queryset=TipoMateriaLegislativa.objects.all(),
empty_label='Selecione',
help_text=""
)
data_apresentacao = django_filters.DateFromToRangeFilter(
label=u'Data de Apresentação (Inicial - Final)',
required=False,
help_text="",
widget=RangeWidgetOverride)
data_publicacao = django_filters.DateFromToRangeFilter(
label=u'Data da Publicação (Inicial - Final)',
required=False,
help_text="",
widget=RangeWidgetOverride)
autoria__autor = django_filters.CharFilter(
widget=forms.HiddenInput(), required=False)
autoria__autor__tipo = django_filters.ModelChoiceFilter(
label=_('Tipo Autor'),
required=False,
queryset=TipoAutor.objects.all(),
empty_label='Selecione',
help_text=""
)
autoria__partido = django_filters.ModelChoiceFilter(
label=_('Partido (Autor)'),
required=False,
queryset=Partido.objects.all(),
empty_label='Selecione',
help_text="")
relatoria__parlamentar_id = django_filters.ModelChoiceFilter(
label='Relator',
required=False,
queryset=Parlamentar.objects.all().order_by('nome_parlamentar'),
empty_label='Selecione',
help_text=""
)
local_origem_externa = django_filters.ModelChoiceFilter(
label=_('Localização de Origem'),
required=False,
queryset=Origem.objects.all(),
empty_label='Selecione',
help_text="")
tramitacao__unidade_tramitacao_destino = django_filters.ModelChoiceFilter(
label=_('Localização Atual'),
required=False,
queryset=UnidadeTramitacao.objects.all(),
empty_label='Selecione',
help_text=""
)
class MateriaLegislativaFilterSet(django_filters.FilterSet):
tramitacao__status = django_filters.ModelChoiceFilter(
label='Situação',
required=False,
queryset=StatusTramitacao.objects.all(),
empty_label='Selecione',
help_text=""
)
filter_overrides = {models.DateField: {
'filter_class': django_filters.DateFromToRangeFilter,
'extra': lambda f: {
'label': '%s (%s)' % (f.verbose_name, _('Inicial - Final')),
'widget': RangeWidgetOverride},
}}
em_tramitacao = django_filters.ChoiceFilter(required=False,
label='Tramitando',
choices=em_tramitacao(),
widget=forms.Select(
attrs={'class': 'selector'}),
help_text="")
autoria__autor = django_filters.CharFilter(widget=forms.HiddenInput())
ementa = django_filters.CharFilter(required=False,
label=u'Assunto',
lookup_expr='icontains',
help_text="")
ementa = django_filters.CharFilter(lookup_expr='icontains')
class Meta:
models = MateriaLegislativa
model = MateriaLegislativa
fields = ['numero',
'numero_protocolo',
'ano',
'tipo',
'data_apresentacao',
'data_publicacao',
'autoria__autor__tipo',
'autoria__partido',
'relatoria__parlamentar_id',
'local_origem_externa',
'tramitacao__unidade_tramitacao_destino',
'tramitacao__status',
'em_tramitacao',
]
order_by = (
('', 'Selecione'),

3
sapl/settings.py

@ -185,3 +185,6 @@ SASS_PROCESSOR_INCLUDE_DIRS = (BOWER_COMPONENTS_ROOT.child(
# hack to suppress many annoying warnings from crispy_forms
# see sapl.temp_suppress_crispy_form_warnings
LOGGING = SUPRESS_CRISPY_FORM_WARNINGS_LOGGING
# suprime texto de ajuda default do django-filter
FILTERS_HELP_TEXT_FILTER = False

Loading…
Cancel
Save