2025-07-26
This commit is contained in:
@@ -18,21 +18,28 @@ class DraftConsumer(AsyncJsonWebsocketConsumer):
|
||||
self.room_group_name = f"draft_{self.draft_session.season.league.slug}_{self.draft_session.season.slug}"
|
||||
|
||||
# Auth check (optional)
|
||||
user = self.scope["user"]
|
||||
if not user.is_authenticated:
|
||||
self.user = self.scope["user"]
|
||||
if not self.user.is_authenticated:
|
||||
await self.close()
|
||||
return
|
||||
|
||||
try:
|
||||
await self.add_draft_participant()
|
||||
except Exception as e:
|
||||
await self.close()
|
||||
return
|
||||
|
||||
await self.channel_layer.group_add(self.room_group_name, self.channel_name)
|
||||
await self.accept()
|
||||
await self.send_json({"type": "connection.accepted", "user": user.username})
|
||||
await self.send_json({"type": "connection.accepted", "user": self.user.username, "budget": self.participant.budget})
|
||||
|
||||
# Notify others (optional)
|
||||
await self.channel_layer.group_send(
|
||||
self.room_group_name,
|
||||
{
|
||||
"type": "user.joined",
|
||||
"user": user.username,
|
||||
"user": self.user.username,
|
||||
"budget": self.participant.budget
|
||||
}
|
||||
)
|
||||
|
||||
@@ -90,7 +97,7 @@ class DraftConsumer(AsyncJsonWebsocketConsumer):
|
||||
|
||||
async def start_draft(self):
|
||||
# Example: shuffle draft order
|
||||
players = await self.get_draft_users()
|
||||
players = await self.get_draft_participants()
|
||||
draft_order = random.sample(players, len(players))
|
||||
|
||||
await self.channel_layer.group_send(
|
||||
@@ -131,10 +138,19 @@ class DraftConsumer(AsyncJsonWebsocketConsumer):
|
||||
# === Example DB Access ===
|
||||
|
||||
@database_sync_to_async
|
||||
def get_draft_users(self):
|
||||
def add_draft_participant(self):
|
||||
self.participant, _ = DraftParticipant.objects.get_or_create(
|
||||
user=self.user,
|
||||
draft=self.draft_session,
|
||||
defaults={
|
||||
"budget":self.draft_session.settings.starting_budget
|
||||
}
|
||||
)
|
||||
|
||||
@database_sync_to_async
|
||||
def get_draft_participants(self):
|
||||
# Replace this with real queryset to fetch users in draft
|
||||
return list(DraftParticipant.objects.select_related('user').filter(draft=self.draft_session).all())
|
||||
return ["alice", "bob", "carol"]
|
||||
|
||||
@database_sync_to_async
|
||||
def get_draft_session(self, draft_session_id_hashed, league_slug, season_slug):
|
||||
|
||||
Reference in New Issue
Block a user