chore(api): rename schedule models fields
This commit is contained in:
parent
8ceb1419a0
commit
57046e2a9d
8 changed files with 224 additions and 334 deletions
|
@ -2,8 +2,14 @@ from django.db import models
|
|||
|
||||
|
||||
class Schedule(models.Model):
|
||||
starts = models.DateTimeField()
|
||||
ends = models.DateTimeField()
|
||||
starts_at = models.DateTimeField(db_column="starts")
|
||||
ends_at = models.DateTimeField(db_column="ends")
|
||||
|
||||
instance = models.ForeignKey(
|
||||
"schedule.ShowInstance",
|
||||
on_delete=models.DO_NOTHING,
|
||||
)
|
||||
|
||||
file = models.ForeignKey(
|
||||
"storage.File",
|
||||
on_delete=models.DO_NOTHING,
|
||||
|
@ -16,31 +22,60 @@ class Schedule(models.Model):
|
|||
blank=True,
|
||||
null=True,
|
||||
)
|
||||
clip_length = models.DurationField(blank=True, null=True)
|
||||
|
||||
length = models.DurationField(blank=True, null=True, db_column="clip_length")
|
||||
fade_in = models.TimeField(blank=True, null=True)
|
||||
fade_out = models.TimeField(blank=True, null=True)
|
||||
cue_in = models.DurationField()
|
||||
cue_out = models.DurationField()
|
||||
media_item_played = models.BooleanField(blank=True, null=True)
|
||||
instance = models.ForeignKey("schedule.ShowInstance", on_delete=models.DO_NOTHING)
|
||||
playout_status = models.SmallIntegerField()
|
||||
broadcasted = models.SmallIntegerField()
|
||||
|
||||
class PositionStatus(models.IntegerChoices):
|
||||
FILLER = -1, "Filler" # Used to fill a show that already started
|
||||
OUTSIDE = 0, "Outside" # Is outside the show time frame
|
||||
INSIDE = 1, "Inside" # Is inside the show time frame
|
||||
BOUNDARY = 2, "Boundary" # Is at the boundary of the show time frame
|
||||
|
||||
position = models.IntegerField()
|
||||
position_status = models.SmallIntegerField(
|
||||
choices=PositionStatus.choices,
|
||||
default=PositionStatus.INSIDE,
|
||||
db_column="playout_status",
|
||||
)
|
||||
|
||||
# Broadcasted is set to 1 when a live source is not
|
||||
# on. Used for the playout history.
|
||||
broadcasted = models.SmallIntegerField()
|
||||
played = models.BooleanField(
|
||||
blank=True,
|
||||
null=True,
|
||||
db_column="media_item_played",
|
||||
)
|
||||
|
||||
@property
|
||||
def overbooked(self):
|
||||
"""
|
||||
A schedule item is overbooked if it starts after the end of the show
|
||||
instance it is in.
|
||||
|
||||
Related to self.position_status
|
||||
"""
|
||||
return self.starts_at >= self.instance.ends_at
|
||||
|
||||
def get_owner(self):
|
||||
return self.instance.get_owner()
|
||||
|
||||
def get_cueout(self):
|
||||
def get_cue_out(self):
|
||||
"""
|
||||
Returns a scheduled item cueout that is based on the current show instance.
|
||||
Returns a scheduled item cue out that is based on the current show
|
||||
instance.
|
||||
|
||||
Cueout of a specific item can potentially overrun the show that it is
|
||||
scheduled in. In that case, the cueout should be the end of the show.
|
||||
Cue out of a specific item can potentially overrun the show that it is
|
||||
scheduled in. In that case, the cue out should be the end of the show.
|
||||
This prevents the next show having overlapping items playing.
|
||||
|
||||
Cases:
|
||||
- When the schedule ends before the end of the show instance,
|
||||
return the stored cueout.
|
||||
return the stored cue out.
|
||||
|
||||
- When the schedule starts before the end of the show instance
|
||||
and ends after the show instance ends,
|
||||
|
@ -49,13 +84,17 @@ class Schedule(models.Model):
|
|||
- When the schedule starts after the end of the show instance,
|
||||
return the stored cue_out even if the schedule WILL NOT BE PLAYED.
|
||||
"""
|
||||
if self.starts < self.instance.ends and self.instance.ends < self.ends:
|
||||
return self.instance.ends - self.starts
|
||||
if (
|
||||
self.starts_at < self.instance.ends_at
|
||||
and self.instance.ends_at < self.ends_at
|
||||
):
|
||||
return self.instance.ends_at - self.starts_at
|
||||
return self.cue_out
|
||||
|
||||
def get_ends(self):
|
||||
def get_ends_at(self):
|
||||
"""
|
||||
Returns a scheduled item ends that is based on the current show instance.
|
||||
Returns a scheduled item ends that is based on the current show
|
||||
instance.
|
||||
|
||||
End of a specific item can potentially overrun the show that it is
|
||||
scheduled in. In that case, the end should be the end of the show.
|
||||
|
@ -72,17 +111,9 @@ class Schedule(models.Model):
|
|||
- When the schedule starts after the end of the show instance,
|
||||
return the show instance ends.
|
||||
"""
|
||||
if self.instance.ends < self.ends:
|
||||
return self.instance.ends
|
||||
return self.ends
|
||||
|
||||
@property
|
||||
def is_valid(self):
|
||||
"""
|
||||
A schedule item is valid if it starts before the end of the show instance
|
||||
it is in
|
||||
"""
|
||||
return self.starts < self.instance.ends
|
||||
if self.instance.ends_at < self.ends_at:
|
||||
return self.instance.ends_at
|
||||
return self.ends_at
|
||||
|
||||
class Meta:
|
||||
managed = False
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue