diff --git a/sapl/base/urls.py b/sapl/base/urls.py index 0bed621c9..fbb1e483d 100644 --- a/sapl/base/urls.py +++ b/sapl/base/urls.py @@ -11,7 +11,7 @@ from django.views.generic.base import RedirectView, TemplateView from sapl.base.views import (AutorCrud, ConfirmarEmailView, TipoAutorCrud, get_estatistica, DetailUsuarioView, PesquisarAutorView, RecuperarSenhaEmailView, RecuperarSenhaFinalizadoView, - RecuperarSenhaConfirmaView, RecuperarSenhaCompletoView) + RecuperarSenhaConfirmaView, RecuperarSenhaCompletoView, RelatorioMateriaAnoAssuntoView) from sapl.settings import EMAIL_SEND_USER, MEDIA_URL, LOGOUT_REDIRECT_URL from .apps import AppConfig @@ -86,6 +86,9 @@ urlpatterns = [ url(r'^sistema/relatorios/materia-por-tramitacao$', RelatorioMateriasTramitacaoView.as_view(), name='materia_por_tramitacao'), + url(r'^sistema/relatorios/materia-por-assunto$', + RelatorioMateriaAnoAssuntoView.as_view(), + name='materia_por_ano_assunto'), url(r'^sistema/relatorios/historico-tramitacoes$', RelatorioHistoricoTramitacaoView.as_view(), name='historico_tramitacoes'), diff --git a/sapl/base/views.py b/sapl/base/views.py index 2608ae0b9..093307897 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -15,7 +15,7 @@ from django.contrib.auth.views import (PasswordResetView, PasswordResetConfirmVi from django.core.exceptions import ObjectDoesNotExist, PermissionDenied, ValidationError from django.core.mail import send_mail from django.db import connection -from django.db.models import Count, Q, ProtectedError, Max +from django.db.models import Count, Q, ProtectedError, Max, F from django.http import Http404, HttpResponseRedirect, JsonResponse from django.shortcuts import render, redirect from django.template import TemplateDoesNotExist @@ -42,7 +42,7 @@ from sapl.comissoes.models import Comissao, Reuniao from sapl.crud.base import CrudAux, make_pagination from sapl.materia.models import (Anexada, Autoria, DocumentoAcessorio, MateriaEmTramitacao, MateriaLegislativa, Proposicao, StatusTramitacao, TipoDocumento, TipoMateriaLegislativa, UnidadeTramitacao, - Tramitacao) + MateriaAssunto, Tramitacao) from sapl.norma.models import NormaJuridica, TipoNormaJuridica from sapl.parlamentares.models import ( Filiacao, Legislatura, Mandato, Parlamentar, SessaoLegislativa) @@ -1095,6 +1095,32 @@ class RelatorioMateriasPorAutorView(RelatorioMixin, FilterView): return context +class RelatorioMateriaAnoAssuntoView(ListView): + template_name = 'base/RelatorioMateriasAnoAssunto.html' + + def get_queryset(self): + return MateriaAssunto.objects.all().values( + 'assunto_id', + assunto_materia=F('assunto__assunto'), + ano=F('materia__ano')).annotate( + total=Count('assunto_id')).order_by('-materia__ano', 'assunto_id') + + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['title'] = _('Matérias por Ano e Assunto') + mat = MateriaLegislativa.objects.exclude(id__in= + MateriaAssunto.objects.distinct( + 'materia_id').values_list( + 'materia_id', + flat=True + ).order_by( + 'materia_id' + )).values( + 'ano').annotate(total=Count('ano')).order_by('-ano') + context.update({"materias_sem_assunto": mat}) + return context + + class RelatorioNormasPublicadasMesView(RelatorioMixin, FilterView): model = NormaJuridica filterset_class = RelatorioNormasMesFilterSet diff --git a/sapl/templates/base/RelatorioMateriasAnoAssunto.html b/sapl/templates/base/RelatorioMateriasAnoAssunto.html new file mode 100644 index 000000000..5e9b2b16a --- /dev/null +++ b/sapl/templates/base/RelatorioMateriasAnoAssunto.html @@ -0,0 +1,53 @@ +{% extends "crud/list.html" %} +{% load i18n %} +{% load crispy_forms_tags %} +{% block base_content %} +
+ {% include 'paginacao.html'%} +{% endblock %} \ No newline at end of file diff --git a/sapl/templates/base/relatorios_list.html b/sapl/templates/base/relatorios_list.html index ed1066403..61ec100ca 100644 --- a/sapl/templates/base/relatorios_list.html +++ b/sapl/templates/base/relatorios_list.html @@ -24,6 +24,10 @@