Merge branch '124-qr-code' into 'master'

Resolve "QR Code"

Closes #124

See merge request enrichment-2024/qivip!82
This commit is contained in:
ben8
2025-05-19 16:31:54 +00:00
4 changed files with 24 additions and 5 deletions

View File

@@ -8,10 +8,20 @@ from django.contrib import messages
from django.conf import settings from django.conf import settings
import json import json
import qrcode
import base64
from io import BytesIO
from django.shortcuts import render
# Create your views here. # Create your views here.
def lobby(request, join_code): def lobby(request, join_code):
relative_url = reverse("play:create_participant", kwargs={"join_code": join_code})
full_url = request.build_absolute_uri(relative_url)
qr = qrcode.make(full_url)
buffer = BytesIO()
qr.save(buffer, format="PNG")
img_base64 = base64.b64encode(buffer.getvalue()).decode("utf-8")
@@ -20,6 +30,7 @@ def lobby(request, join_code):
context = { context = {
'quiz': quiz, 'quiz': quiz,
'quiz_game': quiz_game, 'quiz_game': quiz_game,
"qr_code_base64": img_base64,
} }
@@ -29,6 +40,7 @@ def lobby(request, join_code):
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
context["qr_code_base64"] = img_base64
return render(request, 'play/lobby.html', context=context) return render(request, 'play/lobby.html', context=context)
elif mode=="learn": elif mode=="learn":
return redirect('play:create_participant', join_code=join_code) return redirect('play:create_participant', join_code=join_code)
@@ -50,6 +62,7 @@ def lobby(request, join_code):
return redirect('play:create_participant', join_code=join_code) return redirect('play:create_participant', join_code=join_code)
context['participant'] = participant context['participant'] = participant
context["qr_code_base64"] = img_base64
return render(request, 'play/lobby.html', context=context) return render(request, 'play/lobby.html', context=context)
def select_mode(request,join_code): def select_mode(request,join_code):
@@ -334,5 +347,5 @@ def selected_mode(request, join_code):
return redirect('play:question',join_code) return redirect('play:question',join_code)
return redirect('play:lobby', join_code=join_code)
return render(request, 'play/lobby.html', context=context)

View File

@@ -68,7 +68,7 @@
<br> <br>
- alle öffentlichen Quizze können auch ohne Account gespielt werden - alle öffentlichen Quizze können auch ohne Account gespielt werden
<br> <br>
- qivip ist 100% kostenlos - qivip ist zu 100% kostenlos
<br> <br>
- es gibt keine Werbung - es gibt keine Werbung
<br> <br>
@@ -133,7 +133,7 @@
<br> <br>
<br> <br>
<b>Moderator: </b>Der Moderator selbst spielt nicht mit. Gehen Sie entweder auf die Startseite und klicken Sie auf "Moderieren" oder klicken einfach auf "spielen" (eines von Ihnen ausgewählten Quizzes) und dann auf Moderiermodus. <b>Moderator: </b>Der Moderator selbst spielt nicht mit. Gehen Sie entweder auf die Startseite und klicken Sie auf "Moderieren" oder klicken einfach auf "spielen" (eines von Ihnen ausgewählten Quizzes) und dann auf Moderiermodus.
Der Moderator kann das Spiel, wenn die Teilnehmer da sind starten. Der Moderator kann das Spiel, wenn die Teilnehmer da sind, starten.
<br> <br>
<br> <br>
<b>Teilnehmer: </b>Gehen Sie auf die Startseite und klicken Sie auf "Teilnehmen" und geben Sie dann den beim Moderator angegebenen Zahlencode ein. Anschließlich können Sie noch einen Anzeigenamen eingeben. <b>Teilnehmer: </b>Gehen Sie auf die Startseite und klicken Sie auf "Teilnehmen" und geben Sie dann den beim Moderator angegebenen Zahlencode ein. Anschließlich können Sie noch einen Anzeigenamen eingeben.

View File

@@ -8,12 +8,17 @@
<div class="text-center mb-8"> <div class="text-center mb-8">
<h3 class="text-xl text-gray-600 mb-2">{{ quiz.name }}</h3> <h3 class="text-xl text-gray-600 mb-2">{{ quiz.name }}</h3>
{% if request.session.mode != "learn" %} {% if request.session.mode != "learn" %}
{% if host_id %}
<div class="bg-blue-100 rounded-lg p-4 mb-4"> <div class="bg-blue-100 rounded-lg p-4 mb-4">
<h1 class="text-4xl font-bold text-blue-800">{{ quiz_game.join_code }}</h1> <h1 class="text-4xl font-bold text-blue-800">{{ quiz_game.join_code }}</h1>
<div class="w-full flex justify-center my-2">
<img src="data:image/png;base64,{{ qr_code_base64 }}" class="h-50 w-50" alt="QR-Code">
</div>
<p class="text-sm text-blue-600 mt-1">Spiel-Code</p> <p class="text-sm text-blue-600 mt-1">Spiel-Code</p>
</div> </div>
</div> </div>
{% endif %} {% endif %}
{% endif %}
<!-- Participant Info --> <!-- Participant Info -->
{% if participant %} {% if participant %}

View File

@@ -8,3 +8,4 @@ django-cleanup
redis redis
channels_redis channels_redis
python-dotenv # Production server safety python-dotenv # Production server safety
qrcode~=7.4.2