From dc3b1fd6165d7657a952df18f053507cda2a7925 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Cantu=C3=A1ria?= Date: Wed, 8 Jul 2020 12:04:44 -0300 Subject: [PATCH] =?UTF-8?q?HOT-FIX:=20Corrige=20data=5Fultima=5Fatualizaca?= =?UTF-8?q?o=20para=20estat=C3=ADsticas?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/base/views.py | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/sapl/base/views.py b/sapl/base/views.py index 6a29eb5d1..960e7827c 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -1631,32 +1631,25 @@ def mandato_sem_data_inicio(): def get_estatistica(request): + materias = MateriaLegislativa.objects.all() + normas = NormaJuridica.objects.all() + + datas = [ + materias.order_by('-data_ultima_atualizacao').values_list('data_ultima_atualizacao', flat=True) + .exclude(data_ultima_atualizacao__isnull=True).first(), + normas.order_by('-data_ultima_atualizacao').values_list('data_ultima_atualizacao', flat=True) + .exclude(data_ultima_atualizacao__isnull=True).first() + ] - json_dict = {} - - datas = [MateriaLegislativa.objects.all(). - order_by('-data_ultima_atualizacao'). - values_list('data_ultima_atualizacao', flat=True). - first(), - NormaJuridica.objects.all(). - order_by('-data_ultima_atualizacao'). - values_list('data_ultima_atualizacao', flat=True). - first()] # Retorna [None, None] se inexistem registros - - max_data = '' - - if datas[0] and datas[1]: - max_data = max(datas) - else: - max_data = next(iter([i for i in datas if i is not None]), '') - - 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() + max_data = max(datas) if datas[0] and datas[1] else next(iter([i for i in datas if i is not None]), '') - return JsonResponse(json_dict) + return JsonResponse({ + "data_ultima_atualizacao": max_data, + "num_materias_legislativas": materias.count(), + "num_normas_juridicas ": normas.count(), + "num_parlamentares": Parlamentar.objects.all().count(), + "num_sessoes_plenarias": SessaoPlenaria.objects.all().count() + }) class ListarMandatoSemDataInicioView(PermissionRequiredMixin, ListView):