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.helper import FormHelper
from crispy_forms.layout import HTML, Button, Field, Fieldset, Layout, Submit
@ -14,7 +12,7 @@ import sapl
import django_filters
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 .models import (DocumentoAcessorioAdministrativo, DocumentoAdministrativo,
@ -57,14 +55,13 @@ class ProtocoloFilterSet(django_filters.FilterSet):
filter_overrides = {models.DateField: {
'filter_class': django_filters.DateFromToRangeFilter,
'extra': lambda f: {
'label': '%s (%s)' % (f.verbose_name, _('Inicial - Final')),
'label': 'Data (%s)' % (_('Inicial - Final')),
'widget': RangeWidgetOverride}
}}
ano = django_filters.ChoiceFilter(required=False,
label=u'Ano da Matéria',
choices=ANO_CHOICES,
help_text="")
choices=ANO_CHOICES)
assunto_ementa = django_filters.CharFilter(lookup_expr='icontains')
@ -75,7 +72,7 @@ class ProtocoloFilterSet(django_filters.FilterSet):
fields = ['tipo_protocolo',
'numero',
'tipo_documento',
'data_publicacao',
'data',
'tipo_materia',
'autor'
]
@ -110,8 +107,7 @@ class ProtocoloFilterSet(django_filters.FilterSet):
('ano', 6)])
row2 = crispy_layout_mixin.to_row(
[('inicial', 6),
('final', 6)])
[('data', 12)])
row3 = crispy_layout_mixin.to_row(
[('tipo_documento', 4),
@ -130,16 +126,19 @@ class ProtocoloFilterSet(django_filters.FilterSet):
(Button('limpar',
'Limpar Autor',
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.helper.layout = Layout(Fieldset(_('Pesquisar Protocolo'),
row1, row2,
row3, row4,
HTML(sapl.utils.autor_label),
HTML(sapl.utils.autor_modal),
row5,
form_actions(save_label='Pesquisar')))
self.form.helper.layout = Layout(Fieldset(_(
'Pesquisar Protocolo'),
row1, row2,
row3, row4,
HTML(sapl.utils.autor_label),
HTML(sapl.utils.autor_modal),
row5, row6,
form_actions(save_label='Pesquisar')))
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.views.generic import CreateView, DetailView, FormView, ListView
from django.views.generic.base import TemplateView
from django_filters.views import FilterView
from crud.base import Crud, make_pagination
from materia.models import Proposicao, TipoMateriaLegislativa
@ -16,8 +17,8 @@ from sapl.utils import create_barcode, get_client_ip
from .forms import (AnularProcoloAdmForm, DocumentoAcessorioAdministrativoForm,
DocumentoAdministrativoForm, ProposicaoSimpleForm,
ProtocoloDocumentForm, ProtocoloForm, ProtocoloMateriaForm,
TramitacaoAdmForm)
ProtocoloDocumentForm, ProtocoloFilterSet,
ProtocoloMateriaForm, TramitacaoAdmForm)
from .models import (Autor, DocumentoAcessorioAdministrativo,
DocumentoAdministrativo, Protocolo,
StatusTramitacaoAdministrativo,
@ -37,51 +38,63 @@ ProtocoloDocumentoCrud = Crud.build(Protocolo, '')
ProtocoloMateriaCrud = Crud.build(Protocolo, '')
class ProtocoloPesquisaView(FormView):
template_name = 'protocoloadm/protocolo_pesquisa.html'
form_class = ProtocoloForm
context_object_name = 'protocolos'
success_url = reverse_lazy('protocoloadm:protocolo')
class ProtocoloPesquisaView(FilterView):
model = Protocolo
filterset_class = ProtocoloFilterSet
paginate_by = 10
def post(self, request, *args, **kwargs):
form = ProtocoloForm(request.POST or None)
def get_filterset_kwargs(self, filterset_class):
super(ProtocoloPesquisaView,
self).get_filterset_kwargs(filterset_class)
if form.is_valid():
kwargs = {}
kwargs = {'data': self.request.GET or None}
if request.POST['tipo_protocolo']:
kwargs['tipo_protocolo'] = request.POST['tipo_protocolo']
qs = self.get_queryset()
if request.POST['numero_protocolo']:
kwargs['numero'] = request.POST['numero_protocolo']
qs = qs.distinct()
if request.POST['ano']:
kwargs['ano'] = request.POST['ano']
kwargs.update({
'queryset': qs,
})
return kwargs
if request.POST['inicial']:
kwargs['data'] = datetime.strptime(
request.POST['inicial'],
'%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']
def get_context_data(self, **kwargs):
context = super(ProtocoloPesquisaView,
self).get_context_data(**kwargs)
if request.POST['tipo_materia']:
kwargs['tipo_materia'] = request.POST['tipo_materia']
paginator = context['paginator']
page_obj = context['page_obj']
if request.POST['autor']:
kwargs['autor'] = request.POST['autor']
context['page_range'] = make_pagination(
page_obj.number, paginator.num_pages)
if request.POST['assunto']:
kwargs['assunto_ementa__icontains'] = request.POST['assunto']
return context
request.session['kwargs'] = kwargs
return redirect('protocoloadm:protocolo_list')
def get(self, request, *args, **kwargs):
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:
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):

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