diff --git a/sapl/painel/tasks.py b/sapl/painel/tasks.py index 2a0571135..a7c3b1649 100644 --- a/sapl/painel/tasks.py +++ b/sapl/painel/tasks.py @@ -1,6 +1,3 @@ -from celery import shared_task -from urllib import request - from channels.layers import get_channel_layer from asgiref.sync import async_to_sync @@ -8,7 +5,7 @@ from sapl.painel import views channel_layer = get_channel_layer() -@shared_task -def get_dados_painel_celery(): - json_data = views.get_dados_painel(786) +def get_dados_painel_final(id): + json_data = views.get_dados_painel(id) + print(json_data) async_to_sync(channel_layer.group_send)('painel', {'type':'send_data', 'message': json_data}) diff --git a/sapl/painel/views.py b/sapl/painel/views.py index 4f05ebdbe..ecb87a517 100644 --- a/sapl/painel/views.py +++ b/sapl/painel/views.py @@ -16,6 +16,7 @@ from django.utils.translation import ugettext_lazy as _ from sapl.base.models import AppConfig as ConfiguracoesAplicacao from sapl.base.models import CasaLegislativa from sapl.crud.base import Crud +from sapl.painel import tasks from sapl.painel.apps import AppConfig from sapl.parlamentares.models import Legislatura, Parlamentar, Votante from sapl.sessao.models import (ExpedienteMateria, OradorExpediente, OrdemDia, @@ -307,7 +308,8 @@ def painel_view(request, pk): @user_passes_test(check_permission) def switch_painel(request): - sessao = SessaoPlenaria.objects.get(id=request.POST['pk_sessao']) + pk = request.POST['pk_sessao'] + sessao = SessaoPlenaria.objects.get(id=pk) switch = json.loads(request.POST['aberto']) if switch: @@ -316,6 +318,7 @@ def switch_painel(request): sessao.painel_aberto = False sessao.save() + tasks.get_dados_painel_final(pk) return JsonResponse({}) @@ -349,16 +352,21 @@ def cronometro_painel(request): def get_cronometro_status(request, name): + pk = request.POST['pk_sessao'] + sessao = SessaoPlenaria.objects.get(id=pk) logger = logging.getLogger(__name__) username = request.user.username try: logger.debug("user=" + username + ". Tentando obter cronometro.") cronometro = request.session[name] + sessao.status_cronometro = cronometro except KeyError as e: logger.error("user=" + username + ". Erro ao obter cronometro. Retornado como vazio. " + str(e)) cronometro = '' - return cronometro + sessao.save() + tasks.get_dados_painel_final(pk) + return JsonResponse({}) def get_cronometro_value(name): @@ -582,7 +590,7 @@ def get_dados_painel(pk): 'sessao_solene': sessao.tipo.nome == "Solene", 'sessao_finalizada': sessao.finalizada, 'tema_solene': sessao.tema_solene, - #'status_cronometro_discurso': get_cronometro_status(request, 'discurso'), + 'status_cronometro': sessao.status_cronometro, 'cronometro_aparte': get_cronometro_value('aparte'), 'cronometro_discurso': get_cronometro_value('discurso'), 'cronometro_ordem': get_cronometro_value('ordem'), diff --git a/sapl/sessao/models.py b/sapl/sessao/models.py index 47019abdb..559b6d262 100644 --- a/sapl/sessao/models.py +++ b/sapl/sessao/models.py @@ -157,6 +157,10 @@ class SessaoPlenaria(models.Model): painel_aberto = models.BooleanField(blank=True, default=False, verbose_name=_('Painel está aberto?')) + status_cronometro = models.CharField( + max_length=1, + verbose_name=_('Status do cronômetro painel'), + default='S') tipo = models.ForeignKey(TipoSessaoPlenaria, on_delete=models.PROTECT, verbose_name=_('Tipo'))