From 97c10ec123aebdfee5680409cf9fab2a2a8bad53 Mon Sep 17 00:00:00 2001 From: Edward Oliveira Date: Sun, 30 Jul 2023 15:47:42 -0700 Subject: [PATCH] [WIP] Tela de controle de visibilidade de relatorio --- sapl/relatorios/__init__.py | 2 +- sapl/relatorios/forms.py | 12 ++++++++- sapl/relatorios/migrations/0001_initial.py | 29 +++++++++++++++++++++ sapl/relatorios/migrations/__init__.py | 0 sapl/relatorios/models.py | 25 ++++++++++++++++-- sapl/relatorios/urls.py | 7 ++--- sapl/relatorios/views.py | 20 +++++++++++--- sapl/settings.py | 1 + sapl/templates/menu_tabelas_auxiliares.yaml | 3 +++ sapl/templates/relatorios/configuracao.html | 9 +++++++ sapl/templates/sistema.html | 4 +-- 11 files changed, 99 insertions(+), 13 deletions(-) create mode 100644 sapl/relatorios/migrations/0001_initial.py create mode 100644 sapl/relatorios/migrations/__init__.py create mode 100644 sapl/templates/relatorios/configuracao.html diff --git a/sapl/relatorios/__init__.py b/sapl/relatorios/__init__.py index 6f40d706f..41fb03f7e 100644 --- a/sapl/relatorios/__init__.py +++ b/sapl/relatorios/__init__.py @@ -1 +1 @@ -default_app_config = 'relatorios.apps.AppConfig' +default_app_config = 'sapl.relatorios.apps.AppConfig' diff --git a/sapl/relatorios/forms.py b/sapl/relatorios/forms.py index 8ac7eca02..113d82af9 100644 --- a/sapl/relatorios/forms.py +++ b/sapl/relatorios/forms.py @@ -309,7 +309,8 @@ class RelatorioDataFimPrazoTramitacaoFilterSet(django_filters.FilterSet): @property def qs(self): parent = super(RelatorioDataFimPrazoTramitacaoFilterSet, self).qs - return parent.distinct().prefetch_related('materia__tipo').order_by('tramitacao__data_fim_prazo', 'materia__tipo', 'materia__numero') + return parent.distinct().prefetch_related('materia__tipo').order_by('tramitacao__data_fim_prazo', + 'materia__tipo', 'materia__numero') class Meta(FilterOverridesMetaMixin): model = MateriaEmTramitacao @@ -774,3 +775,12 @@ class RelatorioNormasVigenciaFilterSet(django_filters.FilterSet): @property def qs(self): return qs_override_django_filter(self) + + +class ConfiguracaoRelatorioForm(forms.Form): + nome = forms.CharField(required=True, + label="Nome", + max_length=100) + url = forms.CharField(required=True, + label="URL", + max_length=200) diff --git a/sapl/relatorios/migrations/0001_initial.py b/sapl/relatorios/migrations/0001_initial.py new file mode 100644 index 000000000..45cd87dd1 --- /dev/null +++ b/sapl/relatorios/migrations/0001_initial.py @@ -0,0 +1,29 @@ +# Generated by Django 2.2.28 on 2023-07-25 00:53 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='RelatorioConfig', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('nome', models.CharField(max_length=100, verbose_name='Nome')), + ('url', models.CharField(max_length=200, verbose_name='URL')), + ('publico', models.BooleanField(choices=[(True, 'Sim'), (False, 'Não')], db_index=True, default=True, verbose_name='Público')), + ('privado', models.BooleanField(choices=[(True, 'Sim'), (False, 'Não')], db_index=True, default=True, verbose_name='Público')), + ], + options={ + 'verbose_name': 'Configuração de Relatório', + 'verbose_name_plural': 'Configurações de Relatórios', + 'ordering': ['nome'], + }, + ), + ] diff --git a/sapl/relatorios/migrations/__init__.py b/sapl/relatorios/migrations/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/sapl/relatorios/models.py b/sapl/relatorios/models.py index 0b4331b36..4554b73f1 100644 --- a/sapl/relatorios/models.py +++ b/sapl/relatorios/models.py @@ -1,3 +1,24 @@ -# from django.db import models +from django.db import models +from django.utils.translation import ugettext_lazy as _ +from sapl.utils import YES_NO_CHOICES -# Create your models here. + +class RelatorioConfig(models.Model): + nome = models.CharField(max_length=100, verbose_name=_('Nome')) + url = models.CharField(max_length=200, verbose_name=_('URL')) + publico = models.BooleanField(db_index=True, + default=True, + choices=YES_NO_CHOICES, + verbose_name=_('Público')) + privado = models.BooleanField(db_index=True, + default=True, + choices=YES_NO_CHOICES, + verbose_name=_('Público')) + + class Meta: + verbose_name = _('Configuração de Relatório') + verbose_name_plural = _('Configurações de Relatórios') + ordering = ['nome'] + + def __str__(self): + return f"{self.nome} - {self.url}" diff --git a/sapl/relatorios/urls.py b/sapl/relatorios/urls.py index b27bfc55a..ac2bd1eed 100644 --- a/sapl/relatorios/urls.py +++ b/sapl/relatorios/urls.py @@ -1,4 +1,4 @@ -from django.conf.urls import url +from django.conf.urls import include, url from .apps import AppConfig from .views import (relatorio_capa_processo, @@ -11,7 +11,7 @@ from .views import (relatorio_capa_processo, RelatorioMateriasTramitacaoView, RelatorioMateriaAnoAssuntoView, RelatorioHistoricoTramitacaoView, RelatorioDataFimPrazoTramitacaoView, RelatorioPresencaSessaoView, RelatorioAtasView, RelatorioReuniaoView, RelatorioAudienciaView, RelatorioHistoricoTramitacaoAdmView, - RelatorioDocumentosAcessoriosView, RelatorioNormasPorAutorView) + RelatorioDocumentosAcessoriosView, RelatorioNormasPorAutorView, RelatorioConfigView) from ..base.views import EstatisticasAcessoNormas app_name = AppConfig.name @@ -51,7 +51,8 @@ urlpatterns = [ url(r'^relatorios/(?P\d+)/materia-tramitacao$', relatorio_materia_tramitacao, name='relatorio_materia_tramitacao'), - # TODO mover estas telas para a app 'relatorios' + url(r'^sistema/relatorios/configuracao/', + RelatorioConfigView.as_view(), name='relatorio_config'), url(r'^sistema/relatorios/$', RelatoriosListView.as_view(), name='relatorios_list'), url(r'^sistema/relatorios/materia-por-autor$', diff --git a/sapl/relatorios/views.py b/sapl/relatorios/views.py index ccc88b86c..0469153d7 100755 --- a/sapl/relatorios/views.py +++ b/sapl/relatorios/views.py @@ -5,13 +5,16 @@ import re from datetime import datetime as dt, datetime import unidecode +from django.contrib.auth.mixins import PermissionRequiredMixin +from django.views.generic.detail import DetailView +from django.views.generic.edit import FormMixin from django.core.exceptions import ObjectDoesNotExist from django.db.models import Count, Q, F from django.http import Http404, HttpResponse from django.template.loader import render_to_string from django.utils import timezone from django.utils.translation import ugettext_lazy as _ -from django.views.generic import TemplateView, ListView +from django.views.generic import TemplateView, ListView, FormView from django_filters.views import FilterView from weasyprint import HTML, CSS @@ -31,7 +34,8 @@ from sapl.relatorios.forms import RelatorioNormasPorAutorFilterSet, RelatorioHis RelatorioNormasVigenciaFilterSet, RelatorioNormasMesFilterSet, RelatorioMateriasPorAutorFilterSet, \ RelatorioMateriasPorAnoAutorTipoFilterSet, RelatorioMateriasTramitacaoFilterSet, RelatorioAudienciaFilterSet, \ RelatorioReuniaoFilterSet, RelatorioDataFimPrazoTramitacaoFilterSet, RelatorioHistoricoTramitacaoFilterSet, \ - RelatorioPresencaSessaoFilterSet, RelatorioAtasFilterSet, RelatorioDocumentosAcessoriosFilterSet + RelatorioPresencaSessaoFilterSet, RelatorioAtasFilterSet, RelatorioDocumentosAcessoriosFilterSet, \ + ConfiguracaoRelatorioForm from sapl.sessao.models import (ExpedienteMateria, ExpedienteSessao, IntegranteMesa, JustificativaAusencia, Orador, OradorExpediente, @@ -51,12 +55,14 @@ from sapl.settings import MEDIA_URL from sapl.settings import STATIC_ROOT from sapl.utils import LISTA_DE_UFS, TrocaTag, filiacao_data, create_barcode, show_results_filter_set, \ num_materias_por_tipo, parlamentares_ativos +from .models import RelatorioConfig from .templates import (pdf_capa_processo_gerar, pdf_documento_administrativo_gerar, pdf_espelho_gerar, pdf_etiqueta_protocolo_gerar, pdf_materia_gerar, pdf_ordem_dia_gerar, pdf_pauta_sessao_gerar, pdf_protocolo_gerar, pdf_sessao_plenaria_gerar) -from sapl.crud.base import make_pagination +from sapl.crud.base import make_pagination, Crud +from ..rules import RP_LIST, RP_DETAIL def get_kwargs_params(request, fields): @@ -2727,3 +2733,11 @@ class RelatorioNormasPorAutorView(RelatorioMixin, FilterView): ' - ' + self.request.GET['data_1']) return context + + +class RelatorioConfigView(FormMixin, DetailView): + form_class = ConfiguracaoRelatorioForm + template_name = 'relatorios/configuracao.html' + permission_required = ('base.list_appconfig',) + logger = logging.getLogger(__name__) + diff --git a/sapl/settings.py b/sapl/settings.py index 5517e32f1..41165480c 100644 --- a/sapl/settings.py +++ b/sapl/settings.py @@ -63,6 +63,7 @@ SAPL_APPS = ( 'sapl.protocoloadm', 'sapl.compilacao', 'sapl.api', + 'sapl.relatorios', 'sapl.rules' ) diff --git a/sapl/templates/menu_tabelas_auxiliares.yaml b/sapl/templates/menu_tabelas_auxiliares.yaml index cf64082a1..99669289a 100644 --- a/sapl/templates/menu_tabelas_auxiliares.yaml +++ b/sapl/templates/menu_tabelas_auxiliares.yaml @@ -14,6 +14,9 @@ - title: {% trans 'Autores' %} url: sapl.base:autor_list css_class: btn btn-link + - title: {% trans 'Configuração de Relatórios' %} + url: sapl.relatorios:relatorio_config + css_class: btn btn-link {% if not sapl_as_sapn%} - title: {% trans 'Módulo Parlamentares' %} css_class: head_title diff --git a/sapl/templates/relatorios/configuracao.html b/sapl/templates/relatorios/configuracao.html new file mode 100644 index 000000000..036624e04 --- /dev/null +++ b/sapl/templates/relatorios/configuracao.html @@ -0,0 +1,9 @@ +{% extends "crud/detail.html" %} +{% load i18n %} +{% load common_tags %} + +{% block actions %}{% endblock %} + +{% block detail_content %} + Teste +{% endblock detail_content %} diff --git a/sapl/templates/sistema.html b/sapl/templates/sistema.html index a3e56780e..2a298a86f 100644 --- a/sapl/templates/sistema.html +++ b/sapl/templates/sistema.html @@ -83,8 +83,8 @@ -
+

Módulo Textos Articulados

- -

Módulo Sessão Plenária