Add maximum length a person can queue in a row.

This commit is contained in:
Jim Driessen
2017-06-01 14:13:25 +02:00
parent 2386c7a68d
commit df1a31efb7
5 changed files with 61 additions and 6 deletions

View File

@ -111,12 +111,27 @@ class Queue(models.Model):
return songs[1:]
def request(self, song, user):
order = PlaylistSong.objects.filter(playlist=self.playlist).aggregate(Max('order'))['order__max']
playlist_songs = PlaylistSong.objects.filter(playlist=self.playlist, state=0).order_by('order')
order = 0
seconds_in_a_row = 0
for playlist_song in playlist_songs:
order = playlist_song.order
if playlist_song.user != user:
seconds_in_a_row = 0
else:
seconds_in_a_row += playlist_song.song.duration
if seconds_in_a_row > 0 and seconds_in_a_row + song.duration > settings.MAX_MINUTES_IN_A_ROW * 60\
and not user.is_superuser:
return False
if order is None:
order = 0
order += 1
playlist_song = PlaylistSong(playlist=self.playlist, song=song, user=user, order=order)
playlist_song.save()
return True
def fill_random_queue(self):
song_count = PlaylistSong.objects.filter(playlist_id=self.random_playlist_id, state=0).count()