|
|
|
|
@@ -11,9 +11,6 @@ import json
|
|
|
|
|
|
|
|
|
|
# Create your views here.
|
|
|
|
|
def lobby(request, join_code):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
quiz_game = get_object_or_404(QuizGame, join_code=join_code)
|
|
|
|
|
quiz = get_object_or_404(QivipQuiz, pk=quiz_game.quiz_id.id)
|
|
|
|
|
context = {
|
|
|
|
|
@@ -21,7 +18,6 @@ def lobby(request, join_code):
|
|
|
|
|
'quiz_game': quiz_game,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mode = request.GET.get('mode','default')
|
|
|
|
|
request.session['mode'] = mode
|
|
|
|
|
if "host_id" in request.COOKIES:
|
|
|
|
|
@@ -32,9 +28,6 @@ def lobby(request, join_code):
|
|
|
|
|
elif mode=="learn":
|
|
|
|
|
return redirect('play:create_participant', join_code=join_code)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not "participant_id" in request.COOKIES:
|
|
|
|
|
return redirect('play:create_participant', join_code=join_code)
|
|
|
|
|
|
|
|
|
|
@@ -54,48 +47,46 @@ def lobby(request, join_code):
|
|
|
|
|
def select_mode(request,join_code):
|
|
|
|
|
return render(request, 'play/select_mode.html', {'join_code': join_code})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_participant(request, join_code):
|
|
|
|
|
mode = request.GET.get('mode','default')
|
|
|
|
|
request.session['mode'] = mode
|
|
|
|
|
quiz_game = get_object_or_404(QuizGame, join_code=join_code)
|
|
|
|
|
if mode!="learn":
|
|
|
|
|
if "participant_id" in request.COOKIES:
|
|
|
|
|
# Prüfe ob der Teilnehmer noch existiert
|
|
|
|
|
participant_id = request.COOKIES['participant_id']
|
|
|
|
|
try:
|
|
|
|
|
participant = QuizGameParticipant.objects.get(participant_id=participant_id)
|
|
|
|
|
if participant.quiz_game.join_code != join_code:
|
|
|
|
|
participant.quiz_game = quiz_game
|
|
|
|
|
participant.score = 0 # Reset score when joining new game
|
|
|
|
|
participant.save()
|
|
|
|
|
return redirect('play:lobby', join_code=join_code)
|
|
|
|
|
except QuizGameParticipant.DoesNotExist:
|
|
|
|
|
# Cookie löschen wenn Teilnehmer nicht mehr existiert
|
|
|
|
|
response = HttpResponseRedirect(request.path)
|
|
|
|
|
response.delete_cookie('participant_id')
|
|
|
|
|
if request.method == 'GET' and "participant_id" in request.COOKIES:
|
|
|
|
|
# Prüfe ob der Teilnehmer noch existiert
|
|
|
|
|
participant_id = request.COOKIES['participant_id']
|
|
|
|
|
try:
|
|
|
|
|
participant = QuizGameParticipant.objects.get(participant_id=participant_id)
|
|
|
|
|
if participant.quiz_game.join_code != join_code:
|
|
|
|
|
participant.quiz_game = quiz_game
|
|
|
|
|
participant.score = 0 # Reset score when joining new game
|
|
|
|
|
participant.save()
|
|
|
|
|
return render(request, 'play/initialize_participant.html', {'participant': participant, 'join_code': quiz_game.join_code})
|
|
|
|
|
except QuizGameParticipant.DoesNotExist:
|
|
|
|
|
# Cookie löschen wenn Teilnehmer nicht mehr existiert
|
|
|
|
|
response = HttpResponseRedirect(request.path)
|
|
|
|
|
response.delete_cookie('participant_id')
|
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
display_name = request.POST.get('display_name')
|
|
|
|
|
if not display_name:
|
|
|
|
|
return render(request, 'play/initialize_participant.html', {
|
|
|
|
|
'join_code': join_code,
|
|
|
|
|
'error': 'Bitte geben Sie einen Namen ein'
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
participant = QuizGameParticipant()
|
|
|
|
|
participant.display_name = display_name
|
|
|
|
|
participant.quiz_game = quiz_game
|
|
|
|
|
participant.score = 0 # Initialize score
|
|
|
|
|
participant.save()
|
|
|
|
|
|
|
|
|
|
response = HttpResponseRedirect(reverse('play:lobby', kwargs={'join_code': join_code}))
|
|
|
|
|
response.set_cookie('participant_id', participant.participant_id, max_age=3600)
|
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
if request.method == 'POST':
|
|
|
|
|
display_name = request.POST.get('display_name')
|
|
|
|
|
if not display_name:
|
|
|
|
|
return render(request, 'play/initialize_participant.html', {
|
|
|
|
|
'join_code': join_code,
|
|
|
|
|
'error': 'Bitte geben Sie einen Namen ein'
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
participant = QuizGameParticipant()
|
|
|
|
|
participant.display_name = display_name
|
|
|
|
|
participant.quiz_game = quiz_game
|
|
|
|
|
participant.score = 0 # Initialize score
|
|
|
|
|
participant.save()
|
|
|
|
|
|
|
|
|
|
response = HttpResponseRedirect(reverse('play:lobby', kwargs={'join_code': join_code}))
|
|
|
|
|
response.set_cookie('participant_id', participant.participant_id, max_age=3600)
|
|
|
|
|
return response
|
|
|
|
|
|
|
|
|
|
return render(request, 'play/initialize_participant.html', {'join_code': join_code})
|
|
|
|
|
return render(request, 'play/initialize_participant.html', {'join_code': join_code})
|
|
|
|
|
else:
|
|
|
|
|
messages.error(request, "Beitritt nicht möglich.")
|
|
|
|
|
return render(request, 'play/join_game.html')
|
|
|
|
|
|