richtiger Modus fix
This commit is contained in:
@@ -13,7 +13,7 @@ import json
|
|||||||
# Create your views here.
|
# Create your views here.
|
||||||
def lobby(request, join_code):
|
def lobby(request, join_code):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
quiz_game = get_object_or_404(QuizGame, join_code=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)
|
quiz = get_object_or_404(QivipQuiz, pk=quiz_game.quiz_id.id)
|
||||||
@@ -22,17 +22,11 @@ def lobby(request, join_code):
|
|||||||
'quiz_game': quiz_game,
|
'quiz_game': quiz_game,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
mode = request.GET.get('mode','default')
|
|
||||||
request.session['mode'] = mode
|
|
||||||
if "host_id" in request.COOKIES:
|
if "host_id" in request.COOKIES:
|
||||||
host_id = request.COOKIES['host_id']
|
host_id = request.COOKIES['host_id']
|
||||||
if host_id == quiz_game.host_id:
|
if host_id == quiz_game.host_id:
|
||||||
context['host_id'] = host_id
|
context['host_id'] = host_id
|
||||||
return render(request, 'play/lobby.html', context=context)
|
return render(request, 'play/lobby.html', context=context)
|
||||||
elif mode=="learn":
|
|
||||||
return redirect('play:create_participant', join_code=join_code)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -101,7 +95,6 @@ def create_participant(request, join_code):
|
|||||||
messages.error(request, "Beitritt nicht möglich.")
|
messages.error(request, "Beitritt nicht möglich.")
|
||||||
return render(request, 'play/join_game.html')
|
return render(request, 'play/join_game.html')
|
||||||
def create_game(request, quiz_id):
|
def create_game(request, quiz_id):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
quiz = QivipQuiz.objects.get(id=quiz_id)
|
quiz = QivipQuiz.objects.get(id=quiz_id)
|
||||||
game = QuizGame()
|
game = QuizGame()
|
||||||
@@ -226,20 +219,24 @@ def finished(request, join_code):
|
|||||||
})
|
})
|
||||||
|
|
||||||
def question(request, join_code):
|
def question(request, join_code):
|
||||||
|
|
||||||
quiz_game = get_object_or_404(QuizGame, join_code=join_code)
|
quiz_game = get_object_or_404(QuizGame, join_code=join_code)
|
||||||
|
|
||||||
# Verify game state
|
# Verify game state
|
||||||
if quiz_game.current_state != 'question':
|
if quiz_game.current_state != 'question':
|
||||||
|
|
||||||
return redirect('play:lobby', join_code=join_code)
|
return redirect('play:lobby', join_code=join_code)
|
||||||
|
|
||||||
|
|
||||||
# Get current question
|
# Get current question
|
||||||
questions = quiz_game.quiz_id.questions.all()
|
questions = quiz_game.quiz_id.questions.all()
|
||||||
if quiz_game.current_question_index >= len(questions):
|
if quiz_game.current_question_index >= len(questions):
|
||||||
return redirect('play:lobby', join_code=join_code)
|
return redirect('play:lobby', join_code=join_code)
|
||||||
|
|
||||||
|
|
||||||
current_question = questions[quiz_game.current_question_index]
|
current_question = questions[quiz_game.current_question_index]
|
||||||
question_data = json.loads(current_question.data)
|
question_data = json.loads(current_question.data)
|
||||||
|
|
||||||
# Check if user is host
|
# Check if user is host
|
||||||
if 'host_id' in request.COOKIES and request.COOKIES['host_id'] == quiz_game.host_id:
|
if 'host_id' in request.COOKIES and request.COOKIES['host_id'] == quiz_game.host_id:
|
||||||
return render(request, 'play/game/question_host.html', {
|
return render(request, 'play/game/question_host.html', {
|
||||||
@@ -265,7 +262,8 @@ def question(request, join_code):
|
|||||||
except QuizGameParticipant.DoesNotExist:
|
except QuizGameParticipant.DoesNotExist:
|
||||||
return redirect('play:create_participant', join_code=join_code)
|
return redirect('play:create_participant', join_code=join_code)
|
||||||
request.session['my_participant-participant_id'] = participant.participant_id
|
request.session['my_participant-participant_id'] = participant.participant_id
|
||||||
|
|
||||||
|
|
||||||
return render(request, 'play/game/question_participant.html', {
|
return render(request, 'play/game/question_participant.html', {
|
||||||
'quiz_game': quiz_game,
|
'quiz_game': quiz_game,
|
||||||
'question_data': question_data,
|
'question_data': question_data,
|
||||||
@@ -277,6 +275,8 @@ def question(request, join_code):
|
|||||||
})
|
})
|
||||||
|
|
||||||
def waiting_room(request, join_code):
|
def waiting_room(request, join_code):
|
||||||
|
mode = request.GET.get('mode','default')# hinzugefügt
|
||||||
|
request.session['mode'] = mode # hinzugefügt
|
||||||
quiz_game = get_object_or_404(QuizGame, join_code=join_code)
|
quiz_game = get_object_or_404(QuizGame, join_code=join_code)
|
||||||
|
|
||||||
# Check if user is host
|
# Check if user is host
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
{% block content %}
|
{% block content %}
|
||||||
|
|
||||||
{% if request.session.mode == "learn" %}
|
{% if request.session.mode == "learn" %}
|
||||||
|
|
||||||
<div class="container mx-auto px-4">
|
<div class="container mx-auto px-4">
|
||||||
<div class="flex justify-end mb-4">
|
<div class="flex justify-end mb-4">
|
||||||
<button onclick="leaveGame()" class="bg-red-500 hover:bg-red-600 text-white font-bold py-2 px-4 rounded">
|
<button onclick="leaveGame()" class="bg-red-500 hover:bg-red-600 text-white font-bold py-2 px-4 rounded">
|
||||||
|
|||||||
Reference in New Issue
Block a user