diff --git a/protocoloadm/forms.py b/protocoloadm/forms.py index 6bf4bf840..c27a56f8c 100644 --- a/protocoloadm/forms.py +++ b/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): diff --git a/protocoloadm/views.py b/protocoloadm/views.py index 510959798..35f00186d 100644 --- a/protocoloadm/views.py +++ b/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): diff --git a/templates/paginacao_pesquisa_materia.html b/templates/paginacao_pesquisa_materia.html new file mode 100644 index 000000000..f82dcd48a --- /dev/null +++ b/templates/paginacao_pesquisa_materia.html @@ -0,0 +1,37 @@ +{% if is_paginated %} + +{% endif %} \ No newline at end of file diff --git a/templates/protocoloadm/protocolo_filter.html b/templates/protocoloadm/protocolo_filter.html new file mode 100644 index 000000000..6e84f4381 --- /dev/null +++ b/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 %} +

Pesquisar Protocolo

+

+ + {% crispy filter.form %} + +

+ + + + + {% if page_obj|length %} + {% if filter_url %} +

Pesquisa concluída com sucesso! Foram encontrados {{numero_res}} protocolos.

+ {% endif %} + {% for p in page_obj %} + + + + {% endfor %} + {% else %} + + + {% endif %} + +

Resultados

+ Protocolo: + + {{ p.numero|stringformat:'06d' }}/{{ p.ano }} + +   -   + + + Etiqueta Individual +
+ + Assunto: {{ p.assunto_ementa }}
+ + Data Protocolo: {{ p.data|date:"d/m/Y" }} - Horário: {{ p.timestamp|date:"H:m:s" }}
+ + Interessado: {{ p.interessado }}
+ + Natureza do Processo: + {% if p.tipo_processo == 0 %} + Administrativo + {% elif p.tipo_processo == 1 %} + Matéria Legislativa + {% endif %}
+ + Classificação: {{ p.tipo_documento }}
+

+
+

Nenhum protocolo encontrado com essas especificações

+
+ +{% include "paginacao_pesquisa_materia.html" %} + +{% endblock detail_content %} \ No newline at end of file