From 7e1554a03ee15b1d7d68c470cd72d84cab26648c Mon Sep 17 00:00:00 2001 From: Cesar Carvalho Date: Tue, 18 Dec 2018 15:39:57 -0200 Subject: [PATCH] correcoes e adicao de opcao no configuracao de aplicacao --- sapl/base/forms.py | 3 +- ...28_appconfig_estatisticas_acesso_normas.py | 20 ++++++ sapl/base/models.py | 5 ++ sapl/base/urls.py | 7 +- sapl/base/views.py | 18 +++++ sapl/norma/views.py | 12 ++-- .../base/EstatisticasAcessoNormas_filter.html | 71 +++++++++++-------- .../base/RelatorioNormaMes_filter.html | 2 +- .../base/RelatorioNormasVigencia_filter.html | 2 +- sapl/templates/base/layouts.yaml | 6 ++ sapl/templates/base/relatorios_list.html | 10 +-- 11 files changed, 111 insertions(+), 45 deletions(-) create mode 100644 sapl/base/migrations/0028_appconfig_estatisticas_acesso_normas.py diff --git a/sapl/base/forms.py b/sapl/base/forms.py index fbd5f35e1..4b8be29bf 100644 --- a/sapl/base/forms.py +++ b/sapl/base/forms.py @@ -1140,7 +1140,8 @@ class ConfiguracoesAppForm(ModelForm): 'cronometro_consideracoes', 'mostrar_brasao_painel', 'receber_recibo_proposicao', - 'assinatura_ata'] + 'assinatura_ata', + 'estatisticas_acesso_normas'] def __init__(self, *args, **kwargs): super(ConfiguracoesAppForm, self).__init__(*args, **kwargs) diff --git a/sapl/base/migrations/0028_appconfig_estatisticas_acesso_normas.py b/sapl/base/migrations/0028_appconfig_estatisticas_acesso_normas.py new file mode 100644 index 000000000..7a4af06de --- /dev/null +++ b/sapl/base/migrations/0028_appconfig_estatisticas_acesso_normas.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.8 on 2018-12-18 17:03 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('base', '0027_appconfig_relatorios_atos'), + ] + + operations = [ + migrations.AddField( + model_name='appconfig', + name='estatisticas_acesso_normas', + field=models.CharField(choices=[('S', 'Sim'), ('N', 'Não')], default='N', max_length=1, verbose_name='Estatísticas de acesso a normas'), + ), + ] diff --git a/sapl/base/models.py b/sapl/base/models.py index a426d9170..2f42dc8ae 100644 --- a/sapl/base/models.py +++ b/sapl/base/models.py @@ -92,6 +92,11 @@ class AppConfig(models.Model): verbose_name=_('Relatórios de atos acessados'), choices=RELATORIO_ATOS_ACESSADOS, default='N') + estatisticas_acesso_normas = models.CharField( + max_length=1, + verbose_name=_('Estatísticas de acesso a normas'), + choices=RELATORIO_ATOS_ACESSADOS, default='N') + sequencia_numeracao = models.CharField( max_length=1, verbose_name=_('Sequência de numeração'), diff --git a/sapl/base/urls.py b/sapl/base/urls.py index 1abfa6a14..ae4add258 100644 --- a/sapl/base/urls.py +++ b/sapl/base/urls.py @@ -26,7 +26,8 @@ from .views import (AlterarSenha, AppConfigCrud, CasaLegislativaCrud, RelatorioReuniaoView, SaplSearchView, RelatorioNormasPublicadasMesView, RelatorioNormasVigenciaView, - EstatisticasAcessoNormas) + EstatisticasAcessoNormas, + RelatoriosListView) app_name = AppConfig.name @@ -87,8 +88,8 @@ urlpatterns = [ url(r'^sistema/app-config/', include(AppConfigCrud.get_urls())), # TODO mover estas telas para a app 'relatorios' - url(r'^sistema/relatorios/$', TemplateView.as_view( - template_name='base/relatorios_list.html'), name='relatorios_list'), + url(r'^sistema/relatorios/$', + RelatoriosListView.as_view(), name='relatorios_list'), url(r'^sistema/relatorios/materia-por-autor$', RelatorioMateriasPorAutorView.as_view(), name='materia_por_autor'), url(r'^sistema/relatorios/relatorio-por-mes$', diff --git a/sapl/base/views.py b/sapl/base/views.py index 37883a65c..45f4ec2f5 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -280,6 +280,20 @@ class AutorCrud(CrudAux): return url_reverse +class RelatoriosListView(TemplateView): + template_name='base/relatorios_list.html' + + def get_context_data(self, **kwargs): + context = super(TemplateView, self).get_context_data(**kwargs) + + estatisticas_acesso_normas = AppConfig.objects.first().estatisticas_acesso_normas + if estatisticas_acesso_normas == 'S': + context['estatisticas_acesso_normas'] = True + else: + context['estatisticas_acesso_normas'] = False + + return context + class RelatorioAtasView(FilterView): model = SessaoPlenaria filterset_class = RelatorioAtasFilterSet @@ -874,12 +888,16 @@ class EstatisticasAcessoNormas(FilterView): norma_est = [norma, len(NormaEstatisticas.objects.filter(norma=norma))] normas_mes[meses[norma.data.month]].append(norma_est) + meses_sem_acesso = [] # Ordena por acesso e limita em 5 for n in normas_mes: sorted_by_value = sorted(normas_mes[n], key=lambda kv: kv[1], reverse=True) normas_mes[n] = sorted_by_value[0:5] + if all(v[1]==0 for v in normas_mes[n]): + meses_sem_acesso.append(n) context['normas_mes'] = normas_mes + context['meses_sem_acesso'] = meses_sem_acesso quant_normas_mes = {} for key in normas_mes.keys(): diff --git a/sapl/norma/views.py b/sapl/norma/views.py index 89aaaee85..f7800c42f 100644 --- a/sapl/norma/views.py +++ b/sapl/norma/views.py @@ -1,6 +1,8 @@ -import re import logging +import re +import sapl +import weasyprint from django.contrib.auth.mixins import PermissionRequiredMixin from django.core.exceptions import ObjectDoesNotExist @@ -13,8 +15,6 @@ from django.views.generic import TemplateView, UpdateView from django.views.generic.base import RedirectView from django.views.generic.edit import FormView from django_filters.views import FilterView -import weasyprint -import sapl from sapl.base.models import AppConfig from sapl.compilacao.views import IntegracaoTaView from sapl.crud.base import (RP_DETAIL, RP_LIST, Crud, CrudAux, @@ -191,8 +191,10 @@ class NormaCrud(Crud): class DetailView(Crud.DetailView): def get(self, request, *args, **kwargs): - NormaEstatisticas.objects.create(usuario=str(self.request.user), - norma_id=kwargs['pk']) + estatisticas_acesso_normas = AppConfig.objects.first().estatisticas_acesso_normas + if estatisticas_acesso_normas == 'S': + NormaEstatisticas.objects.create(usuario=str(self.request.user), + norma_id=kwargs['pk']) return super().get(request, *args, **kwargs) diff --git a/sapl/templates/base/EstatisticasAcessoNormas_filter.html b/sapl/templates/base/EstatisticasAcessoNormas_filter.html index fb4914fb0..a8246e22d 100644 --- a/sapl/templates/base/EstatisticasAcessoNormas_filter.html +++ b/sapl/templates/base/EstatisticasAcessoNormas_filter.html @@ -17,37 +17,48 @@ {% if normas_mes|length == 0 %}

{% trans 'Não foi encontrada nenhuma norma com os parâmetros buscados.'%}

- {% endif %} - {% for mes, normas in normas_mes.items %} -
- - - - - - -

Mês: {{ mes }}

- - - - - - - - - - {% for n in normas %} + {% elif normas_mes|length == meses_sem_acesso|length %} +
+

{% trans 'Nenhuma norma teve acesso neste ano.'%}

+ {% else %} + {% for mes, normas in normas_mes.items %} +
+
MatériaNormaAcessos
+ - - - + - {% endfor %} - -
- {{n.0.tipo.descricao}} - {{n.0.tipo.sigla}} {{n.0.numero}}/{{n.0.ano}} - {{n.0.ementa}}
{{n.0.observacao}}
{{n.1}}

Mês: {{ mes }}

-
- {% endfor %} + + + {% if not mes in meses_sem_acesso %} + + + + + + + + + + {% for n in normas %} + {% if n.1 > 0 %} + + + + + + {% endif %} + {% endfor %} + +
NormaEmentaAcessos
+ {{n.0.tipo.descricao}} - {{n.0.tipo.sigla}} {{n.0.numero}}/{{n.0.ano}} + {{n.0.ementa}}
{{n.0.observacao}}
{{n.1}}
+ {% else %} +

{% trans 'Nenhuma norma deste mês teve acessos.'%}

+

+ {% endif %} + + {% endfor %} + {% endif %} {% endif %} {% endblock base_content %} diff --git a/sapl/templates/base/RelatorioNormaMes_filter.html b/sapl/templates/base/RelatorioNormaMes_filter.html index b035a20dd..d4f8d5b30 100644 --- a/sapl/templates/base/RelatorioNormaMes_filter.html +++ b/sapl/templates/base/RelatorioNormaMes_filter.html @@ -46,8 +46,8 @@ - + diff --git a/sapl/templates/base/RelatorioNormasVigencia_filter.html b/sapl/templates/base/RelatorioNormasVigencia_filter.html index e88916a3c..6412b5b20 100644 --- a/sapl/templates/base/RelatorioNormasVigencia_filter.html +++ b/sapl/templates/base/RelatorioNormasVigencia_filter.html @@ -26,8 +26,8 @@
Matéria NormaEmenta
- + diff --git a/sapl/templates/base/layouts.yaml b/sapl/templates/base/layouts.yaml index ef1e53d2a..36597ad44 100644 --- a/sapl/templates/base/layouts.yaml +++ b/sapl/templates/base/layouts.yaml @@ -23,6 +23,12 @@ AppConfig: {% trans 'Textos Articulados' %}: - texto_articulado_proposicao texto_articulado_materia texto_articulado_norma + {% trans 'Relatórios' %}: + - relatorios_atos + + {% trans 'Estatísticas de acesso' %}: + - estatisticas_acesso_normas + {% trans 'Assinaturas' %}: - assinatura_ata diff --git a/sapl/templates/base/relatorios_list.html b/sapl/templates/base/relatorios_list.html index 9f42a78f6..87f8933be 100644 --- a/sapl/templates/base/relatorios_list.html +++ b/sapl/templates/base/relatorios_list.html @@ -56,10 +56,12 @@ - - - - + {% if estatisticas_acesso_normas %} + + + + + {% endif %}
Matéria NormaEmenta
Normas por vigência Normas vigentes ou não vigentes.
Estatísticas de acesso de Normas. Normas por acesso.
Estatísticas de acesso de Normas. Normas por acesso.