kpsul/kfet/open/consumers.py

27 lines
788 B
Python

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...).
"""
async def open_status(self, event):
await self.send_json(event)
async def connect(self):
"""Send current status on connect."""
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))