|
|
@ -2,6 +2,7 @@ from django.conf import settings
|
|
|
|
from django.contrib.auth.decorators import login_required
|
|
|
|
from django.contrib.auth.decorators import login_required
|
|
|
|
from django.db import transaction
|
|
|
|
from django.db import transaction
|
|
|
|
from django.db.models import F, Min
|
|
|
|
from django.db.models import F, Min
|
|
|
|
|
|
|
|
from django.http import JsonResponse
|
|
|
|
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 django.utils import timezone
|
|
|
@ -11,6 +12,7 @@ from .forms import AddBreakContentForm, CreatePlaylistForm
|
|
|
|
from .models import BreakContent
|
|
|
|
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
|
|
|
|
|
|
|
|
from ..vote.models import Rating
|
|
|
|
|
|
|
|
|
|
|
|
def get_absolute_join_session_url(request, session):
|
|
|
|
def get_absolute_join_session_url(request, session):
|
|
|
|
return request.build_absolute_uri(reverse('join_session', args=(session.pk,)))
|
|
|
|
return request.build_absolute_uri(reverse('join_session', args=(session.pk,)))
|
|
|
@ -125,6 +127,18 @@ def add_break_content(request):
|
|
|
|
|
|
|
|
|
|
|
|
return render(request, 'host/add_break_content.html', {'form': form})
|
|
|
|
return render(request, 'host/add_break_content.html', {'form': form})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
|
|
|
def may_advance(request):
|
|
|
|
|
|
|
|
session = get_object_or_404(Session, pk=request.session.get('session'))
|
|
|
|
|
|
|
|
artist = session.playlist.artist_set.order_by('id')[session.offset]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
num_participants = session.participant_set.count()
|
|
|
|
|
|
|
|
if num_participants == 0:
|
|
|
|
|
|
|
|
return JsonResponse(False, safe=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ratio = Rating.objects.filter(artist=artist, participant__session=session).count() / num_participants
|
|
|
|
|
|
|
|
return JsonResponse(ratio >= settings.ADVANCE_THRESHOLD, safe=False)
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
@login_required
|
|
|
|
def session(request):
|
|
|
|
def session(request):
|
|
|
|
if 'session' in request.session:
|
|
|
|
if 'session' in request.session:
|
|
|
|