Browse Source

Implementa maior parte da pesquisa de Protocolo

pull/339/head
Eduardo Calil 9 years ago
parent
commit
79a8a4d72e
  1. 84
      protocoloadm/forms.py
  2. 83
      protocoloadm/views.py
  3. 2
      sapl/settings.py
  4. 37
      templates/paginacao_pesquisa_materia.html
  5. 66
      templates/protocoloadm/protocolo_filter.html

84
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,
@ -31,67 +29,6 @@ NATUREZA_PROCESSO = [('0', 'Administrativo'),
ANO_CHOICES = [('', '---------')] + RANGE_ANOS
# class ProtocoloForm(forms.Form):
# YEARS = get_range_anos()
# tipo_protocolo = forms.ChoiceField(required=False,
# label='Tipo de Protocolo',
# choices=TIPOS_PROTOCOLO,
# widget=forms.Select(
# attrs={'class': 'selector'}))
# numero_protocolo = forms.CharField(
# label='Número de Protocolo', required=False)
# ano = forms.ChoiceField(required=False,
# label='Ano',
# choices=YEARS,
# widget=forms.Select(
# attrs={'class': 'selector'}))
# inicial = forms.DateField(label='Data Inicial',
# required=False,
# widget=forms.TextInput(
# attrs={'class': 'dateinput'}))
# final = forms.DateField(label='Data Final', required=False,
# widget=forms.TextInput(
# attrs={'class': 'dateinput'}))
# natureza_processo = forms.ChoiceField(required=False,
# label='Natureza Processo',
# choices=[
# ('0', 'Administrativo'),
# ('1', 'Legislativo'),
# ('', 'Ambos')])
# tipo_documento = forms.ModelChoiceField(
# label='Tipo de Documento',
# required=False,
# queryset=TipoDocumentoAdministrativo.objects.all(),
# empty_label='Selecione',
# )
# interessado = forms.CharField(label='Interessado', required=False)
# tipo_materia = forms.ModelChoiceField(
# label='Tipo de Matéria',
# required=False,
# queryset=TipoMateriaLegislativa.objects.all(),
# empty_label='Selecione',
# )
# autor = forms.CharField(widget=forms.HiddenInput(), required=False)
# assunto = forms.CharField(label='Assunto', required=False)
# def __init__(self, *args, **kwargs):
# super(ProtocoloForm, self).__init__(
# *args, **kwargs)
# Importar essa classe de materias.views quando for feito o Merge do branch 217
class RangeWidgetOverride(forms.MultiWidget):
@ -118,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')
@ -136,7 +72,7 @@ class ProtocoloFilterSet(django_filters.FilterSet):
fields = ['tipo_protocolo',
'numero',
'tipo_documento',
'data_publicacao',
'data',
'tipo_materia',
'autor'
]
@ -171,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),
@ -191,15 +126,18 @@ 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'),
self.form.helper.layout = Layout(Fieldset(_(
'Pesquisar Protocolo'),
row1, row2,
row3, row4,
HTML(sapl.utils.autor_label),
HTML(sapl.utils.autor_modal),
row5,
row5, row6,
form_actions(save_label='Pesquisar')))

83
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')
def get_context_data(self, **kwargs):
context = super(ProtocoloPesquisaView,
self).get_context_data(**kwargs)
if request.POST['tipo_documento']:
kwargs['tipo_documento'] = request.POST['tipo_documento']
paginator = context['paginator']
page_obj = context['page_obj']
if request.POST['interessado']:
kwargs['interessado__icontains'] = request.POST['interessado']
context['page_range'] = make_pagination(
page_obj.number, paginator.num_pages)
if request.POST['tipo_materia']:
kwargs['tipo_materia'] = request.POST['tipo_materia']
return context
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:
url = ''
if request.POST['autor']:
kwargs['autor'] = request.POST['autor']
self.filterset.form.fields['o'].label = _('Ordenação')
if request.POST['assunto']:
kwargs['assunto_ementa__icontains'] = request.POST['assunto']
context = self.get_context_data(filter=self.filterset,
object_list=self.object_list,
filter_url=url,
numero_res=len(self.object_list)
)
request.session['kwargs'] = kwargs
return redirect('protocoloadm:protocolo_list')
else:
return self.form_invalid(form)
return self.render_to_response(context)
class ProtocoloListView(ListView):

2
sapl/settings.py

@ -187,3 +187,5 @@ SASS_PROCESSOR_INCLUDE_DIRS = (BOWER_COMPONENTS_ROOT.child(
# hack to suppress many annoying warnings from crispy_forms
# see sapl.temp_suppress_crispy_form_warnings
LOGGING = SUPRESS_CRISPY_FORM_WARNINGS_LOGGING
FILTERS_HELP_TEXT_FILTER = False

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