Browse Source

ListView for show materia results

pull/98/head
Eduardo Edson Batista Cordeiro Alves 9 years ago
parent
commit
f47dce347a
  1. 5
      materia/urls.py
  2. 69
      materia/views.py
  3. 22
      templates/materia/pesquisa_materia_list.html

5
materia/urls.py

@ -7,7 +7,8 @@ from materia.views import (AutoriaEditView, AutoriaView,
LegislacaoCitadaEditView, LegislacaoCitadaView, LegislacaoCitadaEditView, LegislacaoCitadaView,
MateriaAnexadaEditView, MateriaAnexadaView, MateriaAnexadaEditView, MateriaAnexadaView,
MateriaLegislativaPesquisaView, NumeracaoEditView, MateriaLegislativaPesquisaView, NumeracaoEditView,
NumeracaoView, ProposicaoListView, ProposicaoView, NumeracaoView, PesquisaMateriaListView,
ProposicaoListView, ProposicaoView,
RelatoriaEditView, RelatoriaView, RelatoriaEditView, RelatoriaView,
TramitacaoEditView, TramitacaoView, autor_crud, TramitacaoEditView, TramitacaoView, autor_crud,
materia_legislativa_crud, orgao_crud, origem_crud, materia_legislativa_crud, orgao_crud, origem_crud,
@ -79,4 +80,6 @@ urlpatterns = [
ProposicaoListView.as_view(), name='list_proposicao'), ProposicaoListView.as_view(), name='list_proposicao'),
url(r'^materia/pesquisar-materia$', url(r'^materia/pesquisar-materia$',
MateriaLegislativaPesquisaView.as_view(), name='pesquisar_materia'), MateriaLegislativaPesquisaView.as_view(), name='pesquisar_materia'),
url(r'^materia/pesquisar-materia-list$',
PesquisaMateriaListView.as_view(), name='pesquisar_materia_list'),
] ]

69
materia/views.py

@ -1,4 +1,4 @@
from datetime import date from datetime import date, datetime
from re import sub from re import sub
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
@ -8,6 +8,7 @@ from django import forms
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.forms import ModelForm from django.forms import ModelForm
from django.shortcuts import redirect
from django.utils.html import strip_tags from django.utils.html import strip_tags
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
@ -18,8 +19,9 @@ from vanilla import GenericView
import sapl import sapl
from comissoes.models import Comissao, Composicao from comissoes.models import Comissao, Composicao
from norma.models import LegislacaoCitada, NormaJuridica, TipoNormaJuridica from norma.models import LegislacaoCitada, NormaJuridica, TipoNormaJuridica
from sapl.crud import build_crud
from parlamentares.models import Parlamentar from parlamentares.models import Parlamentar
from sapl.crud import build_crud
from .models import (Anexada, Autor, Autoria, DespachoInicial, from .models import (Anexada, Autor, Autoria, DespachoInicial,
DocumentoAcessorio, MateriaLegislativa, Numeracao, Orgao, DocumentoAcessorio, MateriaLegislativa, Numeracao, Orgao,
Origem, Proposicao, RegimeTramitacao, Relatoria, Origem, Proposicao, RegimeTramitacao, Relatoria,
@ -1926,14 +1928,14 @@ class MateriaLegislativaPesquisaForm(forms.Form):
widget=forms.Select( widget=forms.Select(
attrs={'class': 'selector'})) 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'], input_formats=['%d/%m/%Y'],
required=False, required=False,
widget=forms.DateInput( widget=forms.DateInput(
format='%d/%m/%Y', format='%d/%m/%Y',
attrs={'class': 'dateinput'})) 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'], input_formats=['%d/%m/%Y'],
required=False, required=False,
widget=forms.DateInput( widget=forms.DateInput(
@ -2013,3 +2015,62 @@ class MateriaLegislativaPesquisaView(FormMixin, GenericView):
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):
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

22
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 %}
<table>
<tr><td><h2>Resultados</h2></td></tr>
{% for m in materias %}
<tr>
<td>
<strong><a href="{% url 'materialegislativa:detail' m.id %}">{{m.tipo.sigla}} {{m.numero}}/{{m.ano}} - {{m.tipo}}</strong></a></br>
{{ m.ementa }}</br>
<strong>Localização Atual:</strong> {{m.local_origem_externa}}</br>
</tr>
{% endfor %}
</table>
{% include "paginacao.html" %}
{% else %}
<h2>Nenhum Registro recuperado</h2>
{% endif %}
{% endblock detail_content %}
Loading…
Cancel
Save