From 74556027403d9edee3f64df7d54964c24df72f9e Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Wed, 13 Sep 2017 19:41:31 -0300 Subject: [PATCH] Fix #1474 bug iframe telas pesquisa (#1478) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix #1474 * Conserta PEP8 * Melhoria no código --- sapl/base/views.py | 18 +++++++++++- sapl/materia/tests/test_materia.py | 1 + sapl/materia/tests/test_materia_form.py | 6 ++-- sapl/materia/urls.py | 4 +-- sapl/materia/views.py | 29 ++++++++++++++----- sapl/norma/views.py | 3 ++ sapl/parlamentares/views.py | 5 ++-- sapl/protocoloadm/views.py | 8 ++++- sapl/sessao/urls.py | 5 ++-- sapl/sessao/views.py | 9 ++++-- .../RelatorioHistoricoTramitacao_filter.html | 4 +-- ...latorioMateriasPorAnoAutorTipo_filter.html | 4 +-- .../RelatorioMateriasPorAutor_filter.html | 4 +-- .../base/RelatorioPresencaSessao_filter.html | 4 +-- sapl/templates/materia/em_lote/acessorio.html | 4 +-- .../templates/materia/em_lote/tramitacao.html | 4 +-- .../materia/materialegislativa_filter.html | 6 ++-- .../templates/norma/normajuridica_filter.html | 6 ++-- .../documentoadministrativo_filter.html | 6 ++-- .../protocoloadm/protocolo_filter.html | 8 ++--- .../sessao/sessaoplenaria_filter.html | 2 +- sapl/utils.py | 9 ++++++ 22 files changed, 100 insertions(+), 49 deletions(-) diff --git a/sapl/base/views.py b/sapl/base/views.py index cae2052c9..3edc7a99c 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -23,7 +23,8 @@ from sapl.materia.models import (Autoria, MateriaLegislativa, TipoMateriaLegislativa) from sapl.sessao.models import (PresencaOrdemDia, SessaoPlenaria, SessaoPlenariaPresenca) -from sapl.utils import parlamentares_ativos, sapl_logger +from sapl.utils import (parlamentares_ativos, sapl_logger,\ + show_results_filter_set) from .forms import (CasaLegislativaForm, ConfiguracoesAppForm, RelatorioAtasFilterSet, @@ -202,6 +203,9 @@ class RelatorioAtasView(FilterView): context['object_list'] = context['object_list'].exclude(upload_ata='') qr = self.request.GET.copy() context['filter_url'] = ('&' + qr.urlencode()) if len(qr) > 0 else '' + + context['show_results'] = show_results_filter_set(qr) + return context @@ -294,6 +298,9 @@ class RelatorioPresencaSessaoView(FilterView): # ===================================================================== qr = self.request.GET.copy() context['filter_url'] = ('&' + qr.urlencode()) if len(qr) > 0 else '' + + context['show_results'] = show_results_filter_set(qr) + return context @@ -308,6 +315,9 @@ class RelatorioHistoricoTramitacaoView(FilterView): context['title'] = _('Histórico de Tramitações') qr = self.request.GET.copy() context['filter_url'] = ('&' + qr.urlencode()) if len(qr) > 0 else '' + + context['show_results'] = show_results_filter_set(qr) + return context @@ -337,6 +347,8 @@ class RelatorioMateriasTramitacaoView(FilterView): qr = self.request.GET.copy() context['filter_url'] = ('&' + qr.urlencode()) if len(qr) > 0 else '' + context['show_results'] = show_results_filter_set(qr) + return context @@ -409,6 +421,8 @@ class RelatorioMateriasPorAnoAutorTipoView(FilterView): qr = self.request.GET.copy() context['filter_url'] = ('&' + qr.urlencode()) if len(qr) > 0 else '' + context['show_results'] = show_results_filter_set(qr) + if 'ano' in self.request.GET and self.request.GET['ano']: ano = int(self.request.GET['ano']) context['relatorio'] = self.get_materias_autor_ano(ano) @@ -447,6 +461,8 @@ class RelatorioMateriasPorAutorView(FilterView): qr = self.request.GET.copy() context['filter_url'] = ('&' + qr.urlencode()) if len(qr) > 0 else '' + context['show_results'] = show_results_filter_set(qr) + return context diff --git a/sapl/materia/tests/test_materia.py b/sapl/materia/tests/test_materia.py index 39c17020b..c7a773a9c 100644 --- a/sapl/materia/tests/test_materia.py +++ b/sapl/materia/tests/test_materia.py @@ -17,6 +17,7 @@ from sapl.norma.models import (LegislacaoCitada, NormaJuridica, TipoNormaJuridica) from sapl.utils import models_with_gr_for_model + @pytest.mark.django_db(transaction=False) def make_unidade_tramitacao(descricao): # Cria uma comissão para ser a unidade de tramitação diff --git a/sapl/materia/tests/test_materia_form.py b/sapl/materia/tests/test_materia_form.py index a700ee45a..41ad04837 100644 --- a/sapl/materia/tests/test_materia_form.py +++ b/sapl/materia/tests/test_materia_form.py @@ -3,7 +3,8 @@ from django.utils.translation import ugettext as _ from model_mommy import mommy from sapl.materia import forms -from sapl.materia.models import (MateriaLegislativa, TipoMateriaLegislativa) +from sapl.materia.models import MateriaLegislativa, TipoMateriaLegislativa + @pytest.mark.django_db(transaction=False) def test_valida_campos_obrigatorios_ficha_pesquisa_form(): @@ -19,6 +20,7 @@ def test_valida_campos_obrigatorios_ficha_pesquisa_form(): assert len(errors) == 3 + @pytest.mark.django_db(transaction=False) def test_ficha_pesquisa_form_datas_invalidas(): tipo = mommy.make(TipoMateriaLegislativa) @@ -29,7 +31,7 @@ def test_ficha_pesquisa_form_datas_invalidas(): }) assert not form.is_valid() assert form.errors['__all__'] == [_('A Data Final não pode ser menor que ' - 'a Data Inicial')] + 'a Data Inicial')] @pytest.mark.django_db(transaction=False) diff --git a/sapl/materia/urls.py b/sapl/materia/urls.py index a59dc8592..b6a87cd5f 100644 --- a/sapl/materia/urls.py +++ b/sapl/materia/urls.py @@ -8,8 +8,8 @@ from sapl.materia.views import (AcompanhamentoConfirmarView, CriarProtocoloMateriaView, DespachoInicialCrud, DocumentoAcessorioCrud, DocumentoAcessorioEmLoteView, - ImpressosView, EtiquetaPesquisaView, - FichaPesquisaView, FichaSelecionaView, + EtiquetaPesquisaView, FichaPesquisaView, + FichaSelecionaView, ImpressosView, LegislacaoCitadaCrud, MateriaAssuntoCrud, MateriaLegislativaCrud, MateriaLegislativaPesquisaView, MateriaTaView, diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 8ef6e625b..9a35204b1 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -14,7 +14,7 @@ from django.core.urlresolvers import reverse from django.http import HttpResponse, JsonResponse from django.http.response import Http404, HttpResponseRedirect from django.shortcuts import get_object_or_404, redirect -from django.template import loader, RequestContext +from django.template import RequestContext, loader from django.utils import formats from django.utils.translation import ugettext_lazy as _ from django.views.generic import CreateView, ListView, TemplateView, UpdateView @@ -42,7 +42,7 @@ from sapl.norma.models import LegislacaoCitada from sapl.protocoloadm.models import Protocolo from sapl.utils import (TURNO_TRAMITACAO_CHOICES, YES_NO_CHOICES, autor_label, autor_modal, gerar_hash_arquivo, get_base_url, - montar_row_autor) + montar_row_autor, show_results_filter_set) from .email_utils import do_envia_email_confirmacao from .forms import (AcessorioEmLoteFilterSet, AcompanhamentoMateriaForm, @@ -138,6 +138,9 @@ class AdicionarVariasAutorias(PermissionRequiredForAppCrudMixin, FilterView): context['title'] = _('Pesquisar Autores') qr = self.request.GET.copy() context['filter_url'] = ('&' + qr.urlencode()) if len(qr) > 0 else '' + + context['show_results'] = show_results_filter_set(qr) + context['pk_materia'] = self.kwargs['pk'] return context @@ -1509,6 +1512,8 @@ class MateriaLegislativaPesquisaView(FilterView): context['filter_url'] = ('&' + qr.urlencode()) if len(qr) > 0 else '' + context['show_results'] = show_results_filter_set(qr) + return context @@ -1610,6 +1615,9 @@ class DocumentoAcessorioEmLoteView(PermissionRequiredMixin, FilterView): context['object_list'] = context['object_list'].order_by( 'ano', 'numero') context['filter_url'] = ('&' + qr.urlencode()) if len(qr) > 0 else '' + + context['show_results'] = show_results_filter_set(qr) + return context def post(self, request, *args, **kwargs): @@ -1677,6 +1685,9 @@ class PrimeiraTramitacaoEmLoteView(PermissionRequiredMixin, FilterView): 'ano', 'numero') context['filter_url'] = ('&' + qr.urlencode()) if len(qr) > 0 else '' + + context['show_results'] = show_results_filter_set(qr) + return context def post(self, request, *args, **kwargs): @@ -1819,6 +1830,7 @@ class FichaPesquisaView(PermissionRequiredMixin, FormView): return HttpResponseRedirect(url) + class FichaSelecionaView(PermissionRequiredMixin, FormView): form_class = FichaSelecionaForm template_name = 'materia/impressos/ficha_seleciona.html' @@ -1827,7 +1839,7 @@ class FichaSelecionaView(PermissionRequiredMixin, FormView): def get_context_data(self, **kwargs): if ('tipo' not in self.request.GET or 'data_inicial' not in self.request.GET or - 'data_final' not in self.request.GET): + 'data_final' not in self.request.GET): return HttpResponseRedirect(reverse( 'sapl.materia:impressos_ficha_pesquisa')) @@ -1846,13 +1858,14 @@ class FichaSelecionaView(PermissionRequiredMixin, FormView): context['quantidade'] = len(materia_list) materia_list = materia_list[:20] - context['form'].fields['materia'].choices = [(m.id, str(m)) for m in materia_list] + context['form'].fields['materia'].choices = [ + (m.id, str(m)) for m in materia_list] if context['quantidade'] > 20: messages.info(self.request, _('Sua pesquisa retornou mais do que ' - '20 impressos. Por questões de performance, foram retornados ' - 'apenas os 20 primeiros. Caso queira outros, tente fazer uma ' - 'pesquisa mais específica')) + '20 impressos. Por questões de performance, foram retornados ' + 'apenas os 20 primeiros. Caso queira outros, tente fazer uma ' + 'pesquisa mais específica')) return context @@ -1870,6 +1883,6 @@ class FichaSelecionaView(PermissionRequiredMixin, FormView): context['materia'] = materia context['despachos'] = materia.despachoinicial_set.all().values_list( - 'comissao__nome', flat=True) + 'comissao__nome', flat=True) return gerar_pdf_impressos(self.request, context, 'materia/impressos/ficha_pdf.html') diff --git a/sapl/norma/views.py b/sapl/norma/views.py index 8e70bd8e1..33589f243 100644 --- a/sapl/norma/views.py +++ b/sapl/norma/views.py @@ -11,6 +11,7 @@ from sapl.base.models import AppConfig from sapl.compilacao.views import IntegracaoTaView from sapl.crud.base import (RP_DETAIL, RP_LIST, Crud, CrudAux, MasterDetailCrud, make_pagination) +from sapl.utils import show_results_filter_set from .forms import NormaFilterSet, NormaJuridicaForm, NormaRelacionadaForm from .models import (AssuntoNorma, NormaJuridica, NormaRelacionada, @@ -81,6 +82,8 @@ class NormaPesquisaView(FilterView): context['filter_url'] = ('&' + qr.urlencode()) if len(qr) > 0 else '' + context['show_results'] = show_results_filter_set(qr) + return context diff --git a/sapl/parlamentares/views.py b/sapl/parlamentares/views.py index 0a27e8c4e..6f4cf4265 100644 --- a/sapl/parlamentares/views.py +++ b/sapl/parlamentares/views.py @@ -25,9 +25,8 @@ from sapl.materia.models import Autoria, Proposicao, Relatoria from sapl.parlamentares.apps import AppConfig from sapl.utils import parlamentares_ativos -from .forms import (FiliacaoForm, LegislaturaForm, - MandatoForm, ParlamentarCreateForm, ParlamentarForm, - VotanteForm) +from .forms import (FiliacaoForm, LegislaturaForm, MandatoForm, + ParlamentarCreateForm, ParlamentarForm, VotanteForm) from .models import (CargoMesa, Coligacao, ComposicaoColigacao, ComposicaoMesa, Dependente, Filiacao, Frente, Legislatura, Mandato, NivelInstrucao, Parlamentar, Partido, SessaoLegislativa, diff --git a/sapl/protocoloadm/views.py b/sapl/protocoloadm/views.py index 82de1d73d..c2ff10189 100644 --- a/sapl/protocoloadm/views.py +++ b/sapl/protocoloadm/views.py @@ -21,7 +21,7 @@ from sapl.crud.base import Crud, CrudAux, MasterDetailCrud, make_pagination from sapl.materia.models import MateriaLegislativa, TipoMateriaLegislativa from sapl.parlamentares.models import Legislatura, Parlamentar from sapl.protocoloadm.models import Protocolo -from sapl.utils import create_barcode, get_client_ip +from sapl.utils import create_barcode, get_client_ip, show_results_filter_set from .forms import (AnularProcoloAdmForm, DocumentoAcessorioAdministrativoForm, DocumentoAdministrativoFilterSet, @@ -212,6 +212,9 @@ class ProtocoloPesquisaView(PermissionRequiredMixin, FilterView): numero_res=len(self.object_list) ) + context['show_results'] = show_results_filter_set( + self.request.GET.copy()) + return self.render_to_response(context) @@ -564,6 +567,9 @@ class PesquisarDocumentoAdministrativoView(DocumentoAdministrativoMixin, numero_res=len(self.object_list) ) + context['show_results'] = show_results_filter_set( + self.request.GET.copy()) + return self.render_to_response(context) diff --git a/sapl/sessao/urls.py b/sapl/sessao/urls.py index 3edf60104..e454a9eee 100644 --- a/sapl/sessao/urls.py +++ b/sapl/sessao/urls.py @@ -19,9 +19,8 @@ from sapl.sessao.views import (AdicionarVariasMateriasExpediente, VotacaoNominalExpedienteDetailView, VotacaoNominalExpedienteEditView, VotacaoNominalExpedienteView, - VotacaoNominalView, VotacaoView, - abrir_votacao, atualizar_mesa, - insere_parlamentar_composicao, + VotacaoNominalView, VotacaoView, abrir_votacao, + atualizar_mesa, insere_parlamentar_composicao, mudar_ordem_materia_sessao, recuperar_materia, recuperar_numero_sessao, remove_parlamentar_composicao, diff --git a/sapl/sessao/views.py b/sapl/sessao/views.py index c3775f3dd..c68987bc6 100644 --- a/sapl/sessao/views.py +++ b/sapl/sessao/views.py @@ -34,6 +34,7 @@ from sapl.parlamentares.models import (Filiacao, Legislatura, Mandato, Parlamentar, SessaoLegislativa) from sapl.sessao.apps import AppConfig from sapl.sessao.forms import ExpedienteMateriaForm, OrdemDiaForm +from sapl.utils import show_results_filter_set from .forms import (AdicionarVariasMateriasFilterSet, ExpedienteForm, ListMateriaForm, MesaForm, OradorExpedienteForm, @@ -117,7 +118,7 @@ def verifica_sessao_iniciada(request, spk): sessao = SessaoPlenaria.objects.get(id=spk) if not sessao.iniciada or sessao.finalizada: - msg = _('Não é possível abrir matérias para votação. '\ + msg = _('Não é possível abrir matérias para votação. ' 'Esta Sessão Plenária não foi iniciada ou está finalizada.') messages.add_message(request, messages.INFO, msg) return False @@ -143,8 +144,8 @@ def abrir_votacao(request, pk, spk): raise Http404 if (verifica_presenca(request, presenca_model, spk) and - verifica_votacoes_abertas(request) and - verifica_sessao_iniciada(request, spk)): + verifica_votacoes_abertas(request) and + verifica_sessao_iniciada(request, spk)): materia_votacao = model.objects.get(id=pk) materia_votacao.votacao_aberta = True materia_votacao.save() @@ -2455,6 +2456,8 @@ class PesquisarSessaoPlenariaView(FilterView): numero_res=len(self.object_list) ) + context['show_results'] = show_results_filter_set(self.request.GET.copy()) + return self.render_to_response(context) diff --git a/sapl/templates/base/RelatorioHistoricoTramitacao_filter.html b/sapl/templates/base/RelatorioHistoricoTramitacao_filter.html index 8cba5d186..421be8d06 100644 --- a/sapl/templates/base/RelatorioHistoricoTramitacao_filter.html +++ b/sapl/templates/base/RelatorioHistoricoTramitacao_filter.html @@ -3,11 +3,11 @@ {% load crispy_forms_tags %} {% block base_content %} - {% if not filter_url %} + {% if not show_results %} {% crispy filter.form %} {% endif %} - {% if filter_url %} + {% if show_results %}
{% trans 'Fazer nova pesquisa' %}
diff --git a/sapl/templates/base/RelatorioMateriasPorAnoAutorTipo_filter.html b/sapl/templates/base/RelatorioMateriasPorAnoAutorTipo_filter.html index 23ef5e275..43deac36b 100644 --- a/sapl/templates/base/RelatorioMateriasPorAnoAutorTipo_filter.html +++ b/sapl/templates/base/RelatorioMateriasPorAnoAutorTipo_filter.html @@ -3,11 +3,11 @@ {% load crispy_forms_tags %} {% block base_content %} - {% if not filter_url %} + {% if not show_results %} {% crispy filter.form %} {% endif %} - {% if filter_url %} + {% if show_results %}
{% trans 'Fazer nova pesquisa' %}
diff --git a/sapl/templates/base/RelatorioMateriasPorAutor_filter.html b/sapl/templates/base/RelatorioMateriasPorAutor_filter.html index 889caf0f1..c75aad42b 100644 --- a/sapl/templates/base/RelatorioMateriasPorAutor_filter.html +++ b/sapl/templates/base/RelatorioMateriasPorAutor_filter.html @@ -3,11 +3,11 @@ {% load crispy_forms_tags %} {% block base_content %} - {% if not filter_url %} + {% if not show_results %} {% crispy filter.form %} {% endif %} - {% if filter_url %} + {% if show_results %}
{% trans 'Fazer nova pesquisa' %}
diff --git a/sapl/templates/base/RelatorioPresencaSessao_filter.html b/sapl/templates/base/RelatorioPresencaSessao_filter.html index ea3b1fca2..e3e447f8d 100644 --- a/sapl/templates/base/RelatorioPresencaSessao_filter.html +++ b/sapl/templates/base/RelatorioPresencaSessao_filter.html @@ -4,11 +4,11 @@ {% load common_tags %} {% block base_content %} - {% if not filter_url %} + {% if not show_results %} {% crispy filter.form %} {% endif %} - {% if filter_url %} + {% if show_results %}