diff --git a/materia/urls.py b/materia/urls.py index 07490c9f3..e728f31aa 100644 --- a/materia/urls.py +++ b/materia/urls.py @@ -7,7 +7,8 @@ from materia.views import (AutoriaEditView, AutoriaView, LegislacaoCitadaEditView, LegislacaoCitadaView, MateriaAnexadaEditView, MateriaAnexadaView, MateriaLegislativaPesquisaView, NumeracaoEditView, - NumeracaoView, ProposicaoListView, ProposicaoView, + NumeracaoView, PesquisaMateriaListView, + ProposicaoListView, ProposicaoView, RelatoriaEditView, RelatoriaView, TramitacaoEditView, TramitacaoView, autor_crud, materia_legislativa_crud, orgao_crud, origem_crud, @@ -79,4 +80,6 @@ urlpatterns = [ ProposicaoListView.as_view(), name='list_proposicao'), url(r'^materia/pesquisar-materia$', MateriaLegislativaPesquisaView.as_view(), name='pesquisar_materia'), + url(r'^materia/pesquisar-materia-list$', + PesquisaMateriaListView.as_view(), name='pesquisar_materia_list'), ] diff --git a/materia/views.py b/materia/views.py index ec1f558f2..a1e73eab7 100644 --- a/materia/views.py +++ b/materia/views.py @@ -1,4 +1,4 @@ -from datetime import date +from datetime import date, datetime from re import sub from crispy_forms.helper import FormHelper @@ -8,6 +8,7 @@ from django import forms from django.core.exceptions import ObjectDoesNotExist from django.core.urlresolvers import reverse from django.forms import ModelForm +from django.shortcuts import redirect from django.utils.html import strip_tags from django.utils.safestring import mark_safe from django.utils.translation import ugettext_lazy as _ @@ -18,8 +19,9 @@ from vanilla import GenericView import sapl from comissoes.models import Comissao, Composicao from norma.models import LegislacaoCitada, NormaJuridica, TipoNormaJuridica -from sapl.crud import build_crud from parlamentares.models import Parlamentar +from sapl.crud import build_crud + from .models import (Anexada, Autor, Autoria, DespachoInicial, DocumentoAcessorio, MateriaLegislativa, Numeracao, Orgao, Origem, Proposicao, RegimeTramitacao, Relatoria, @@ -1926,14 +1928,14 @@ class MateriaLegislativaPesquisaForm(forms.Form): widget=forms.Select( attrs={'class': 'selector'})) - data_apresentacao = forms.DateField(label=u'Data Fim Prazo', + data_apresentacao = forms.DateField(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 = forms.DateField(label=u'Data Fim Prazo', + data_publicacao = forms.DateField(label=u'Data da Publicação', input_formats=['%d/%m/%Y'], required=False, widget=forms.DateInput( @@ -2013,3 +2015,62 @@ class MateriaLegislativaPesquisaView(FormMixin, GenericView): def get(self, request, *args, **kwargs): form = MateriaLegislativaPesquisaForm() return self.render_to_response({'form': form}) + + def post(self, request, *args, **kwargs): + kwargs = {} + + # TODO: Autor, Relator, Localização, Origem + + if request.POST['tipo']: + kwargs['tipo'] = request.POST['tipo'] + + if request.POST['numero']: + kwargs['numero'] = request.POST['numero'] + + if request.POST['ano']: + kwargs['ano'] = request.POST['ano'] + + if request.POST['numero_protocolo']: + kwargs['numero_protocolo'] = request.POST['numero_protocolo'] + + if request.POST['data_apresentacao']: + kwargs['data_apresentacao'] = datetime.strptime( + request.POST['data_apresentacao'], + '%d/%m/%Y').strftime('%Y-%m-%d') + + if request.POST['data_publicacao']: + kwargs['data_publicacao'] = datetime.strptime( + request.POST['data_publicacao'], + '%d/%m/%Y').strftime('%Y-%m-%d') + + if request.POST['tramitacao']: + kwargs['em_tramitacao'] = request.POST['tramitacao'] + + if request.POST['assunto']: + kwargs['ementa'] = request.POST['assunto'] + + request.session['kwargs'] = kwargs + return redirect('pesquisar_materia_list') + + +class PesquisaMateriaListView(FormMixin, ListView): + template_name = 'materia/pesquisa_materia_list.html' + context_object_name = 'materias' + model = MateriaLegislativa + paginate_by = 10 + + def get_queryset(self): + kwargs = self.request.session['kwargs'] + return MateriaLegislativa.objects.filter( + **kwargs) + + def get_context_data(self, **kwargs): + context = super(PesquisaMateriaListView, self).get_context_data( + **kwargs) + + paginator = context['paginator'] + page_obj = context['page_obj'] + + context['page_range'] = sapl.crud.make_pagination( + page_obj.number, paginator.num_pages) + return context diff --git a/templates/materia/pesquisa_materia_list.html b/templates/materia/pesquisa_materia_list.html new file mode 100644 index 000000000..87f2b73c4 --- /dev/null +++ b/templates/materia/pesquisa_materia_list.html @@ -0,0 +1,22 @@ +{% extends "materia/materialegislativa_detail.html" %} +{% load i18n %} +{% load crispy_forms_tags %} +{% block sections_nav %} {% endblock %} +{% block detail_content %} +{% if materias %} + + + {% for m in materias %} + + + {% endfor %} +

Resultados

+ {{m.tipo.sigla}} {{m.numero}}/{{m.ano}} - {{m.tipo}}
+ {{ m.ementa }}
+ Localização Atual: {{m.local_origem_externa}}
+
+{% include "paginacao.html" %} +{% else %} +

Nenhum Registro recuperado

+{% endif %} +{% endblock detail_content %} \ No newline at end of file