|
|
@ -1,9 +1,12 @@
|
|
|
|
from django.conf import settings
|
|
|
|
from django.conf import settings
|
|
|
|
|
|
|
|
from django.db.models import F, Min
|
|
|
|
from django.shortcuts import get_object_or_404, redirect, render
|
|
|
|
from django.shortcuts import get_object_or_404, redirect, render
|
|
|
|
from django.urls import reverse
|
|
|
|
from django.urls import reverse
|
|
|
|
|
|
|
|
from django.utils import timezone
|
|
|
|
from re import match
|
|
|
|
from re import match
|
|
|
|
|
|
|
|
|
|
|
|
from .forms import CreatePlaylistForm
|
|
|
|
from .forms import AddBreakContentForm, CreatePlaylistForm
|
|
|
|
|
|
|
|
from .models import BreakContent
|
|
|
|
from .spreadsheet import get_sheet_data
|
|
|
|
from .spreadsheet import get_sheet_data
|
|
|
|
from ..core.models import Artist, Playlist, Session
|
|
|
|
from ..core.models import Artist, Playlist, Session
|
|
|
|
|
|
|
|
|
|
|
@ -81,6 +84,41 @@ def create_playlist(request):
|
|
|
|
|
|
|
|
|
|
|
|
return render(request, 'host/create_playlist.html', {'error': None, 'form': form})
|
|
|
|
return render(request, 'host/create_playlist.html', {'error': None, 'form': form})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def break_view(request):
|
|
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
|
|
|
session = get_object_or_404(Session, pk=request.session.get('session'))
|
|
|
|
|
|
|
|
session.last_break = timezone.now()
|
|
|
|
|
|
|
|
session.save()
|
|
|
|
|
|
|
|
return redirect('view_artist', session.playlist.pk, session.offset)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
min_use_count = BreakContent.objects.aggregate(Min('use_count'))['use_count__min']
|
|
|
|
|
|
|
|
content = BreakContent.objects.filter(use_count=min_use_count).order_by('?')[0]
|
|
|
|
|
|
|
|
content.use_count = F('use_count') + 1
|
|
|
|
|
|
|
|
content.save()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return render(request, 'host/break.html', {'video_id': content.video_id})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def add_break_content(request):
|
|
|
|
|
|
|
|
form = AddBreakContentForm()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
|
|
|
form = AddBreakContentForm(request.POST)
|
|
|
|
|
|
|
|
if not form.is_valid():
|
|
|
|
|
|
|
|
return redirect('add_break_content')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m = match(settings.YOUTUBE_RE, form.cleaned_data['video_url'])
|
|
|
|
|
|
|
|
if m == None:
|
|
|
|
|
|
|
|
return redirect('add_break_content')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
min_use_count = BreakContent.objects.aggregate(Min('use_count'))['use_count__min']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
content = BreakContent(video_id=m[1], use_count=min_use_count or 0)
|
|
|
|
|
|
|
|
content.save()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return redirect('add_break_content')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return render(request, 'host/add_break_content.html', {'form': form})
|
|
|
|
|
|
|
|
|
|
|
|
def session(request):
|
|
|
|
def session(request):
|
|
|
|
if 'session' in request.session:
|
|
|
|
if 'session' in request.session:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
@ -124,6 +162,9 @@ def view_artist(request, playlist, offset):
|
|
|
|
if session.offset < offset:
|
|
|
|
if session.offset < offset:
|
|
|
|
session.offset = offset
|
|
|
|
session.offset = offset
|
|
|
|
session.save()
|
|
|
|
session.save()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (timezone.now()-session.last_break).total_seconds() >= settings.BREAK_INTERVAL*60:
|
|
|
|
|
|
|
|
return redirect('break')
|
|
|
|
except Session.DoesNotExist:
|
|
|
|
except Session.DoesNotExist:
|
|
|
|
del request.session['session']
|
|
|
|
del request.session['session']
|
|
|
|
|
|
|
|
|
|
|
|