mirror of
https://gitlab.science.ru.nl/technicie/MarietjeDjango.git
synced 2025-12-09 22:12:22 +01:00
Add maximum length a person can queue in a row.
This commit is contained in:
@ -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()
|
||||
|
||||
Reference in New Issue
Block a user