Implement song/jingle boolean checks.

This commit is contained in:
Josh Washburne 2018-03-30 11:06:45 -04:00
parent aa90232897
commit 09ecf2a0ca
2 changed files with 23 additions and 7 deletions

View file

@ -47,7 +47,7 @@ class NextRequest(RetrieveAPIView):
limit = get_setting('songs_per_jingle') limit = get_setting('songs_per_jingle')
played_songs = SongRequest.music.get_played_requests(limit) played_songs = SongRequest.music.get_played_requests(limit)
if [j for j in played_songs if j.song.song_type == 'J']: if [j for j in played_songs if j.song.is_jingle]:
if not SongRequest.music.unplayed().exists(): if not SongRequest.music.unplayed().exists():
random_song = Song.music.get_random_requestable_song() random_song = Song.music.get_random_requestable_song()
next_play = SongRequest.objects.create(profile=dj_profile, next_play = SongRequest.objects.create(profile=dj_profile,

View file

@ -135,25 +135,41 @@ class Song(Disableable, Publishable, Timestampable, models.Model):
class Meta: class Meta:
ordering = ['sorted_title', ] ordering = ['sorted_title', ]
@property def _is_jingle(self):
def full_title(self): """
Is the object a jingle?
"""
return self.song_type == 'J'
_is_jingle.boolean = True
is_jingle = property(_is_jingle)
def _is_song(self):
"""
Is the object a song?
"""
return self.song_type == 'S'
_is_song.boolean = True
is_song = property(_is_song)
def _full_title(self):
""" """
String representing the entire song title, including the game and String representing the entire song title, including the game and
artists involved. artists involved.
""" """
if self.song_type == 'S': if self._is_song():
enabled_artists = self.artists.all().filter(disabled=False) enabled_artists = self.artists.all().filter(disabled=False)
all_artists = ', '.join([a.full_name for a in enabled_artists]) all_artists = ', '.join([a.full_name for a in enabled_artists])
return '{} - {} [{}]'.format(self.game.title, return '{} - {} [{}]'.format(self.game.title,
self.title, self.title,
all_artists) all_artists)
return self.title return self.title
full_title = property(_full_title)
def get_time_until_requestable(self): def get_time_until_requestable(self):
""" """
Length of time before a song can be requested again. Length of time before a song can be requested again.
""" """
if self.song_type == 'S': if self._is_song():
if self.last_played: if self.last_played:
allowed_datetime = Song.music.datetime_from_wait() allowed_datetime = Song.music.datetime_from_wait()
remaining_wait = self.last_played - allowed_datetime remaining_wait = self.last_played - allowed_datetime
@ -167,7 +183,7 @@ class Song(Disableable, Publishable, Timestampable, models.Model):
""" """
Datetime when a song can be requested again. Datetime when a song can be requested again.
""" """
if self.song_type == 'S': if self._is_song():
return self.last_played + Song.music.wait_total() return self.last_played + Song.music.wait_total()
return None return None
@ -175,7 +191,7 @@ class Song(Disableable, Publishable, Timestampable, models.Model):
""" """
Can the song be requested or not? Can the song be requested or not?
""" """
if self.song_type == 'S': if self._is_song():
return self.get_date_when_requestable() <= timezone.now() return self.get_date_when_requestable() <= timezone.now()
return False return False
_is_requestable.boolean = True _is_requestable.boolean = True