feat(api): split api into multiple apps (#1626)

Fixes #1622

- split the api into 4 apps: core, history, schedule, storage
- exploded the settings into testing/prod
This commit is contained in:
Jonas L 2022-04-04 14:38:50 +02:00 committed by GitHub
parent 87d2da9d84
commit fce988aef1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
120 changed files with 1499 additions and 1078 deletions

View file

@ -0,0 +1,6 @@
from .playlist import Playlist, PlaylistContent
from .podcast import ImportedPodcast, Podcast, PodcastEpisode, StationPodcast
from .schedule import Schedule
from .show import Show, ShowDays, ShowHost, ShowInstance, ShowRebroadcast
from .smart_block import SmartBlock, SmartBlockContent, SmartBlockCriteria
from .webstream import Webstream, WebstreamMetadata

View file

@ -0,0 +1,39 @@
from django.db import models
class Playlist(models.Model):
name = models.CharField(max_length=255)
mtime = models.DateTimeField(blank=True, null=True)
utime = models.DateTimeField(blank=True, null=True)
creator = models.ForeignKey("core.User", models.DO_NOTHING, blank=True, null=True)
description = models.CharField(max_length=512, blank=True, null=True)
length = models.DurationField(blank=True, null=True)
def get_owner(self):
return self.creator
class Meta:
managed = False
db_table = "cc_playlist"
class PlaylistContent(models.Model):
playlist = models.ForeignKey("Playlist", models.DO_NOTHING, blank=True, null=True)
file = models.ForeignKey("storage.File", models.DO_NOTHING, blank=True, null=True)
block = models.ForeignKey("SmartBlock", models.DO_NOTHING, blank=True, null=True)
stream_id = models.IntegerField(blank=True, null=True)
type = models.SmallIntegerField()
position = models.IntegerField(blank=True, null=True)
trackoffset = models.FloatField()
cliplength = models.DurationField(blank=True, null=True)
cuein = models.DurationField(blank=True, null=True)
cueout = models.DurationField(blank=True, null=True)
fadein = models.TimeField(blank=True, null=True)
fadeout = models.TimeField(blank=True, null=True)
def get_owner(self):
return self.playlist.owner
class Meta:
managed = False
db_table = "cc_playlistcontents"

View file

@ -0,0 +1,83 @@
from django.db import models
class Podcast(models.Model):
url = models.CharField(max_length=4096)
title = models.CharField(max_length=4096)
creator = models.CharField(max_length=4096, blank=True, null=True)
description = models.CharField(max_length=4096, blank=True, null=True)
language = models.CharField(max_length=4096, blank=True, null=True)
copyright = models.CharField(max_length=4096, blank=True, null=True)
link = models.CharField(max_length=4096, blank=True, null=True)
itunes_author = models.CharField(max_length=4096, blank=True, null=True)
itunes_keywords = models.CharField(max_length=4096, blank=True, null=True)
itunes_summary = models.CharField(max_length=4096, blank=True, null=True)
itunes_subtitle = models.CharField(max_length=4096, blank=True, null=True)
itunes_category = models.CharField(max_length=4096, blank=True, null=True)
itunes_explicit = models.CharField(max_length=4096, blank=True, null=True)
owner = models.ForeignKey(
"core.User", models.DO_NOTHING, db_column="owner", blank=True, null=True
)
def get_owner(self):
return self.owner
class Meta:
managed = False
db_table = "podcast"
permissions = [
("change_own_podcast", "Change the podcasts where they are the owner"),
("delete_own_podcast", "Delete the podcasts where they are the owner"),
]
class PodcastEpisode(models.Model):
file = models.ForeignKey("storage.File", models.DO_NOTHING, blank=True, null=True)
podcast = models.ForeignKey("Podcast", models.DO_NOTHING)
publication_date = models.DateTimeField()
download_url = models.CharField(max_length=4096)
episode_guid = models.CharField(max_length=4096)
episode_title = models.CharField(max_length=4096)
episode_description = models.TextField()
def get_owner(self):
return self.podcast.owner
class Meta:
managed = False
db_table = "podcast_episodes"
permissions = [
(
"change_own_podcastepisode",
"Change the episodes of podcasts where they are the owner",
),
(
"delete_own_podcastepisode",
"Delete the episodes of podcasts where they are the owner",
),
]
class StationPodcast(models.Model):
podcast = models.ForeignKey("Podcast", models.DO_NOTHING)
def get_owner(self):
return self.podcast.owner
class Meta:
managed = False
db_table = "station_podcast"
class ImportedPodcast(models.Model):
auto_ingest = models.BooleanField()
auto_ingest_timestamp = models.DateTimeField(blank=True, null=True)
album_override = models.BooleanField()
podcast = models.ForeignKey("Podcast", models.DO_NOTHING)
def get_owner(self):
return self.podcast.owner
class Meta:
managed = False
db_table = "imported_podcast"

View file

@ -0,0 +1,83 @@
from django.db import models
class Schedule(models.Model):
starts = models.DateTimeField()
ends = models.DateTimeField()
file = models.ForeignKey("storage.File", models.DO_NOTHING, blank=True, null=True)
stream = models.ForeignKey("Webstream", models.DO_NOTHING, blank=True, null=True)
clip_length = models.DurationField(blank=True, null=True)
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("ShowInstance", models.DO_NOTHING)
playout_status = models.SmallIntegerField()
broadcasted = models.SmallIntegerField()
position = models.IntegerField()
def get_owner(self):
return self.instance.get_owner()
def get_cueout(self):
"""
Returns a scheduled item cueout 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.
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.
- When the schedule starts before the end of the show instance
and ends after the show instance ends,
return timedelta between schedule starts and show instance ends.
- 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
return self.cue_out
def get_ends(self):
"""
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.
This prevents the next show having overlapping items playing.
Cases:
- When the schedule ends before the end of the show instance,
return the scheduled item ends.
- When the schedule starts before the end of the show instance
and ends after the show instance ends,
return the show instance ends.
- 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
class Meta:
managed = False
db_table = "cc_schedule"
permissions = [
("change_own_schedule", "Change the content on their shows"),
("delete_own_schedule", "Delete the content on their shows"),
]

View file

@ -0,0 +1,94 @@
from django.db import models
class Show(models.Model):
name = models.CharField(max_length=255)
url = models.CharField(max_length=255, blank=True, null=True)
genre = models.CharField(max_length=255, blank=True, null=True)
description = models.CharField(max_length=8192, blank=True, null=True)
color = models.CharField(max_length=6, blank=True, null=True)
background_color = models.CharField(max_length=6, blank=True, null=True)
live_stream_using_airtime_auth = models.BooleanField(blank=True, null=True)
live_stream_using_custom_auth = models.BooleanField(blank=True, null=True)
live_stream_user = models.CharField(max_length=255, blank=True, null=True)
live_stream_pass = models.CharField(max_length=255, blank=True, null=True)
linked = models.BooleanField()
is_linkable = models.BooleanField()
image_path = models.CharField(max_length=255, blank=True, null=True)
has_autoplaylist = models.BooleanField()
autoplaylist = models.ForeignKey(
"Playlist", models.DO_NOTHING, blank=True, null=True
)
autoplaylist_repeat = models.BooleanField()
def get_owner(self):
return self.showhost_set.all()
class Meta:
managed = False
db_table = "cc_show"
class ShowDays(models.Model):
first_show = models.DateField()
last_show = models.DateField(blank=True, null=True)
start_time = models.TimeField()
timezone = models.CharField(max_length=1024)
duration = models.CharField(max_length=1024)
day = models.SmallIntegerField(blank=True, null=True)
repeat_type = models.SmallIntegerField()
next_pop_date = models.DateField(blank=True, null=True)
show = models.ForeignKey("Show", models.DO_NOTHING)
record = models.SmallIntegerField(blank=True, null=True)
def get_owner(self):
return self.show.get_owner()
class Meta:
managed = False
db_table = "cc_show_days"
class ShowHost(models.Model):
show = models.ForeignKey("Show", models.DO_NOTHING)
subjs = models.ForeignKey("core.User", models.DO_NOTHING)
class Meta:
managed = False
db_table = "cc_show_hosts"
class ShowInstance(models.Model):
description = models.CharField(max_length=8192, blank=True, null=True)
starts = models.DateTimeField()
ends = models.DateTimeField()
show = models.ForeignKey("Show", models.DO_NOTHING)
record = models.SmallIntegerField(blank=True, null=True)
rebroadcast = models.SmallIntegerField(blank=True, null=True)
instance = models.ForeignKey("self", models.DO_NOTHING, blank=True, null=True)
file = models.ForeignKey("storage.File", models.DO_NOTHING, blank=True, null=True)
time_filled = models.DurationField(blank=True, null=True)
created = models.DateTimeField()
last_scheduled = models.DateTimeField(blank=True, null=True)
modified_instance = models.BooleanField()
autoplaylist_built = models.BooleanField()
def get_owner(self):
return show.get_owner()
class Meta:
managed = False
db_table = "cc_show_instances"
class ShowRebroadcast(models.Model):
day_offset = models.CharField(max_length=1024)
start_time = models.TimeField()
show = models.ForeignKey("Show", models.DO_NOTHING)
def get_owner(self):
return show.get_owner()
class Meta:
managed = False
db_table = "cc_show_rebroadcast"

View file

@ -0,0 +1,83 @@
from django.db import models
class SmartBlock(models.Model):
name = models.CharField(max_length=255)
mtime = models.DateTimeField(blank=True, null=True)
utime = models.DateTimeField(blank=True, null=True)
creator = models.ForeignKey("core.User", models.DO_NOTHING, blank=True, null=True)
description = models.CharField(max_length=512, blank=True, null=True)
length = models.DurationField(blank=True, null=True)
type = models.CharField(max_length=7, blank=True, null=True)
def get_owner(self):
return self.creator
class Meta:
managed = False
db_table = "cc_block"
permissions = [
(
"change_own_smartblock",
"Change the smartblocks where they are the owner",
),
(
"delete_own_smartblock",
"Delete the smartblocks where they are the owner",
),
]
class SmartBlockContent(models.Model):
block = models.ForeignKey("SmartBlock", models.DO_NOTHING, blank=True, null=True)
file = models.ForeignKey("storage.File", models.DO_NOTHING, blank=True, null=True)
position = models.IntegerField(blank=True, null=True)
trackoffset = models.FloatField()
cliplength = models.DurationField(blank=True, null=True)
cuein = models.DurationField(blank=True, null=True)
cueout = models.DurationField(blank=True, null=True)
fadein = models.TimeField(blank=True, null=True)
fadeout = models.TimeField(blank=True, null=True)
def get_owner(self):
return self.block.get_owner()
class Meta:
managed = False
db_table = "cc_blockcontents"
permissions = [
(
"change_own_smartblockcontent",
"Change the content of smartblocks where they are the owner",
),
(
"delete_own_smartblockcontent",
"Delete the content of smartblocks where they are the owner",
),
]
class SmartBlockCriteria(models.Model):
criteria = models.CharField(max_length=32)
modifier = models.CharField(max_length=16)
value = models.CharField(max_length=512)
extra = models.CharField(max_length=512, blank=True, null=True)
criteriagroup = models.IntegerField(blank=True, null=True)
block = models.ForeignKey("SmartBlock", models.DO_NOTHING)
def get_owner(self):
return self.block.get_owner()
class Meta:
managed = False
db_table = "cc_blockcriteria"
permissions = [
(
"change_own_smartblockcriteria",
"Change the criteria of smartblocks where they are the owner",
),
(
"delete_own_smartblockcriteria",
"Delete the criteria of smartblocks where they are the owner",
),
]

View file

@ -0,0 +1,39 @@
from django.contrib.auth import get_user_model
from django.db import models
class Webstream(models.Model):
name = models.CharField(max_length=255)
description = models.CharField(max_length=255)
url = models.CharField(max_length=512)
length = models.DurationField()
creator_id = models.IntegerField()
mtime = models.DateTimeField()
utime = models.DateTimeField()
lptime = models.DateTimeField(blank=True, null=True)
mime = models.CharField(max_length=1024, blank=True, null=True)
def get_owner(self):
User = get_user_model()
return User.objects.get(pk=self.creator_id)
class Meta:
managed = False
db_table = "cc_webstream"
permissions = [
("change_own_webstream", "Change the webstreams where they are the owner"),
("delete_own_webstream", "Delete the webstreams where they are the owner"),
]
class WebstreamMetadata(models.Model):
instance = models.ForeignKey("Schedule", models.DO_NOTHING)
start_time = models.DateTimeField()
liquidsoap_data = models.CharField(max_length=1024)
def get_owner(self):
return self.instance.get_owner()
class Meta:
managed = False
db_table = "cc_webstream_metadata"