Browse Source

Implementa maior parte da pesquisa de Protocolo

pull/339/head
Eduardo Calil 9 years ago
committed by Edward Ribeiro
parent
commit
57c2d90c4e
  1. 33
      protocoloadm/forms.py
  2. 85
      protocoloadm/views.py
  3. 37
      templates/paginacao_pesquisa_materia.html
  4. 66
      templates/protocoloadm/protocolo_filter.html

33
protocoloadm/forms.py

@ -1,5 +1,3 @@
from datetime import date
from crispy_forms.bootstrap import InlineRadios from crispy_forms.bootstrap import InlineRadios
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Button, Field, Fieldset, Layout, Submit from crispy_forms.layout import HTML, Button, Field, Fieldset, Layout, Submit
@ -14,7 +12,7 @@ import sapl
import django_filters import django_filters
from crispy_layout_mixin import form_actions from crispy_layout_mixin import form_actions
from materia.models import Autor, TipoMateriaLegislativa from materia.models import Autor
from sapl.utils import RANGE_ANOS from sapl.utils import RANGE_ANOS
from .models import (DocumentoAcessorioAdministrativo, DocumentoAdministrativo, from .models import (DocumentoAcessorioAdministrativo, DocumentoAdministrativo,
@ -57,14 +55,13 @@ class ProtocoloFilterSet(django_filters.FilterSet):
filter_overrides = {models.DateField: { filter_overrides = {models.DateField: {
'filter_class': django_filters.DateFromToRangeFilter, 'filter_class': django_filters.DateFromToRangeFilter,
'extra': lambda f: { 'extra': lambda f: {
'label': '%s (%s)' % (f.verbose_name, _('Inicial - Final')), 'label': 'Data (%s)' % (_('Inicial - Final')),
'widget': RangeWidgetOverride} 'widget': RangeWidgetOverride}
}} }}
ano = django_filters.ChoiceFilter(required=False, ano = django_filters.ChoiceFilter(required=False,
label=u'Ano da Matéria', label=u'Ano da Matéria',
choices=ANO_CHOICES, choices=ANO_CHOICES)
help_text="")
assunto_ementa = django_filters.CharFilter(lookup_expr='icontains') assunto_ementa = django_filters.CharFilter(lookup_expr='icontains')
@ -75,7 +72,7 @@ class ProtocoloFilterSet(django_filters.FilterSet):
fields = ['tipo_protocolo', fields = ['tipo_protocolo',
'numero', 'numero',
'tipo_documento', 'tipo_documento',
'data_publicacao', 'data',
'tipo_materia', 'tipo_materia',
'autor' 'autor'
] ]
@ -110,8 +107,7 @@ class ProtocoloFilterSet(django_filters.FilterSet):
('ano', 6)]) ('ano', 6)])
row2 = crispy_layout_mixin.to_row( row2 = crispy_layout_mixin.to_row(
[('inicial', 6), [('data', 12)])
('final', 6)])
row3 = crispy_layout_mixin.to_row( row3 = crispy_layout_mixin.to_row(
[('tipo_documento', 4), [('tipo_documento', 4),
@ -130,16 +126,19 @@ class ProtocoloFilterSet(django_filters.FilterSet):
(Button('limpar', (Button('limpar',
'Limpar Autor', 'Limpar Autor',
css_class='btn btn-primary btn-sm'), 10)]) css_class='btn btn-primary btn-sm'), 10)])
row6 = crispy_layout_mixin.to_row(
[('o', 12)])
self.helper = FormHelper() self.form.helper = FormHelper()
self.form.helper.form_method = 'GET' self.form.helper.form_method = 'GET'
self.helper.layout = Layout(Fieldset(_('Pesquisar Protocolo'), self.form.helper.layout = Layout(Fieldset(_(
row1, row2, 'Pesquisar Protocolo'),
row3, row4, row1, row2,
HTML(sapl.utils.autor_label), row3, row4,
HTML(sapl.utils.autor_modal), HTML(sapl.utils.autor_label),
row5, HTML(sapl.utils.autor_modal),
form_actions(save_label='Pesquisar'))) row5, row6,
form_actions(save_label='Pesquisar')))
class AnularProcoloAdmForm(ModelForm): class AnularProcoloAdmForm(ModelForm):

85
protocoloadm/views.py

@ -9,6 +9,7 @@ from django.shortcuts import redirect
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.views.generic import CreateView, DetailView, FormView, ListView from django.views.generic import CreateView, DetailView, FormView, ListView
from django.views.generic.base import TemplateView from django.views.generic.base import TemplateView
from django_filters.views import FilterView
from crud.base import Crud, make_pagination from crud.base import Crud, make_pagination
from materia.models import Proposicao, TipoMateriaLegislativa from materia.models import Proposicao, TipoMateriaLegislativa
@ -16,8 +17,8 @@ from sapl.utils import create_barcode, get_client_ip
from .forms import (AnularProcoloAdmForm, DocumentoAcessorioAdministrativoForm, from .forms import (AnularProcoloAdmForm, DocumentoAcessorioAdministrativoForm,
DocumentoAdministrativoForm, ProposicaoSimpleForm, DocumentoAdministrativoForm, ProposicaoSimpleForm,
ProtocoloDocumentForm, ProtocoloForm, ProtocoloMateriaForm, ProtocoloDocumentForm, ProtocoloFilterSet,
TramitacaoAdmForm) ProtocoloMateriaForm, TramitacaoAdmForm)
from .models import (Autor, DocumentoAcessorioAdministrativo, from .models import (Autor, DocumentoAcessorioAdministrativo,
DocumentoAdministrativo, Protocolo, DocumentoAdministrativo, Protocolo,
StatusTramitacaoAdministrativo, StatusTramitacaoAdministrativo,
@ -37,51 +38,63 @@ ProtocoloDocumentoCrud = Crud.build(Protocolo, '')
ProtocoloMateriaCrud = Crud.build(Protocolo, '') ProtocoloMateriaCrud = Crud.build(Protocolo, '')
class ProtocoloPesquisaView(FormView): class ProtocoloPesquisaView(FilterView):
template_name = 'protocoloadm/protocolo_pesquisa.html' model = Protocolo
form_class = ProtocoloForm filterset_class = ProtocoloFilterSet
context_object_name = 'protocolos' paginate_by = 10
success_url = reverse_lazy('protocoloadm:protocolo')
def post(self, request, *args, **kwargs): def get_filterset_kwargs(self, filterset_class):
form = ProtocoloForm(request.POST or None) super(ProtocoloPesquisaView,
self).get_filterset_kwargs(filterset_class)
if form.is_valid(): kwargs = {'data': self.request.GET or None}
kwargs = {}
if request.POST['tipo_protocolo']: qs = self.get_queryset()
kwargs['tipo_protocolo'] = request.POST['tipo_protocolo']
if request.POST['numero_protocolo']: qs = qs.distinct()
kwargs['numero'] = request.POST['numero_protocolo']
if request.POST['ano']: kwargs.update({
kwargs['ano'] = request.POST['ano'] 'queryset': qs,
})
return kwargs
if request.POST['inicial']: def get_context_data(self, **kwargs):
kwargs['data'] = datetime.strptime( context = super(ProtocoloPesquisaView,
request.POST['inicial'], self).get_context_data(**kwargs)
'%d/%m/%Y').strftime('%Y-%m-%d')
if request.POST['tipo_documento']:
kwargs['tipo_documento'] = request.POST['tipo_documento']
if request.POST['interessado']:
kwargs['interessado__icontains'] = request.POST['interessado']
if request.POST['tipo_materia']: paginator = context['paginator']
kwargs['tipo_materia'] = request.POST['tipo_materia'] page_obj = context['page_obj']
if request.POST['autor']: context['page_range'] = make_pagination(
kwargs['autor'] = request.POST['autor'] page_obj.number, paginator.num_pages)
if request.POST['assunto']: return context
kwargs['assunto_ementa__icontains'] = request.POST['assunto']
request.session['kwargs'] = kwargs def get(self, request, *args, **kwargs):
return redirect('protocoloadm:protocolo_list') super(ProtocoloPesquisaView, self).get(request)
# Se a pesquisa estiver quebrando com a paginação
# Olhe esta função abaixo
# Provavelmente você criou um novo campo no Form/FilterSet
# Então a ordem da URL está diferente
data = self.filterset.data
if (data and data.get('numero') is not None):
url = "&"+str(self.request.environ['QUERY_STRING'])
if url[:5] == "&page":
ponto_comeco = url.find('numero=') - 1
url = url[ponto_comeco:]
else: else:
return self.form_invalid(form) url = ''
self.filterset.form.fields['o'].label = _('Ordenação')
context = self.get_context_data(filter=self.filterset,
object_list=self.object_list,
filter_url=url,
numero_res=len(self.object_list)
)
return self.render_to_response(context)
class ProtocoloListView(ListView): class ProtocoloListView(ListView):

37
templates/paginacao_pesquisa_materia.html

@ -0,0 +1,37 @@
{% if is_paginated %}
<nav class="text-center">
<ul class="pagination">
{% if page_obj.has_previous %}
<li class="page-item">
<a class="page-link" href="?page={{page_obj.previous_page_number}}{{filter_url}}">
<span class="pager-prev">Anterior</span>
</a>
</li>
{% else %}
<li class="pager-prev disabled"><a href="">Anterior</a></li>
{% endif %}
{% for page in page_range %}
{% if page == None or page == 'None' %}
<li class="page-item disabled">
<a class="page-link" href="">...</a>
</li>
{% else %}
<li {% if page == page_obj.number %} class="page-item active" {% endif %}>
<a class="page-link" href="?page={{page}}{{filter_url}}">{{ page }}</a>
</li>
{% endif %}
{% endfor %}
{% if page_obj.has_next %}
<li class="page-item">
<a class="page-link" href="?page={{page_obj.next_page_number}}{{filter_url}}">
<span class="pager-next">Próxima</span>
</a>
</li>
{% else %}
<li class="pager-next disabled"><a href="">Próxima</a></li>
{% endif %}
</ul>
</nav>
{% endif %}

66
templates/protocoloadm/protocolo_filter.html

@ -0,0 +1,66 @@
{% extends "protocoloadm/protocoloadm_detail.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% load static %}
{% block actions %}{% endblock %}
{% block sections_nav %} {% endblock %}
{% block detail_content %}
<h1><b>Pesquisar Protocolo</b></h1>
<br></br>
{% crispy filter.form %}
<p></p>
<table class="table table-striped table-bordered">
<thead class="thead-default">
<tr><td><h3>Resultados</h3></td></tr>
</thead>
{% if page_obj|length %}
{% if filter_url %}
<h3>Pesquisa concluída com sucesso! Foram encontrados {{numero_res}} protocolos.</h3>
{% endif %}
{% for p in page_obj %}
<tr>
<td>
<strong>Protocolo:</strong>
<a href="{% url 'protocoloadm:protocolo_mostrar' p.numero p.ano %}">
{{ p.numero|stringformat:'06d' }}/{{ p.ano }}
</a>
&nbsp;&nbsp;-&nbsp;&nbsp;
<a href="{% url 'relatorios:relatorio_etiqueta_protocolo' p.numero p.ano %}">
<img src="{% static 'img/etiqueta.png' %}" alt="Etiqueta Individual">
</a></br>
<strong>Assunto:</strong> {{ p.assunto_ementa }}</br>
<strong>Data Protocolo:</strong> {{ p.data|date:"d/m/Y" }} - Horário: {{ p.timestamp|date:"H:m:s" }}</br>
<strong>Interessado:</strong> {{ p.interessado }}</br>
<strong>Natureza do Processo:</strong>
{% if p.tipo_processo == 0 %}
Administrativo
{% elif p.tipo_processo == 1 %}
Matéria Legislativa
{% endif %}</br>
<strong>Classificação:</strong> {{ p.tipo_documento }} </br>
<p></p>
</td>
</tr>
{% endfor %}
{% else %}
<tr>
<td>
<h3>Nenhum protocolo encontrado com essas especificações</h3>
</tr>
{% endif %}
</table>
{% include "paginacao_pesquisa_materia.html" %}
{% endblock detail_content %}
Loading…
Cancel
Save