diff --git a/sapl/base/forms.py b/sapl/base/forms.py index 8a6df3366..c871f39f8 100644 --- a/sapl/base/forms.py +++ b/sapl/base/forms.py @@ -904,6 +904,8 @@ class EstatisticasAcessoNormasForm(Form): class RelatorioNormasVigenciaFilterSet(django_filters.FilterSet): + o = AnoNumeroOrderingFilter(help_text='') + ano = django_filters.ChoiceFilter(required=True, label='Ano da Norma', choices=choice_anos_com_normas, @@ -927,12 +929,27 @@ class RelatorioNormasVigenciaFilterSet(django_filters.FilterSet): row1 = to_row([('ano', 12)]) row2 = to_row([('vigencia', 12)]) + buttons = FormActions( + *[ + HTML(''' +
+ + +
+ ''') + ], + Submit('pesquisar', _('Pesquisar'), css_class='float-right', + onclick='return true;'), + css_class='form-group row justify-content-between' + , + ) + self.form.helper = SaplFormHelper() self.form.helper.form_method = 'GET' self.form.helper.layout = Layout( Fieldset(_('Normas por vigência.'), row1, row2, - form_actions(label='Pesquisar')) + buttons, ) ) @property diff --git a/sapl/base/views.py b/sapl/base/views.py index 048ffcee4..723fc9075 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -32,7 +32,8 @@ from haystack.query import SearchQuerySet from sapl.relatorios.views import (relatorio_materia_em_tramitacao, relatorio_materia_por_autor, relatorio_materia_por_ano_autor, relatorio_presenca_sessao, relatorio_historico_tramitacao, relatorio_fim_prazo_tramitacao, - relatorio_atas, relatorio_audiencia, relatorio_normas_mes) + relatorio_atas, relatorio_audiencia, relatorio_normas_mes, + relatorio_normas_vigencia) from sapl import settings from sapl.audiencia.models import AudienciaPublica, TipoAudienciaPublica @@ -1274,6 +1275,41 @@ class RelatorioNormasVigenciaView(FilterView): return kwargs + def get(self, request, *args, **kwargs): + super(RelatorioNormasVigenciaView, 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('tipo') is not None: + url = "&" + str(self.request.environ['QUERY_STRING']) + if url.startswith("&page"): + ponto_comeco = url.find('tipo=') - 1 + url = url[ponto_comeco:] + else: + url = '' + self.filterset.form.fields['o'].label = _('Ordenação') + # é usada essa verificação anônima para quando os documentos administrativos + # estão no modo ostensivo, mas podem existir documentos administrativos + # restritos + length = self.object_list.count() + + is_relatorio = request.GET.get('relatorio', None) + self.paginate_by = None if is_relatorio else self.paginate_by + context = self.get_context_data(filter=self.filterset, + filter_url=url, + numero_res=length + ) + context['show_results'] = show_results_filter_set( + self.request.GET.copy()) + + if is_relatorio: + return relatorio_normas_vigencia(request, context) + else: + return self.render_to_response(context) + + def get_context_data(self, **kwargs): context = super(RelatorioNormasVigenciaView, self).get_context_data(**kwargs) diff --git a/sapl/relatorios/views.py b/sapl/relatorios/views.py index 9854d77d4..469a9b759 100755 --- a/sapl/relatorios/views.py +++ b/sapl/relatorios/views.py @@ -1571,6 +1571,53 @@ def relatorio_normas_mes(request, context): return response +def relatorio_normas_mes(request, context): + base_url = request.build_absolute_uri() + casa = CasaLegislativa.objects.first() + rodape = ' '.join(get_rodape(casa)) + + context.update({'data': dt.today().strftime('%d/%m/%Y')}) + context.update({'rodape': rodape}) + + header_context = {"casa": casa, 'logotipo': casa.logotipo, 'MEDIA_URL': MEDIA_URL} + + html_template = render_to_string('relatorios/relatorio_normas_mes.html', context) + html_header = render_to_string('relatorios/header_ata.html', header_context) + + pdf_file = make_pdf(base_url=base_url, main_template=html_template, header_template=html_header) + + response = HttpResponse(content_type='application/pdf;') + response['Content-Disposition'] = 'inline; filename=relatorio.pdf' + response['Content-Transfer-Encoding'] = 'binary' + response.write(pdf_file) + + return response + + + +def relatorio_normas_vigencia(request, context): + base_url = request.build_absolute_uri() + casa = CasaLegislativa.objects.first() + rodape = ' '.join(get_rodape(casa)) + + context.update({'data': dt.today().strftime('%d/%m/%Y')}) + context.update({'rodape': rodape}) + + header_context = {"casa": casa, 'logotipo': casa.logotipo, 'MEDIA_URL': MEDIA_URL} + + html_template = render_to_string('relatorios/relatorio_normas_vigencia.html', context) + html_header = render_to_string('relatorios/header_ata.html', header_context) + + pdf_file = make_pdf(base_url=base_url, main_template=html_template, header_template=html_header) + + response = HttpResponse(content_type='application/pdf;') + response['Content-Disposition'] = 'inline; filename=relatorio.pdf' + response['Content-Transfer-Encoding'] = 'binary' + response.write(pdf_file) + + return response + + def relatorio_sessao_plenaria_pdf(request, pk): base_url=request.build_absolute_uri() logger = logging.getLogger(__name__) diff --git a/sapl/templates/relatorios/relatorio_normas_vigencia.html b/sapl/templates/relatorios/relatorio_normas_vigencia.html new file mode 100644 index 000000000..bb47d8fc1 --- /dev/null +++ b/sapl/templates/relatorios/relatorio_normas_vigencia.html @@ -0,0 +1,89 @@ +{% load i18n %} +{% load common_tags %} +{% load static %} + + + + + + + + +

Fim de Prazo de Tramitações

+ + PARÂMETROS DE PESQUISA:
+  Ano: {{ ano }}
+  Vigência: {{ vigencia }}
+ {% if object_list %} +
+ {% if object_list|length > 1 %} +

Foram encontradas {{object_list|length}} normas.

+ {% else %} +

Foi encontrada 1 norma.

+ {% endif %} +
+ + + + + + + + + {% for norma in object_list %} + + + + + {% endfor %} + +
NormaEmenta
+ {{norma.tipo.descricao}} - {{norma.tipo.sigla}} {{norma.numero}}/{{norma.ano}} + {{norma.ementa}}
{{norma.observacao}}
+ {% else %} + + + + + + +
Não foi encontrada nenhuma norma com os parâmetros buscados.
+ {% endif %} +
+

Estatísticas das normas do ano:


+

{{quant_vigente}} vigente(s) / {{quant_nao_vigente}} não vigente(s)

+ \ No newline at end of file