|
|
@ -1,4 +1,6 @@
|
|
|
|
|
|
|
|
from django.contrib.auth.decorators import login_required
|
|
|
|
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 .forms import RateArtistForm
|
|
|
|
from .forms import RateArtistForm
|
|
|
|
from .models import Participant, Rating
|
|
|
|
from .models import Participant, Rating
|
|
|
@ -6,14 +8,30 @@ from ..core.models import Session
|
|
|
|
|
|
|
|
|
|
|
|
# Create your views here.
|
|
|
|
# Create your views here.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
|
|
|
def create_token(request):
|
|
|
|
|
|
|
|
session = get_object_or_404(Session, pk=request.session.get('session'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
token = None
|
|
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
|
|
|
participant = Participant(session=session)
|
|
|
|
|
|
|
|
participant.save()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
token = request.build_absolute_uri(reverse('participate', args=(participant.token,)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return render(request, 'vote/create_token.html', {'token': token})
|
|
|
|
|
|
|
|
|
|
|
|
def join_session(request, session):
|
|
|
|
def join_session(request, session):
|
|
|
|
session = get_object_or_404(Session, pk=session)
|
|
|
|
session = get_object_or_404(Session, pk=session)
|
|
|
|
|
|
|
|
|
|
|
|
if 'token' in request.session:
|
|
|
|
if 'token' in request.session:
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
participant = Participant.objects.get(pk=request.session['token'])
|
|
|
|
participant = Participant.objects.get(pk=request.session['token'])
|
|
|
|
|
|
|
|
if participant.session == session:
|
|
|
|
return redirect('current_artist', session.pk)
|
|
|
|
return redirect('current_artist', session.pk)
|
|
|
|
except Participant.DoesNotExist:
|
|
|
|
except Participant.DoesNotExist:
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
del request.session['token']
|
|
|
|
del request.session['token']
|
|
|
|
|
|
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
if request.method == 'POST':
|
|
|
@ -25,6 +43,22 @@ def join_session(request, session):
|
|
|
|
|
|
|
|
|
|
|
|
return render(request, 'vote/join_session.html', {})
|
|
|
|
return render(request, 'vote/join_session.html', {})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def participate(request, token):
|
|
|
|
|
|
|
|
if 'token' in request.session:
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
participant = Participant.objects.get(pk=request.session['token'])
|
|
|
|
|
|
|
|
if participant.token == token:
|
|
|
|
|
|
|
|
return redirect('current_artist', participant.session.pk)
|
|
|
|
|
|
|
|
except Participant.DoesNotExist:
|
|
|
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
del request.session['token']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
participant = get_object_or_404(Participant, pk=token)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
request.session['token'] = participant.pk
|
|
|
|
|
|
|
|
return redirect('current_artist', participant.session.playlist.pk)
|
|
|
|
|
|
|
|
|
|
|
|
def artist(request, playlist, offset=None):
|
|
|
|
def artist(request, playlist, offset=None):
|
|
|
|
participant = get_object_or_404(Participant, pk=request.session.get('token'))
|
|
|
|
participant = get_object_or_404(Participant, pk=request.session.get('token'))
|
|
|
|
|
|
|
|
|
|
|
|