Integrate draft session support with phase handling and real-time updates
- Added user authentication UI in the base template for navbar. - Expanded `league.dj.html` to include a new "Draft Sessions" tab showing active drafts. - Refactored Django views and models to support `DraftSession` with participants and movies. - Replaced deprecated models like `DraftParticipant` and `DraftMoviePool` with a new schema using `DraftSessionParticipant`. - Introduced WebSocket consumers (`DraftAdminConsumer`, `DraftParticipantConsumer`) with structured phase logic and caching. - Added `DraftStateManager` for managing draft state in Django cache. - Created frontend UI components in React for draft admin and participants, including phase control and WebSocket message logging. - Updated SCSS styles for improved UI structure and messaging area.
This commit is contained in:
@@ -1,38 +1,53 @@
|
||||
from django.db.models import ForeignKey, Model, IntegerField, BooleanField, CASCADE, PROTECT, OneToOneField
|
||||
from django.db.models import (
|
||||
ForeignKey,
|
||||
Model,
|
||||
IntegerField,
|
||||
BooleanField,
|
||||
CASCADE,
|
||||
PROTECT,
|
||||
OneToOneField,
|
||||
ManyToManyField,
|
||||
)
|
||||
from boxofficefantasy.models import Season, User, Movie
|
||||
from boxofficefantasy_project.utils import encode_id, decode_id
|
||||
|
||||
|
||||
# Create your models here.
|
||||
class DraftSession(Model):
|
||||
season = ForeignKey(Season, on_delete=CASCADE)
|
||||
is_active = BooleanField()
|
||||
current_nomination_index = IntegerField()
|
||||
|
||||
participants: ManyToManyField = ManyToManyField(
|
||||
User, through="DraftSessionParticipant", related_name="participant_entries"
|
||||
)
|
||||
movies: ManyToManyField = ManyToManyField(Movie, related_name="draft_sessions", blank=True)
|
||||
|
||||
@property
|
||||
def hashed_id(self):
|
||||
if not self.pk: return ""
|
||||
def hashid(self):
|
||||
if not self.pk:
|
||||
return ""
|
||||
return f"{encode_id(self.pk)}"
|
||||
|
||||
|
||||
@classmethod
|
||||
def decode_id(cls, hashed_id:str) -> id:
|
||||
def decode_id(cls, hashed_id: str) -> id:
|
||||
return decode_id(hashed_id)
|
||||
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
is_new = self.pk is None
|
||||
super().save(*args, **kwargs)
|
||||
if is_new and not hasattr(self, 'settings'):
|
||||
if is_new and not hasattr(self, "settings"):
|
||||
DraftSessionSettings.objects.create(draft_session=self)
|
||||
|
||||
|
||||
class DraftParticipant(Model):
|
||||
draft = ForeignKey(DraftSession, on_delete=CASCADE)
|
||||
class DraftSessionParticipant(Model):
|
||||
draft_session = ForeignKey(DraftSession, on_delete=CASCADE, blank=True)
|
||||
user = ForeignKey(User, on_delete=CASCADE)
|
||||
budget = IntegerField()
|
||||
|
||||
class DraftMoviePool(Model):
|
||||
draft = ForeignKey(DraftSession, on_delete=CASCADE)
|
||||
movie = ForeignKey(Movie, on_delete=CASCADE)
|
||||
nominated = BooleanField()
|
||||
class Meta:
|
||||
unique_together = [("draft_session", "user")]
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.user} in {self.draft_session}"
|
||||
|
||||
|
||||
class DraftPick(Model):
|
||||
draft = ForeignKey(DraftSession, on_delete=CASCADE)
|
||||
@@ -41,16 +56,15 @@ class DraftPick(Model):
|
||||
bid_amount = IntegerField()
|
||||
nomination_order = IntegerField()
|
||||
|
||||
|
||||
class DraftSessionSettings(Model):
|
||||
starting_budget = IntegerField(default=100)
|
||||
draft_session = OneToOneField(
|
||||
DraftSession,
|
||||
on_delete=CASCADE,
|
||||
related_name="settings"
|
||||
DraftSession, on_delete=CASCADE, related_name="settings"
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f"Settings for {self.draft_session}"
|
||||
|
||||
|
||||
class Meta:
|
||||
verbose_name_plural = "Draft session settings"
|
||||
verbose_name_plural = "Draft session settings"
|
||||
|
||||
Reference in New Issue
Block a user