From babcc49c33205aa6dda4bd8990fa8818b8568f5e Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Mon, 11 Mar 2019 14:39:52 -0300 Subject: [PATCH] Adiciona endpoint para vereficar se SAPL alimentado --- sapl/base/urls.py | 4 +++- sapl/base/views.py | 22 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/sapl/base/urls.py b/sapl/base/urls.py index 1cf489885..cc10f81d6 100644 --- a/sapl/base/urls.py +++ b/sapl/base/urls.py @@ -9,7 +9,7 @@ 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 +from sapl.base.views import AutorCrud, ConfirmarEmailView, TipoAutorCrud, get_data_ultima_atualizacao from sapl.settings import EMAIL_SEND_USER, MEDIA_URL from .apps import AppConfig @@ -193,6 +193,8 @@ urlpatterns = [ ListarLegislaturaInfindavelView.as_view(), name='lista_legislatura_infindavel'), + url(r'^sistema/data_ultima_atualizacao', get_data_ultima_atualizacao), + # todos os sublinks de sistema devem vir acima deste url(r'^sistema/$', permission_required('base.view_tabelas_auxiliares') (TemplateView.as_view(template_name='sistema.html')), diff --git a/sapl/base/views.py b/sapl/base/views.py index 4e24b35b1..f6b34eb51 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -15,8 +15,8 @@ from django.core.mail import send_mail from django.core.urlresolvers import reverse, reverse_lazy from django.db import connection from django.db.models import Count, Q, ProtectedError -from django.http import Http404, HttpResponseRedirect from django.shortcuts import render +from django.http import Http404, HttpResponseRedirect, JsonResponse from django.template import TemplateDoesNotExist from django.template.loader import get_template from django.utils import timezone @@ -1263,6 +1263,26 @@ def mandato_sem_data_inicio(): return Mandato.objects.filter(data_inicio_mandato__isnull=True).order_by('parlamentar') +def get_data_ultima_atualizacao(request): + + 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()] + + max_data = '' + + if datas[0] and datas[1]: + max_data = max(datas) + else: + max_data = next([i for i in datas if i is not None], '') + return JsonResponse({'data_ultima_atualizacao': max_data}) + + class ListarMandatoSemDataInicioView(PermissionRequiredMixin, ListView): model = get_user_model() template_name = 'base/mandato_sem_data_inicio.html'