gestioCOF/kfet/open/consumers.py

27 lines
788 B
Python
Raw Normal View History

from ..decorators import kfet_is_team
from ..utils import DjangoJsonWebsocketConsumer, PermConsumerMixin
from .open import kfet_open
class OpenKfetConsumer(PermConsumerMixin, DjangoJsonWebsocketConsumer):
"""Consumer for K-Fêt Open.
WS groups:
kfet.open.base: Only carries the values visible for all users.
kfet.open.team: Carries all values (raw status...).
"""
2022-06-27 15:34:24 +02:00
async def open_status(self, event):
await self.send_json(event)
2022-06-27 15:34:24 +02:00
async def connect(self):
"""Send current status on connect."""
2022-06-27 15:34:24 +02:00
await super().connect()
group = "team" if kfet_is_team(self.user) else "base"
await self.channel_layer.group_add(f"kfet.open.{group}", self.channel_name)
await self.send_json(kfet_open.export(self.user))