feat: websockets
CI / test (push) Successful in 1m56s
CI / build (push) Successful in 48s

This commit is contained in:
2026-07-31 14:27:50 +02:00
parent 125c9dd186
commit 393b39cacd
13 changed files with 626 additions and 2 deletions
+27
View File
@@ -0,0 +1,27 @@
import json
from channels.generic.websocket import AsyncWebsocketConsumer
from django.utils.html import escape
class EchoConsumer(AsyncWebsocketConsumer):
"""Consumer mínimo para verificar el cableado de Channels + htmx (ver
ws_demo.html). No representa ninguna funcionalidad real todavía."""
async def connect(self):
# Mismo criterio de acceso que BackofficeAccessMixin.
if not self.scope['user'].is_staff:
await self.close()
return
await self.accept()
async def receive(self, text_data):
try:
payload = json.loads(text_data)
except (TypeError, ValueError):
payload = {}
message = escape(payload.get('message', ''))
await self.send(text_data=f'<div id="ws-demo-log" hx-swap-oob="beforeend"><p>Eco: {message}</p></div>')