Join Mechanik erstellen
This commit is contained in:
@@ -4,6 +4,6 @@ from . import views
|
||||
app_name = 'play'
|
||||
|
||||
urlpatterns = [
|
||||
path('lobby', views.lobby, name='lobby'),
|
||||
path('lobby/<str:join_code>', views.lobby, name='lobby'),
|
||||
path('join', views.join_game, name='join_game'),
|
||||
]
|
||||
@@ -1,8 +1,20 @@
|
||||
from django.shortcuts import render
|
||||
from django.shortcuts import render, redirect, get_object_or_404
|
||||
from play.models import QuizGame
|
||||
from library.models import QivipQuiz
|
||||
|
||||
# Create your views here.
|
||||
def lobby(request):
|
||||
return render(request, 'play/lobby.html')
|
||||
def lobby(request, join_code):
|
||||
quiz_game = get_object_or_404(QuizGame, join_code=join_code)
|
||||
return render(request, 'play/lobby.html', {'debug': "test"})
|
||||
|
||||
def join_game(request):
|
||||
if request.method == 'POST':
|
||||
join_code = request.POST.get('game_code')
|
||||
try:
|
||||
quiz = QuizGame.objects.get(join_code=join_code)
|
||||
return redirect('play:lobby', join_code=join_code)
|
||||
except QuizGame.DoesNotExist:
|
||||
# TODO: Mit message eine Fehlermeldung weitergeben (und im entsprechenden Template Designen)
|
||||
pass
|
||||
return render(request, 'play/join_game.html')
|
||||
@@ -7,7 +7,7 @@
|
||||
<form action="{% url 'play:join_game' %}" method="post" class="flex flex-col gap-4">
|
||||
{% csrf_token %}
|
||||
<div class="flex gap-3 items-center justify-center">
|
||||
<input type="text" name="game_code" placeholder="XXX-XXX" maxlength="7" pattern="[A-Za-z0-9]{3}-[A-Za-z0-9]{3}" class="w-32 p-3 rounded-full bg-gray-200 focus:scale-105 transition duration-200 font-black focus:outline-none focus:ring-2 focus:ring-blue-400 focus:bg-blue-100 text-center uppercase tracking-wider" oninput="let v = this.value.replace(/[^A-Za-z0-9]/g, '').slice(0,6).toUpperCase(); this.value = v.length > 3 ? v.slice(0,3) + '-' + v.slice(3) : v;" autofocus>
|
||||
<input type="text" name="game_code" placeholder="XXX-XXX" maxlength="7" class="w-32 p-3 rounded-full bg-gray-200 focus:scale-105 transition duration-200 font-black focus:outline-none focus:ring-2 focus:ring-blue-400 focus:bg-blue-100 text-center tracking-wider" autofocus>
|
||||
<button type="submit" class="h-12 px-6 rounded-full bg-blue-600 text-white font-black hover:scale-105 transition duration-200 flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed hover:bg-blue-700 active:scale-95 group" disabled>
|
||||
<span class="hidden sm:block">Beitreten</span>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" class="w-5 h-5 transition-transform group-hover:translate-x-1">
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
<li>Spieler 2</li>
|
||||
<li>Spieler 3</li>
|
||||
</ul>
|
||||
{{debug}}
|
||||
</div>
|
||||
<button class="w-full p-3 rounded-full bg-blue-600 text-white font-black hover:scale-105 transition duration-200" type="submit">Starten</button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user