From 3335f508c423523eff4a4f9f2900e4380c01505a Mon Sep 17 00:00:00 2001 From: Ulysses Lara Date: Wed, 20 Mar 2019 13:34:42 -0300 Subject: [PATCH] Adiciona contagem de materias legislativas, sessoes, parlamentares e normas juridicas (#2640) --- sapl/base/urls.py | 5 +++-- sapl/base/views.py | 13 +++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/sapl/base/urls.py b/sapl/base/urls.py index cc10f81d6..88855cba2 100644 --- a/sapl/base/urls.py +++ b/sapl/base/urls.py @@ -9,7 +9,8 @@ from django.contrib.auth.views import (password_reset, password_reset_complete, from django.views.generic.base import RedirectView, TemplateView from sapl import base -from sapl.base.views import AutorCrud, ConfirmarEmailView, TipoAutorCrud, get_data_ultima_atualizacao +from sapl.base.views import AutorCrud, ConfirmarEmailView, TipoAutorCrud, get_estatistica, get_data_ultima_atualizacao + from sapl.settings import EMAIL_SEND_USER, MEDIA_URL from .apps import AppConfig @@ -193,7 +194,7 @@ urlpatterns = [ ListarLegislaturaInfindavelView.as_view(), name='lista_legislatura_infindavel'), - url(r'^sistema/data_ultima_atualizacao', get_data_ultima_atualizacao), + url(r'^sistema/estatisticas', get_estatistica), # todos os sublinks de sistema devem vir acima deste url(r'^sistema/$', permission_required('base.view_tabelas_auxiliares') diff --git a/sapl/base/views.py b/sapl/base/views.py index 755510456..3723a18be 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -1263,7 +1263,9 @@ def mandato_sem_data_inicio(): return Mandato.objects.filter(data_inicio_mandato__isnull=True).order_by('parlamentar') -def get_data_ultima_atualizacao(request): +def get_estatistica(request): + + json_dict = {} datas = [MateriaLegislativa.objects.all(). order_by('-data_ultima_atualizacao'). @@ -1280,7 +1282,14 @@ def get_data_ultima_atualizacao(request): max_data = max(datas) else: max_data = next(iter([i for i in datas if i is not None]), '') - return JsonResponse({'data_ultima_atualizacao': max_data}) + + json_dict["data_ultima_atualizacao"] = max_data + json_dict["num_materias_legislativas"] = MateriaLegislativa.objects.all().count() + json_dict["num_normas_juridicas "] = NormaJuridica.objects.all().count() + json_dict["num_parlamentares"] = Parlamentar.objects.all().count() + json_dict["num_sessoes_plenarias"] = SessaoPlenaria.objects.all().count() + + return JsonResponse(json_dict) class ListarMandatoSemDataInicioView(PermissionRequiredMixin, ListView):