Next requests are now based on queued, not played.

This commit is contained in:
Josh W 2019-11-23 19:42:29 -05:00
parent ed8a540f36
commit 8badc08818
2 changed files with 19 additions and 4 deletions

View file

@ -57,9 +57,9 @@ class NextRequest(RetrieveAPIView):
dj_profile = RadioProfile.objects.get(user__is_dj=True) dj_profile = RadioProfile.objects.get(user__is_dj=True)
limit = get_setting('songs_per_jingle') limit = get_setting('songs_per_jingle')
played_songs = SongRequest.music.get_played_requests(limit) queued_songs = SongRequest.music.get_queued_requests(limit)
if [j for j in played_songs if j.song.is_jingle]: if [j for j in queued_songs if j.song.is_jingle]:
if not SongRequest.music.unplayed().exists(): if not SongRequest.music.new_requests().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,
song=random_song) song=random_song)

View file

@ -12,10 +12,25 @@ class RequestManager(models.Manager):
return self.get_queryset().filter(models.Q(queued_at__isnull=False) | return self.get_queryset().filter(models.Q(queued_at__isnull=False) |
models.Q(played_at__isnull=False)) models.Q(played_at__isnull=False))
def not_queued(self):
return self.get_queryset().filter(queued_at__isnull=True)
def queued(self):
return self.get_queryset().filter(models.Q(queued_at__isnull=False) &
models.Q(played_at__isnull=True))
def new_requests(self):
return self.unplayed().not_queued()
def get_played_requests(self, limit=None): def get_played_requests(self, limit=None):
if limit: if limit:
return self.played()[0:limit] return self.played()[0:limit]
return self.played() return self.played()
def get_queued_requests(self, limit=None):
if limit:
return self.queued()[0:limit]
return self.queued()
def next_request(self): def next_request(self):
return self.unplayed().earliest('created_date') return self.new_requests().earliest('created_date')