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 crispy_forms.layout import HTML, Button, Column, Fieldset, Layout, Submit
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.models import Max from django.db.models import Max
from django.forms import ModelForm from django.forms import ModelForm
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django_filters import FilterSet
import crispy_layout_mixin import crispy_layout_mixin
import sapl import sapl
from crispy_layout_mixin import form_actions from crispy_layout_mixin import form_actions
from norma.models import LegislacaoCitada, TipoNormaJuridica from norma.models import LegislacaoCitada, TipoNormaJuridica
from parlamentares.models import Parlamentar, Partido
from sapl.settings import MAX_DOC_UPLOAD_SIZE from sapl.settings import MAX_DOC_UPLOAD_SIZE
from .models import (AcompanhamentoMateria, Anexada, Autor, Autoria, from .models import (AcompanhamentoMateria, Anexada, Autor, Autoria,
DespachoInicial, DocumentoAcessorio, MateriaLegislativa, DespachoInicial, DocumentoAcessorio, MateriaLegislativa,
Numeracao, Origem, Proposicao, Relatoria, Numeracao, Proposicao, Relatoria, TipoMateriaLegislativa,
StatusTramitacao, TipoAutor, TipoMateriaLegislativa, Tramitacao)
Tramitacao, UnidadeTramitacao)
def em_tramitacao(): def em_tramitacao():
@ -594,12 +592,11 @@ class AutoriaForm(ModelForm):
class RangeWidgetOverride(forms.MultiWidget): class RangeWidgetOverride(forms.MultiWidget):
def __init__(self, attrs=None): def __init__(self, attrs=None):
widgets = (forms.DateInput( widgets = (forms.DateInput(format='%d/%m/%Y',
format='%d/%m/%Y',
attrs={'class': 'dateinput'}), attrs={'class': 'dateinput'}),
forms.DateInput( forms.DateInput(format='%d/%m/%Y',
format='%d/%m/%Y',
attrs={'class': 'dateinput'})) attrs={'class': 'dateinput'}))
super(RangeWidgetOverride, self).__init__(widgets, attrs) super(RangeWidgetOverride, self).__init__(widgets, attrs)
@ -612,101 +609,35 @@ class RangeWidgetOverride(forms.MultiWidget):
return ''.join(rendered_widgets) return ''.join(rendered_widgets)
class MateriaLegislativaFilterSet(FilterSet): class MateriaLegislativaFilterSet(django_filters.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=""
)
tramitacao__status = django_filters.ModelChoiceFilter( filter_overrides = {models.DateField: {
label='Situação', 'filter_class': django_filters.DateFromToRangeFilter,
required=False, 'extra': lambda f: {
queryset=StatusTramitacao.objects.all(), 'label': '%s (%s)' % (f.verbose_name, _('Inicial - Final')),
empty_label='Selecione', 'widget': RangeWidgetOverride},
help_text="" }}
)
em_tramitacao = django_filters.ChoiceFilter(required=False, autoria__autor = django_filters.CharFilter(widget=forms.HiddenInput())
label='Tramitando',
choices=em_tramitacao(),
widget=forms.Select(
attrs={'class': 'selector'}),
help_text="")
ementa = django_filters.CharFilter(required=False, ementa = django_filters.CharFilter(lookup_expr='icontains')
label=u'Assunto',
lookup_expr='icontains',
help_text="")
class Meta: 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 = ( order_by = (
('', 'Selecione'), ('', '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 # hack to suppress many annoying warnings from crispy_forms
# see sapl.temp_suppress_crispy_form_warnings # see sapl.temp_suppress_crispy_form_warnings
LOGGING = SUPRESS_CRISPY_FORM_WARNINGS_LOGGING LOGGING = SUPRESS_CRISPY_FORM_WARNINGS_LOGGING
# suprime texto de ajuda default do django-filter
FILTERS_HELP_TEXT_FILTER = False

Loading…
Cancel
Save