Browse Source

Inicia a refatoracao da Pesquisa de Materia

pull/282/head
Eduardo Calil 9 years ago
parent
commit
78b6c13a54
  1. 133
      materia/forms.py
  2. 106
      materia/views.py
  3. 1
      requirements/requirements.txt
  4. 29
      templates/materia/materialegislativa_filter.html

133
materia/forms.py

@ -1,19 +1,25 @@
from crispy_forms.helper import FormHelper 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 ValidationError
from django_filters import FilterSet
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 _
import django_filters
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 sapl.settings import MAX_DOC_UPLOAD_SIZE from sapl.settings import MAX_DOC_UPLOAD_SIZE
from parlamentares.models import Parlamentar, Partido
from .models import (AcompanhamentoMateria, Anexada, Autor, Autoria, from .models import (AcompanhamentoMateria, Anexada, Autor, Autoria,
DespachoInicial, DocumentoAcessorio, MateriaLegislativa, DespachoInicial, DocumentoAcessorio, MateriaLegislativa,
Numeracao, Proposicao, Relatoria, StatusTramitacao, Numeracao, Origem, Proposicao, Relatoria,
StatusTramitacao, TipoAutor, TipoDocumento,
TipoMateriaLegislativa, Tramitacao, UnidadeTramitacao) TipoMateriaLegislativa, Tramitacao, UnidadeTramitacao)
ORDENACAO_MATERIAIS = [(1, 'Crescente'), ORDENACAO_MATERIAIS = [(1, 'Crescente'),
@ -538,26 +544,11 @@ class AutoriaForm(ModelForm):
choices=[(True, _('Sim')), (False, _('Não'))], choices=[(True, _('Sim')), (False, _('Não'))],
) )
materia_id = forms.CharField(widget=forms.HiddenInput(), required=False)
class Meta: class Meta:
model = Autoria model = Autoria
fields = ['autor', fields = ['autor',
'primeiro_autor', 'primeiro_autor',
'partido', 'partido']
'materia_id']
def clean(self):
if self.data['materia_id'] and self.data['autor']:
try:
materia = MateriaLegislativa.objects.get(
id=self.data['materia_id'])
Autoria.objects.get(autor=self.data['autor'],
materia=materia)
raise forms.ValidationError(
_('Essa autoria já foi adicionada!'))
except ObjectDoesNotExist:
pass
def __init__(self, excluir=False, *args, **kwargs): def __init__(self, excluir=False, *args, **kwargs):
@ -688,3 +679,109 @@ class MateriaLegislativaPesquisaForm(ModelForm):
) )
super(MateriaLegislativaPesquisaForm, self).__init__( super(MateriaLegislativaPesquisaForm, self).__init__(
*args, **kwargs) *args, **kwargs)
class MateriaLegislativaPesquisaFields(FilterSet):
# autor = django_filters.ChoiceFilter(
# label='Autor',
# required=False,
# queryset=Autor.objects.all().order_by('tipo'),
# empty_label='Selecione',
# )
# # relatores são os parlamentares ativos?
# relatoria__parlamentar__id = django_filters.ChoiceFilter(
# label='Relator',
# required=False,
# queryset=Parlamentar.objects.all().order_by('nome_parlamentar'),
# empty_label='Selecione',
# )
# tipo = django_filters.ChoiceFilter(
# label=_('Tipo de Matéria'),
# required=False,
# queryset=TipoMateriaLegislativa.objects.all(),
# empty_label='Selecione',
# )
# data_apresentacao = django_filters.DateFilter(
# label=u'Data de Apresentação',
# input_formats=['%d/%m/%Y'],
# required=False,
# widget=forms.DateInput(
# format='%d/%m/%Y',
# attrs={'class': 'dateinput'}))
# data_publicacao = django_filters.DateFilter(
# label=u'Data da Publicação',
# input_formats=['%d/%m/%Y'],
# required=False,
# widget=forms.DateInput(
# format='%d/%m/%Y',
# attrs={'class': 'dateinput'}))
numero = django_filters.CharFilter(required=False,
label=u'Número da Matéria')
numero_protocolo = django_filters.CharFilter(required=False,
label=u'Núm. Protocolo')
ano = django_filters.CharFilter(required=False,
label=u'Ano da Matéria')
ementa__icontains = django_filters.CharFilter(required=False,
label=u'Assunto')
# tramitacao__unidade_tramitacao_destino = django_filters.ChoiceFilter(
# label=_('Localização Atual'),
# required=False,
# queryset=UnidadeTramitacao.objects.all(),
# empty_label='Selecione',
# )
# tramitacao__status = django_filters.ChoiceFilter(
# label='Situação',
# required=False,
# queryset=StatusTramitacao.objects.all(),
# empty_label='Selecione',
# )
# em_tramitacao = django_filters.ChoiceFilter(required=False,
# label='Tramitando',
# choices=em_tramitacao(),
# widget=forms.Select(
# attrs={'class': 'selector'}))
# autoria__autor__tipo = django_filters.ChoiceFilter(
# label=_('Tipo Autor'),
# required=False,
# queryset=TipoAutor.objects.all(),
# empty_label='Selecione',
# )
# autoria__partido = django_filters.ChoiceFilter(
# label=_('Partido (Autor)'),
# required=False,
# queryset=Partido.objects.all(),
# empty_label='Selecione')
# local_origem_externa = django_filters.ChoiceFilter(
# label=_('Localização de Origem'),
# required=False,
# queryset=Origem.objects.all(),
# empty_label='Selecione')
class Meta:
models = MateriaLegislativa
fields = ['tipo',
'ano',
'numero_protocolo',
'data_apresentacao',
'data_publicacao',
'em_tramitacao',
'ementa__icontains',
'autoria__autor__id',
'relatoria__parlamentar__id',
'tramitacao__unidade_tramitacao_destino',
'tramitacao__status',
'autoria__autor__tipo',
'autoria__partido',
'local_origem_externa']

106
materia/views.py

@ -1,3 +1,5 @@
from django_filters.views import FilterView
from datetime import datetime from datetime import datetime
from random import choice from random import choice
from string import ascii_letters, digits from string import ascii_letters, digits
@ -24,7 +26,7 @@ from .forms import (AcompanhamentoMateriaForm, AutoriaForm,
DespachoInicialForm, DocumentoAcessorioForm, DespachoInicialForm, DocumentoAcessorioForm,
FormularioCadastroForm, FormularioSimplificadoForm, FormularioCadastroForm, FormularioSimplificadoForm,
LegislacaoCitadaForm, MateriaAnexadaForm, LegislacaoCitadaForm, MateriaAnexadaForm,
MateriaLegislativaPesquisaForm, NumeracaoForm, MateriaLegislativaPesquisaFields, NumeracaoForm,
ProposicaoForm, RelatoriaForm, TramitacaoForm) ProposicaoForm, RelatoriaForm, TramitacaoForm)
from .models import (AcompanhamentoMateria, Anexada, Autor, Autoria, from .models import (AcompanhamentoMateria, Anexada, Autor, Autoria,
DespachoInicial, DocumentoAcessorio, MateriaLegislativa, DespachoInicial, DocumentoAcessorio, MateriaLegislativa,
@ -1187,59 +1189,59 @@ class ProposicaoListView(ListView):
return context return context
class MateriaLegislativaPesquisaView(FormView): # class MateriaLegislativaPesquisaView(FormView):
template_name = 'materia/pesquisa_materia.html' # template_name = 'materia/pesquisa_materia.html'
def get_success_url(self): # def get_success_url(self):
return reverse('pesquisar_materia') # return reverse('pesquisar_materia')
def get(self, request, *args, **kwargs): # def get(self, request, *args, **kwargs):
form = MateriaLegislativaPesquisaForm() # form = MateriaLegislativaPesquisaForm()
return self.render_to_response({'form': form}) # return self.render_to_response({'form': form})
def post(self, request, *args, **kwargs): # def post(self, request, *args, **kwargs):
kwargs = {} # kwargs = {}
form = MateriaLegislativaPesquisaForm(request.POST) # form = MateriaLegislativaPesquisaForm(request.POST)
if form.data['tipo']: # if form.data['tipo']:
kwargs['tipo'] = form.data['tipo'] # kwargs['tipo'] = form.data['tipo']
if form.data['numero']: # if form.data['numero']:
kwargs['numero'] = form.data['numero'] # kwargs['numero'] = form.data['numero']
if form.data['ano']: # if form.data['ano']:
kwargs['ano'] = form.data['ano'] # kwargs['ano'] = form.data['ano']
if form.data['numero_protocolo']: # if form.data['numero_protocolo']:
kwargs['numero_protocolo'] = form.data['numero_protocolo'] # kwargs['numero_protocolo'] = form.data['numero_protocolo']
if (form.data['apresentacao_inicial'] and # if (form.data['apresentacao_inicial'] and
form.data['apresentacao_final']): # form.data['apresentacao_final']):
kwargs['apresentacao_inicial'] = form.data['apresentacao_inicial'] # kwargs['apresentacao_inicial'] = form.data['apresentacao_inicial']
kwargs['apresentacao_final'] = form.data['apresentacao_final'] # kwargs['apresentacao_final'] = form.data['apresentacao_final']
if (form.data['publicacao_inicial'] and # if (form.data['publicacao_inicial'] and
form.data['publicacao_final']): # form.data['publicacao_final']):
kwargs['publicacao_inicial'] = form.data['publicacao_inicial'] # kwargs['publicacao_inicial'] = form.data['publicacao_inicial']
kwargs['publicacao_final'] = form.data['publicacao_final'] # kwargs['publicacao_final'] = form.data['publicacao_final']
if form.data['local_origem_externa']: # if form.data['local_origem_externa']:
kwargs['local_origem_externa'] = form.data['local_origem_externa'] # kwargs['local_origem_externa'] = form.data['local_origem_externa']
if form.data['autor']: # if form.data['autor']:
kwargs['autor'] = form.data['autor'] # kwargs['autor'] = form.data['autor']
if form.data['localizacao']: # if form.data['localizacao']:
kwargs['localizacao'] = form.data['localizacao'] # kwargs['localizacao'] = form.data['localizacao']
if form.data['em_tramitacao']: # if form.data['em_tramitacao']:
kwargs['em_tramitacao'] = form.data['em_tramitacao'] # kwargs['em_tramitacao'] = form.data['em_tramitacao']
if form.data['situacao']: # if form.data['situacao']:
kwargs['situacao'] = form.data['situacao'] # kwargs['situacao'] = form.data['situacao']
request.session['kwargs'] = kwargs # request.session['kwargs'] = kwargs
return redirect('pesquisar_materia_list') # return redirect('pesquisar_materia_list')
class PesquisaMateriaListView(ListView): class PesquisaMateriaListView(ListView):
@ -1300,6 +1302,32 @@ class PesquisaMateriaListView(ListView):
return materias return materias
class MateriaLegislativaPesquisaView(FilterView):
model = MateriaLegislativa
filterset_class = MateriaLegislativaPesquisaFields
paginate_by = 10
def get_context_data(self, **kwargs):
context = super(MateriaLegislativaPesquisaView,
self).get_context_data(**kwargs)
paginator = context['paginator']
page_obj = context['page_obj']
context['page_range'] = make_pagination(
page_obj.number, paginator.num_pages)
return context
def get(self, request, *args, **kwargs):
# import ipdb; ipdb.set_trace()
filterset_class = self.get_filterset_class()
self.filterset = self.get_filterset(filterset_class)
self.object_list = self.filterset.qs
context = self.get_context_data(filter=self.filterset,
object_list=self.object_list)
return self.render_to_response(context)
class ProposicaoView(CreateView): class ProposicaoView(CreateView):
template_name = "materia/proposicao/proposicao.html" template_name = "materia/proposicao/proposicao.html"
form_class = ProposicaoForm form_class = ProposicaoForm

1
requirements/requirements.txt

@ -6,6 +6,7 @@ django-braces==1.8.1
django-compressor==2.0 django-compressor==2.0
django-crispy-forms==1.6.0 django-crispy-forms==1.6.0
django-extra-views==0.7.1 django-extra-views==0.7.1
django-filter==0.13.0
django-model-utils==2.4 django-model-utils==2.4
django-sass-processor==0.3.4 django-sass-processor==0.3.4
django==1.9 django==1.9

29
templates/materia/materialegislativa_filter.html

@ -0,0 +1,29 @@
{% extends "materia/materialegislativa_detail.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block actions %}{% endblock %}
{% block sections_nav %} {% endblock %}
{% block detail_content %}
<form action="" method="get">
{{ filter.form.as_p }}
<input type="submit" />
</form>
<table class="table table-striped table-bordered">
<thead class="thead-default">
<tr><td><h3>Resultados</h3></td></tr>
</thead>
{% for m in page_obj %}
<tr>
<td>
<strong><a href="{% url 'materialegislativa:detail' m.id %}">{{m.tipo.sigla}} {{m.numero}}/{{m.ano}} - {{m.tipo}}</strong></a></br>
{{ m.ementa|safe }}</br>
<strong>Localização Atual:</strong> {{m.tramitacao_set.last.unidade_tramitacao_destino|default_if_none:"Não Informada"}}</br>
<p></p>
</tr>
{% endfor %}
</table>
{% include "paginacao.html" %}
{% endblock detail_content %}
Loading…
Cancel
Save