Browse Source

fix(painel): inclui tipos_resultado no bootstrap WebSocket

pull/3840/head
RogerKoala 1 week ago
parent
commit
d1f107c7d7
  1. 43
      sapl/painel/consumers.py

43
sapl/painel/consumers.py

@ -12,16 +12,28 @@ from sapl.sessao.models import SessaoPlenaria, SessaoPresencasView, \
def get_materia_votacao(votacao): def get_materia_votacao(votacao):
if not votacao:
return {
"materia_id": "",
"texto": "",
"ementa": "",
"resultado": {
"resultado_votacao": "",
"resultado": "",
"numero_votos": {},
"votos_parlamentares": [],
},
}
materia = votacao.materia
return { return {
# TOO UGLY! FIX THIS if-else "materia_id": materia.id if materia else "",
"materia_id": votacao.materia.id if votacao and votacao.materia else "", "texto": str(materia) if materia else "",
"texto": str(votacao.materia) if votacao and votacao.materia else "", "ementa": materia.ementa if materia and materia.ementa else "",
"ementa": votacao.materia.ementa if votacao and votacao.materia and votacao.materia.ementa else "",
"resultado": { "resultado": {
"resultado_votacao": votacao.resultado_votacao if votacao and votacao.resultado_votacao else "", "resultado_votacao": votacao.resultado_votacao or "",
"resultado": votacao.resultado if votacao and votacao.resultado else "", "resultado": votacao.resultado or "",
"numero_votos": votacao.numero_votos if votacao and votacao.numero_votos else {}, "numero_votos": votacao.numero_votos or {},
"votos_parlamentares": votacao.votos_parlamentares if votacao and votacao.votos_parlamentares else [], "votos_parlamentares": votacao.votos_parlamentares or [],
}, },
} }
@ -107,6 +119,12 @@ def get_dados_painel(sessao_plenaria_id: int) -> dict:
"elapsed_ms": 5320 "elapsed_ms": 5320
} }
# Tipos de Resultado de Votação (for the resultado dropdown)
from sapl.sessao.models import TipoResultadoVotacao
tipos_resultado = list(
TipoResultadoVotacao.objects.all().values('id', 'nome')
)
dados_sessao = { dados_sessao = {
"type": "data", "type": "data",
"sessao_aberta": sessao.iniciada and not sessao.finalizada, "sessao_aberta": sessao.iniciada and not sessao.finalizada,
@ -126,6 +144,7 @@ def get_dados_painel(sessao_plenaria_id: int) -> dict:
"parlamentares": parlamentares, "parlamentares": parlamentares,
"oradores": oradores, "oradores": oradores,
"materia": get_materia_votacao(materia_votacao), "materia": get_materia_votacao(materia_votacao),
"tipos_resultado": tipos_resultado,
"stopwatch": [stopwatch], # TODO: array of stopwatches "stopwatch": [stopwatch], # TODO: array of stopwatches
} }
@ -193,11 +212,15 @@ class PainelConsumer(AsyncJsonWebsocketConsumer):
return return
await self.send_json({"type": "error", "message": "Misformed message"}) await self.send_json({"type": "error", "message": "Misformed message"})
return return
async def stopwatch_update(self, event): async def stopwatch_update(self, event):
await self.send_json(event) await self.send_json(event)
return return
async def vote_update(self, event):
"""Broadcast vote updates to all connected clients (painel + votacao).
Called automatically by Channels when group_send is invoked with type='vote.update'.
"""
await self.send_json(event)
return
@database_sync_to_async @database_sync_to_async
def user_can_view(self, user_id, controller_id) -> bool: def user_can_view(self, user_id, controller_id) -> bool:
# Replace with your ACL check (ORM must be in a sync wrapper) # Replace with your ACL check (ORM must be in a sync wrapper)

Loading…
Cancel
Save