|
|
|
@ -1,4 +1,6 @@
|
|
|
|
|
from django.contrib.auth.decorators import login_required
|
|
|
|
|
from django.shortcuts import get_object_or_404, redirect, render
|
|
|
|
|
from django.urls import reverse
|
|
|
|
|
|
|
|
|
|
from .forms import RateArtistForm
|
|
|
|
|
from .models import Participant, Rating
|
|
|
|
@ -6,15 +8,31 @@ from ..core.models import Session
|
|
|
|
|
|
|
|
|
|
# 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):
|
|
|
|
|
session = get_object_or_404(Session, pk=session)
|
|
|
|
|
|
|
|
|
|
if 'token' in request.session:
|
|
|
|
|
try:
|
|
|
|
|
participant = Participant.objects.get(pk=request.session['token'])
|
|
|
|
|
return redirect('current_artist', session.pk)
|
|
|
|
|
if participant.session == session:
|
|
|
|
|
return redirect('current_artist', session.pk)
|
|
|
|
|
except Participant.DoesNotExist:
|
|
|
|
|
del request.session['token']
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
del request.session['token']
|
|
|
|
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
participant = Participant(session=session)
|
|
|
|
@ -25,6 +43,22 @@ def join_session(request, session):
|
|
|
|
|
|
|
|
|
|
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):
|
|
|
|
|
participant = get_object_or_404(Participant, pk=request.session.get('token'))
|
|
|
|
|
|
|
|
|
|