richtiger Modus fix

This commit is contained in:
ben8
2025-05-04 13:53:26 +02:00
parent 85ba8bc9cb
commit d86a9c51e9
2 changed files with 11 additions and 12 deletions

View File

@@ -13,7 +13,7 @@ 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)
@@ -22,17 +22,11 @@ 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:
host_id = request.COOKIES['host_id']
if host_id == quiz_game.host_id:
context['host_id'] = host_id
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.")
return render(request, 'play/join_game.html')
def create_game(request, quiz_id):
try:
quiz = QivipQuiz.objects.get(id=quiz_id)
game = QuizGame()
@@ -226,20 +219,24 @@ def finished(request, join_code):
})
def question(request, join_code):
quiz_game = get_object_or_404(QuizGame, join_code=join_code)
# Verify game state
if quiz_game.current_state != 'question':
return redirect('play:lobby', join_code=join_code)
# Get current question
questions = quiz_game.quiz_id.questions.all()
if quiz_game.current_question_index >= len(questions):
return redirect('play:lobby', join_code=join_code)
current_question = questions[quiz_game.current_question_index]
question_data = json.loads(current_question.data)
# Check if user is host
if 'host_id' in request.COOKIES and request.COOKIES['host_id'] == quiz_game.host_id:
return render(request, 'play/game/question_host.html', {
@@ -265,7 +262,8 @@ def question(request, join_code):
except QuizGameParticipant.DoesNotExist:
return redirect('play:create_participant', join_code=join_code)
request.session['my_participant-participant_id'] = participant.participant_id
return render(request, 'play/game/question_participant.html', {
'quiz_game': quiz_game,
'question_data': question_data,
@@ -277,6 +275,8 @@ def question(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)
# Check if user is host