From a9343f285a0009d628fe769a81bff0a816f7b857 Mon Sep 17 00:00:00 2001 From: ben8 Date: Fri, 18 Apr 2025 13:48:23 +0000 Subject: [PATCH] Revert "Merge branch '103-verschiedene-lernmodi' into 'master'" This reverts merge request !47 --- django/play/urls.py | 1 - django/play/views.py | 84 ++--------------- django/templates/play/game/finished.html | 2 +- django/templates/play/game/question_host.html | 93 +++---------------- .../templates/play/game/score_overview.html | 27 ++---- django/templates/play/lobby.html | 2 - django/templates/play/select_mode.html | 18 +++- 7 files changed, 42 insertions(+), 185 deletions(-) diff --git a/django/play/urls.py b/django/play/urls.py index 261b472..df8326c 100644 --- a/django/play/urls.py +++ b/django/play/urls.py @@ -13,5 +13,4 @@ urlpatterns = [ path('game//scores', views.scores, name='scores'), path('game//finished', views.finished, name='finished'), path('select_mode/', views.select_mode, name='select_mode'), - path('selected_mode/', views.selected_mode, name='selected_mode'), ] \ No newline at end of file diff --git a/django/play/views.py b/django/play/views.py index ab6488e..173bbeb 100644 --- a/django/play/views.py +++ b/django/play/views.py @@ -1,4 +1,3 @@ -from django.utils import timezone from django.shortcuts import render from django.shortcuts import render, redirect, get_object_or_404, reverse from play.models import QuizGame, QuizGameParticipant @@ -8,12 +7,8 @@ from django.contrib import messages 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,19 +16,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) - - - if not "participant_id" in request.COOKIES: return redirect('play:create_participant', join_code=join_code) @@ -57,11 +44,9 @@ def select_mode(request,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: + + if "participant_id" in request.COOKIES: # Prüfe ob der Teilnehmer noch existiert participant_id = request.COOKIES['participant_id'] try: @@ -77,7 +62,7 @@ def create_participant(request, join_code): response.delete_cookie('participant_id') return response - if request.method == 'POST': + if request.method == 'POST': display_name = request.POST.get('display_name') if not display_name: return render(request, 'play/initialize_participant.html', { @@ -95,12 +80,9 @@ def create_participant(request, 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}) - else: - messages.error(request, "Beitritt nicht möglich.") - return render(request, 'play/join_game.html') + return render(request, 'play/initialize_participant.html', {'join_code': join_code}) + def create_game(request, quiz_id): - try: quiz = QivipQuiz.objects.get(id=quiz_id) game = QuizGame() @@ -108,7 +90,6 @@ def create_game(request, quiz_id): game.host_id = game.generate_unique_id() game.save() - response = HttpResponseRedirect(reverse('play:select_mode', kwargs={'join_code': game.join_code})) response.set_cookie('host_id', game.host_id, max_age=3600) @@ -152,7 +133,7 @@ def finished(request, join_code): def scores(request, join_code): quiz_game = get_object_or_404(QuizGame, join_code=join_code) - + # Verify game state if quiz_game.current_state != 'scores': return redirect('play:lobby', join_code=join_code) @@ -170,18 +151,9 @@ def scores(request, join_code): current_question = questions[quiz_game.current_question_index] question_data = json.loads(current_question.data) - try: - my_participant = request.session.get('my_participant-participant_id') - participant = QuizGameParticipant.objects.get(participant_id=my_participant) - my_participant=participant - except: - participant = QuizGameParticipant.objects.none() - return render(request, 'play/game/score_overview.html', { 'quiz_game': quiz_game, 'participants': participants, - 'participant': participant, - 'my_participant':my_participant, 'is_host': is_host, 'host_id': quiz_game.host_id if is_host else None, 'is_last_question': quiz_game.current_question_index + 1 >= len(questions), @@ -257,11 +229,8 @@ def question(request, join_code): participant_id = request.COOKIES['participant_id'] try: participant = QuizGameParticipant.objects.get(participant_id=participant_id) - - 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, @@ -293,43 +262,4 @@ def waiting_room(request, join_code): return render(request, 'play/game/wait_for_other_players.html', { 'quiz_game': quiz_game, 'participant': participant - }) - - -def selected_mode(request, join_code): - - - mode = request.GET.get('mode','default') - request.session['mode'] = mode - quiz_game = get_object_or_404(QuizGame, join_code=join_code) - quiz = get_object_or_404(QivipQuiz, pk=quiz_game.quiz_id.id) - QuizGameParticipant.objects.filter(quiz_game=quiz_game).delete() - - context = { - 'quiz': quiz, - 'quiz_game': quiz_game, - } - if "host_id" in request.COOKIES: - host_id = request.COOKIES['host_id'] - if host_id == quiz_game.host_id: - context['host_id'] = host_id - - if mode=="learn": - participant = QuizGameParticipant() - if request.user.is_authenticated: - participant.display_name = request.user.username - else: - participant.display_name = "SIE" - - participant.participant_id=host_id - participant.quiz_game = quiz_game - participant.score = 0 # Initialize score - participant.save() - quiz_game.current_state = "question" - quiz_game.question_start_time = timezone.now() - quiz_game.save() - - return redirect('play:question',join_code) - - - return render(request, 'play/lobby.html', context=context) + }) \ No newline at end of file diff --git a/django/templates/play/game/finished.html b/django/templates/play/game/finished.html index 9290126..b0300e1 100644 --- a/django/templates/play/game/finished.html +++ b/django/templates/play/game/finished.html @@ -7,7 +7,7 @@

Quiz beendet!

-

Vielen Dank fürs Spielen!

+

Vielen Dank fürs Mitspielen!

{% if not is_host %} diff --git a/django/templates/play/game/question_host.html b/django/templates/play/game/question_host.html index 82b2a9b..84f1d7f 100644 --- a/django/templates/play/game/question_host.html +++ b/django/templates/play/game/question_host.html @@ -1,67 +1,46 @@ {% extends 'base.html' %} + {% block content %} - -{% if request.session.mode == "learn" %} -
-
- -
{% endif %}

Frage {{ question_index|add:1 }} von {{ total_questions }}

{{ question_data.question }}

- {% if request.session.mode == "learn" %} -
- {% else %} -
- {% endif %} - {% if request.session.mode != "learn" %} + +
-

Verbleibende Zeit

+

Verbleibende Zeit

30

- {% endif %} -

Antworten

0/0

-
+
{% for option in question_data.options %} - + +
{% endfor %}
- - -
{% endblock %} - - {% block extra_js %} {% include 'play/game/common_scripts.html' %} {% endblock %} \ No newline at end of file diff --git a/django/templates/play/game/score_overview.html b/django/templates/play/game/score_overview.html index e8960d0..ae201ac 100644 --- a/django/templates/play/game/score_overview.html +++ b/django/templates/play/game/score_overview.html @@ -10,43 +10,33 @@

{{ question_data.question }}

{% for option in question_data.options %} -
+

{{ option.value }}

0 Antworten

{% endfor %}
- {% if request.session.mode != "learn" %} - +

Punktestand

{% for participant in participants %} - {% if participant == my_participant or is_host %} -
-
-

{{ participant.display_name }}

-

{{ participant.score }} Punkte

-
+
+

{{ participant.display_name }}

+

{{ participant.score }} Punkte

+
{% if participant.last_answer_correct %} {% elif participant.last_answer_correct == False %} {% endif %}
- {% else %} - - - {% endif %} - - - {% endfor %}
- {% endif %} + {% if is_host %} {% if is_last_question %}