Merge branch 'feature/limit_hours' into 'master'

Limit hours when MAX_MINUTES_IN_A_ROW is in effect.

See merge request !8
This commit is contained in:
Jim Driessen
2017-06-12 15:19:53 +02:00
committed by Jim Driessen
2 changed files with 8 additions and 2 deletions

View File

@ -121,7 +121,7 @@ AUTH_USER_MODEL = 'marietje.User'
LANGUAGE_CODE = 'en-us' LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC' TIME_ZONE = 'Europe/Amsterdam'
USE_I18N = True USE_I18N = True
@ -144,4 +144,8 @@ BERTHA_HOST = ('hardcoding.nl', 1819)
MAIL_FROM = 'marietje@hardcoding.nl' MAIL_FROM = 'marietje@hardcoding.nl'
MAX_MINUTES_IN_A_ROW = 20 MAX_MINUTES_IN_A_ROW = 20
# Time range (dependent on timezone specified) when MAX_MINUTES_IN_A_ROW is in effect.
LIMIT_HOURS = (12, 16)

View File

@ -2,6 +2,7 @@ from django.db import models
from django.db.models import Q, Max from django.db.models import Q, Max
from django.conf import settings from django.conf import settings
from songs.models import Song from songs.models import Song
from django.utils import timezone
class Playlist(models.Model): class Playlist(models.Model):
@ -122,8 +123,9 @@ class Queue(models.Model):
else: else:
seconds_in_a_row += playlist_song.song.duration seconds_in_a_row += playlist_song.song.duration
now = timezone.now()
if seconds_in_a_row > 0 and seconds_in_a_row + song.duration > settings.MAX_MINUTES_IN_A_ROW * 60\ 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: and not user.is_superuser and settings.LIMIT_HOURS[0] <= now.hour < settings.LIMIT_HOURS[1]:
return False return False
if order is None: if order is None: