From 09ecf2a0cac9ff94c5e9ebc678899cb334de319f Mon Sep 17 00:00:00 2001 From: Josh Washburne Date: Fri, 30 Mar 2018 11:06:45 -0400 Subject: [PATCH] Implement song/jingle boolean checks. --- savepointradio/api/views/controls.py | 2 +- savepointradio/radio/models.py | 28 ++++++++++++++++++++++------ 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/savepointradio/api/views/controls.py b/savepointradio/api/views/controls.py index 9fa0543..59a53cb 100644 --- a/savepointradio/api/views/controls.py +++ b/savepointradio/api/views/controls.py @@ -47,7 +47,7 @@ class NextRequest(RetrieveAPIView): limit = get_setting('songs_per_jingle') 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(): random_song = Song.music.get_random_requestable_song() next_play = SongRequest.objects.create(profile=dj_profile, diff --git a/savepointradio/radio/models.py b/savepointradio/radio/models.py index 9c41962..049fa4e 100644 --- a/savepointradio/radio/models.py +++ b/savepointradio/radio/models.py @@ -135,25 +135,41 @@ class Song(Disableable, Publishable, Timestampable, models.Model): class Meta: ordering = ['sorted_title', ] - @property - def full_title(self): + def _is_jingle(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 artists involved. """ - if self.song_type == 'S': + if self._is_song(): enabled_artists = self.artists.all().filter(disabled=False) all_artists = ', '.join([a.full_name for a in enabled_artists]) return '{} - {} [{}]'.format(self.game.title, self.title, all_artists) return self.title + full_title = property(_full_title) def get_time_until_requestable(self): """ Length of time before a song can be requested again. """ - if self.song_type == 'S': + if self._is_song(): if self.last_played: allowed_datetime = Song.music.datetime_from_wait() 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. """ - if self.song_type == 'S': + if self._is_song(): return self.last_played + Song.music.wait_total() return None @@ -175,7 +191,7 @@ class Song(Disableable, Publishable, Timestampable, models.Model): """ 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 False _is_requestable.boolean = True